#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long qpow(long long a, long long b, long long p) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % p;
    b >>= 1;
    a = a * a % p;
  }
  return res;
}
long long fac[350], facinv[350];
void init() {
  fac[0] = fac[1] = facinv[0] = facinv[1] = 1;
  for (int i = 2; i <= 300; i++) {
    fac[i] = fac[i - 1] * i % mod;
    facinv[i] = facinv[i - 1] * qpow(i, mod - 2, mod) % mod;
  }
}
long long C(int n, int m) {
  if (n < m) return 0;
  long long res = facinv[m] * facinv[n - m] % mod;
  res *= fac[n];
  res %= mod;
  return res;
}
map<long long, long long int> ma;
long long a[350], num[350];
int n;
long long dp[350][350];
int main() {
  init();
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  ma.clear();
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        while (a[i] % (j * j) == 0) a[i] /= (j * j);
      }
    }
    ma[a[i]]++;
  }
  map<long long, long long int>::iterator it;
  int cnt = 0;
  for (it = ma.begin(); it != ma.end(); ++it) {
    num[cnt++] = (*it).second;
  }
  dp[0][0] = 1;
  long long int tot = 0;
  for (int i = 0; i < cnt; i++) {
    for (int j = 0; j <= tot; j++) {
      if (dp[i][j] == 0) continue;
      for (long long int s = 1; s <= min(tot + 1, num[i]); s++) {
        for (long long int d = 0; d <= min((long long)j, s); d++) {
          long long temp = C(num[i] - 1, s - 1) * C(j, d) % mod;
          temp = temp * C(tot + 1 - j, s - d) % mod;
          temp = temp * dp[i][j] % mod;
          dp[i + 1][j - d + num[i] - s] += temp;
          dp[i + 1][j - d + num[i] - s] %= mod;
        }
      }
    }
    tot += num[i];
  }
  long long res = dp[cnt][0];
  for (int i = 0; i < cnt; i++) {
    res = res * fac[num[i]] % mod;
  }
  cout << res << endl;
  return 0;
}

### Prompt

Create a solution in Cpp for 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 long long mod = 1e9 + 7;
long long qpow(long long a, long long b, long long p) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % p;
    b >>= 1;
    a = a * a % p;
  }
  return res;
}
long long fac[350], facinv[350];
void init() {
  fac[0] = fac[1] = facinv[0] = facinv[1] = 1;
  for (int i = 2; i <= 300; i++) {
    fac[i] = fac[i - 1] * i % mod;
    facinv[i] = facinv[i - 1] * qpow(i, mod - 2, mod) % mod;
  }
}
long long C(int n, int m) {
  if (n < m) return 0;
  long long res = facinv[m] * facinv[n - m] % mod;
  res *= fac[n];
  res %= mod;
  return res;
}
map<long long, long long int> ma;
long long a[350], num[350];
int n;
long long dp[350][350];
int main() {
  init();
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  ma.clear();
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        while (a[i] % (j * j) == 0) a[i] /= (j * j);
      }
    }
    ma[a[i]]++;
  }
  map<long long, long long int>::iterator it;
  int cnt = 0;
  for (it = ma.begin(); it != ma.end(); ++it) {
    num[cnt++] = (*it).second;
  }
  dp[0][0] = 1;
  long long int tot = 0;
  for (int i = 0; i < cnt; i++) {
    for (int j = 0; j <= tot; j++) {
      if (dp[i][j] == 0) continue;
      for (long long int s = 1; s <= min(tot + 1, num[i]); s++) {
        for (long long int d = 0; d <= min((long long)j, s); d++) {
          long long temp = C(num[i] - 1, s - 1) * C(j, d) % mod;
          temp = temp * C(tot + 1 - j, s - d) % mod;
          temp = temp * dp[i][j] % mod;
          dp[i + 1][j - d + num[i] - s] += temp;
          dp[i + 1][j - d + num[i] - s] %= mod;
        }
      }
    }
    tot += num[i];
  }
  long long res = dp[cnt][0];
  for (int i = 0; i < cnt; i++) {
    res = res * fac[num[i]] % mod;
  }
  cout << res << endl;
  return 0;
}

```