#include <bits/stdc++.h>
using namespace std;
int a[305];
long long dp[305][305], ncr[305][305], fact[305];
map<int, int> m;
long long nCr(int n, int r) {
  if (r == n || r == 0) return 1;
  if (r == 1) return n;
  if (ncr[n][r] != -1) return ncr[n][r];
  return (ncr[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)) % 1000000007);
}
int num(int n) {
  while (n % 4 == 0) n /= 4;
  for (int i = 3; i * i <= n; i += 2) {
    while (n % (i * i) == 0) n /= (i * i);
  }
  return n;
}
long long solve(int n) {
  if (n == 1 && a[0] == 1) return 1;
  if (n == 1) return 0;
  int i, j, k, sum = 0, t;
  long long temp;
  memset(ncr, -1, sizeof(ncr));
  dp[0][a[0] - 1] = 1;
  sum = a[0] + 1;
  for (i = 1; i < n; i++) {
    for (j = 0; j < sum; j++) {
      if (dp[i - 1][j] == 0) continue;
      for (k = 1; k <= a[i]; k++) {
        for (t = max(0, k - sum + j); t <= min(j, k); t++) {
          temp = (dp[i - 1][j] * nCr(sum - j, k - t)) % 1000000007;
          temp = (temp * nCr(j, t)) % 1000000007;
          temp = (temp * nCr(a[i] - 1, k - 1)) % 1000000007;
          dp[i][j - t + a[i] - k] =
              (dp[i][j - t + a[i] - k] + temp) % 1000000007;
        }
      }
    }
    sum += a[i];
  }
  return dp[n - 1][0];
}
int main() {
  int n, i, j, k, sz;
  scanf("%d", &n);
  sz = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &j);
    k = num(j);
    if (m.find(k) == m.end()) m[k] = sz++;
    a[m[k]]++;
  }
  sort(a, a + sz, greater<int>());
  long long ans = solve(sz);
  fact[0] = 1;
  for (i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % 1000000007;
  for (i = 0; i < sz; i++) {
    ans = (ans * fact[a[i]]) % 1000000007;
  }
  printf("%I64d\n", ans);
  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;
int a[305];
long long dp[305][305], ncr[305][305], fact[305];
map<int, int> m;
long long nCr(int n, int r) {
  if (r == n || r == 0) return 1;
  if (r == 1) return n;
  if (ncr[n][r] != -1) return ncr[n][r];
  return (ncr[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)) % 1000000007);
}
int num(int n) {
  while (n % 4 == 0) n /= 4;
  for (int i = 3; i * i <= n; i += 2) {
    while (n % (i * i) == 0) n /= (i * i);
  }
  return n;
}
long long solve(int n) {
  if (n == 1 && a[0] == 1) return 1;
  if (n == 1) return 0;
  int i, j, k, sum = 0, t;
  long long temp;
  memset(ncr, -1, sizeof(ncr));
  dp[0][a[0] - 1] = 1;
  sum = a[0] + 1;
  for (i = 1; i < n; i++) {
    for (j = 0; j < sum; j++) {
      if (dp[i - 1][j] == 0) continue;
      for (k = 1; k <= a[i]; k++) {
        for (t = max(0, k - sum + j); t <= min(j, k); t++) {
          temp = (dp[i - 1][j] * nCr(sum - j, k - t)) % 1000000007;
          temp = (temp * nCr(j, t)) % 1000000007;
          temp = (temp * nCr(a[i] - 1, k - 1)) % 1000000007;
          dp[i][j - t + a[i] - k] =
              (dp[i][j - t + a[i] - k] + temp) % 1000000007;
        }
      }
    }
    sum += a[i];
  }
  return dp[n - 1][0];
}
int main() {
  int n, i, j, k, sz;
  scanf("%d", &n);
  sz = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &j);
    k = num(j);
    if (m.find(k) == m.end()) m[k] = sz++;
    a[m[k]]++;
  }
  sort(a, a + sz, greater<int>());
  long long ans = solve(sz);
  fact[0] = 1;
  for (i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % 1000000007;
  for (i = 0; i < sz; i++) {
    ans = (ans * fact[a[i]]) % 1000000007;
  }
  printf("%I64d\n", ans);
  return 0;
}

```