#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
long long fact[405], inv[405];
int bigmod(long long a, long long p) {
  long long ret = 1;
  while (p) {
    if (p & 1) ret = ret * a % mod;
    a = a * a % mod;
    p >>= 1;
  }
  return ret;
}
int mod_add(long long a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int mod_sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
int mod_mul(long long a, long long b) { return (a * b) % mod; }
int mod_div(long long a, long long b) { return mod_mul(a, bigmod(b, mod - 2)); }
int mod_power(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mod_mul(res, a);
    }
    a = mod_mul(a, a);
    b >>= 1;
  }
  return res;
}
void factorial() {
  fact[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < 405; i++) {
    fact[i] = mod_mul(fact[i - 1], i);
    inv[i] = mod_power(fact[i], mod - 2);
  }
}
long long nCr(long long n, long long r) {
  if (r > n) return 0;
  long long ret = fact[n];
  ret = (ret * inv[r]) % mod;
  ret = (ret * inv[n - r]) % mod;
  return ret;
}
int arr[405];
bool vis[405];
long long C[405], g = 0;
long long dp[405][405];
long long sum[405];
int main() {
  factorial();
  int n, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  for (i = 1; i <= n; i++) {
    if (vis[i]) continue;
    vis[i] = true;
    g++;
    C[g]++;
    for (j = i + 1; j <= n; j++) {
      if (vis[j]) continue;
      long long now = (long long)arr[i] * (long long)arr[j];
      long long to = sqrt(now);
      if (to * to == now) {
        vis[j] = true;
        C[g]++;
      }
    }
  }
  for (i = 1; i <= g; i++) sum[i] = sum[i - 1] + C[i];
  dp[0][0] = 1;
  for (int x = 1; x <= g; x++) {
    for (int ij = 1; ij <= C[x]; ij++) {
      for (int y = 0; y <= sum[x - 1]; y++) {
        if (dp[x - 1][y] == 0) continue;
        for (j = 0; j <= min(ij, y); j++) {
          i = ij - j;
          int z = sum[x - 1] + 1 - y;
          if (i > z) continue;
          long long t1, t2, t3, t4;
          t1 = mod_mul(dp[x - 1][y], nCr(y, j));
          t2 = mod_mul(nCr(z, i), nCr(C[x] - 1, ij - 1));
          t3 = fact[C[x]];
          t4 = mod_mul(t1, mod_mul(t2, t3));
          dp[x][(y - j) + (C[x] - ij)] =
              mod_add(dp[x][(y - j) + (C[x] - ij)], t4);
        }
      }
    }
  }
  cout << dp[g][0] << endl;
  return 0;
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

A year ago on the bench in public park Leha found an array of n numbers. Leha believes that permutation p is right if for all 1 ≤ i < n condition, that api·api + 1 is not perfect square, holds. Leha wants to find number of right permutations modulo 109 + 7.

Input

First line of input data contains single integer n (1 ≤ n ≤ 300) — length of the array.

Next line contains n integers a1, a2, ... , an (1 ≤ ai ≤ 109) — found array.

Output

Output single integer — number of right permutations modulo 109 + 7.

Examples

Input

3
1 2 4


Output

2


Input

7
5 2 4 2 4 1 1


Output

144

Note

For first example:

[1, 2, 4] — right permutation, because 2 and 8 are not perfect squares.

[1, 4, 2] — wrong permutation, because 4 is square of 2.

[2, 1, 4] — wrong permutation, because 4 is square of 2.

[2, 4, 1] — wrong permutation, because 4 is square of 2.

[4, 1, 2] — wrong permutation, because 4 is square of 2.

[4, 2, 1] — right permutation, because 8 and 2 are not perfect squares.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
long long fact[405], inv[405];
int bigmod(long long a, long long p) {
  long long ret = 1;
  while (p) {
    if (p & 1) ret = ret * a % mod;
    a = a * a % mod;
    p >>= 1;
  }
  return ret;
}
int mod_add(long long a, long long b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int mod_sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
int mod_mul(long long a, long long b) { return (a * b) % mod; }
int mod_div(long long a, long long b) { return mod_mul(a, bigmod(b, mod - 2)); }
int mod_power(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mod_mul(res, a);
    }
    a = mod_mul(a, a);
    b >>= 1;
  }
  return res;
}
void factorial() {
  fact[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < 405; i++) {
    fact[i] = mod_mul(fact[i - 1], i);
    inv[i] = mod_power(fact[i], mod - 2);
  }
}
long long nCr(long long n, long long r) {
  if (r > n) return 0;
  long long ret = fact[n];
  ret = (ret * inv[r]) % mod;
  ret = (ret * inv[n - r]) % mod;
  return ret;
}
int arr[405];
bool vis[405];
long long C[405], g = 0;
long long dp[405][405];
long long sum[405];
int main() {
  factorial();
  int n, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  for (i = 1; i <= n; i++) {
    if (vis[i]) continue;
    vis[i] = true;
    g++;
    C[g]++;
    for (j = i + 1; j <= n; j++) {
      if (vis[j]) continue;
      long long now = (long long)arr[i] * (long long)arr[j];
      long long to = sqrt(now);
      if (to * to == now) {
        vis[j] = true;
        C[g]++;
      }
    }
  }
  for (i = 1; i <= g; i++) sum[i] = sum[i - 1] + C[i];
  dp[0][0] = 1;
  for (int x = 1; x <= g; x++) {
    for (int ij = 1; ij <= C[x]; ij++) {
      for (int y = 0; y <= sum[x - 1]; y++) {
        if (dp[x - 1][y] == 0) continue;
        for (j = 0; j <= min(ij, y); j++) {
          i = ij - j;
          int z = sum[x - 1] + 1 - y;
          if (i > z) continue;
          long long t1, t2, t3, t4;
          t1 = mod_mul(dp[x - 1][y], nCr(y, j));
          t2 = mod_mul(nCr(z, i), nCr(C[x] - 1, ij - 1));
          t3 = fact[C[x]];
          t4 = mod_mul(t1, mod_mul(t2, t3));
          dp[x][(y - j) + (C[x] - ij)] =
              mod_add(dp[x][(y - j) + (C[x] - ij)], t4);
        }
      }
    }
  }
  cout << dp[g][0] << endl;
  return 0;
}

```