#include <bits/stdc++.h>
using namespace std;
long long n, m, a[1005], belong[1005], f[1005][1005], c[1005][1005], ans,
    d[1005], cnt;
long long fac[1005];
inline long long read() {
  register long long s = 0, t = 0;
  register char ch = getchar();
  while (ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return t ? -s : s;
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long j = 1; j <= n; j++) {
    for (long long k = 1; k < j; k++) {
      long long p = sqrt(a[j] * a[k]);
      if (p * p == a[j] * a[k]) belong[j] = belong[k];
    }
    if (!belong[j]) belong[j] = ++cnt;
    d[belong[j]]++;
  }
  c[0][0] = 1;
  fac[0] = 1;
  for (long long i = 1; i <= n; i++) {
    c[i][0] = c[i][i] = 1;
    fac[i] = 1ll * fac[i - 1] * i % 1000000007;
    for (long long j = 1; j < i; j++)
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % 1000000007;
  }
  f[0][0] = 1;
  for (long long i = 1; i <= cnt; i++)
    for (long long j = 0; j < d[i]; j++) {
      long long p = c[d[i] - 1][j];
      for (long long k = j; k <= n; k++)
        (f[i][k] += f[i - 1][k - j] * p % 1000000007 * fac[d[i]] % 1000000007 *
                    c[k + i][j + 1] % 1000000007) %= 1000000007;
    }
  for (long long i = 0; i <= n; i++) {
    if ((n - cnt - i) & 1)
      ans = (ans + 1000000007 - f[cnt][i]) % 1000000007;
    else
      ans = (ans + f[cnt][i]) % 1000000007;
  }
  cout << ans << 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;
long long n, m, a[1005], belong[1005], f[1005][1005], c[1005][1005], ans,
    d[1005], cnt;
long long fac[1005];
inline long long read() {
  register long long s = 0, t = 0;
  register char ch = getchar();
  while (ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return t ? -s : s;
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long j = 1; j <= n; j++) {
    for (long long k = 1; k < j; k++) {
      long long p = sqrt(a[j] * a[k]);
      if (p * p == a[j] * a[k]) belong[j] = belong[k];
    }
    if (!belong[j]) belong[j] = ++cnt;
    d[belong[j]]++;
  }
  c[0][0] = 1;
  fac[0] = 1;
  for (long long i = 1; i <= n; i++) {
    c[i][0] = c[i][i] = 1;
    fac[i] = 1ll * fac[i - 1] * i % 1000000007;
    for (long long j = 1; j < i; j++)
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % 1000000007;
  }
  f[0][0] = 1;
  for (long long i = 1; i <= cnt; i++)
    for (long long j = 0; j < d[i]; j++) {
      long long p = c[d[i] - 1][j];
      for (long long k = j; k <= n; k++)
        (f[i][k] += f[i - 1][k - j] * p % 1000000007 * fac[d[i]] % 1000000007 *
                    c[k + i][j + 1] % 1000000007) %= 1000000007;
    }
  for (long long i = 0; i <= n; i++) {
    if ((n - cnt - i) & 1)
      ans = (ans + 1000000007 - f[cnt][i]) % 1000000007;
    else
      ans = (ans + f[cnt][i]) % 1000000007;
  }
  cout << ans << endl;
  return 0;
}

```