#include <bits/stdc++.h>
using namespace std;
const int _ = 1e2;
const int maxn = 310;
const int mod = 1e9 + 7;
inline int ad(int x, int y) { return x >= mod - y ? x - mod + y : x + y; }
inline int re(int x, int y) { return x < y ? x - y + mod : x - y; }
inline int mu(int x, int y) { return (long long)x * y % mod; }
inline int qp(int x, long long y) {
  int r = 1;
  while (y) {
    if (y & 1) r = mu(r, x);
    x = mu(x, x);
    y >>= 1;
  }
  return r;
}
inline int iv(int x) { return qp(x, mod - 2); }
inline int dv(int x, int y) { return mu(x, qp(y, mod - 2)); }
inline int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }
int fac[maxn], C[maxn][maxn];
void yu() {
  fac[0] = 1;
  for (int i = 1; i < maxn; i++) fac[i] = mu(fac[i - 1], i);
  for (int i = 0; i < maxn; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) C[i][j] = ad(C[i - 1][j - 1], C[i - 1][j]);
  }
}
int a[maxn], len, num[maxn], f[maxn][maxn];
int main() {
  int n, x, c, d;
  scanf("%d", &n);
  yu();
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[i] = 1;
    for (int j = 2; j * j <= x; j++)
      if (x % j == 0) {
        c = 0;
        while (x % j == 0) x /= j, c ^= 1;
        if (c) a[i] *= j;
      }
    if (x != 1) a[i] *= x;
  }
  sort(a + 1, a + n + 1);
  int cc = 1;
  for (int i = 2; i <= n; i++)
    if (a[i] == a[i - 1])
      cc++;
    else
      num[++len] = cc, cc = 1;
  num[++len] = cc;
  sort(num + 1, num + len + 1, greater<int>());
  f[1][num[1] - 1] = 1;
  int s = 0;
  for (int i = 1; i < len; i++) {
    s += num[i];
    for (int j = 0; j < n; j++)
      if (f[i][j])
        for (int p = 0; p < num[i + 1]; p++)
          for (int k = 0; k <= j && k <= num[i + 1] - p; k++)
            if (j - k + p < n)
              f[i + 1][j - k + p] =
                  ad(f[i + 1][j - k + p],
                     mu(mu(C[j][k], C[s + 1 - j][num[i + 1] - p - k]),
                        mu(C[num[i + 1] - 1][num[i + 1] - p - 1], f[i][j])));
  }
  for (int i = 1; i <= len; i++) f[len][0] = mu(f[len][0], fac[num[i]]);
  printf("%d\n", f[len][0]);
  return 0;
}

### Prompt

Please provide a Cpp coded solution to the problem described below:

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 _ = 1e2;
const int maxn = 310;
const int mod = 1e9 + 7;
inline int ad(int x, int y) { return x >= mod - y ? x - mod + y : x + y; }
inline int re(int x, int y) { return x < y ? x - y + mod : x - y; }
inline int mu(int x, int y) { return (long long)x * y % mod; }
inline int qp(int x, long long y) {
  int r = 1;
  while (y) {
    if (y & 1) r = mu(r, x);
    x = mu(x, x);
    y >>= 1;
  }
  return r;
}
inline int iv(int x) { return qp(x, mod - 2); }
inline int dv(int x, int y) { return mu(x, qp(y, mod - 2)); }
inline int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }
int fac[maxn], C[maxn][maxn];
void yu() {
  fac[0] = 1;
  for (int i = 1; i < maxn; i++) fac[i] = mu(fac[i - 1], i);
  for (int i = 0; i < maxn; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) C[i][j] = ad(C[i - 1][j - 1], C[i - 1][j]);
  }
}
int a[maxn], len, num[maxn], f[maxn][maxn];
int main() {
  int n, x, c, d;
  scanf("%d", &n);
  yu();
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[i] = 1;
    for (int j = 2; j * j <= x; j++)
      if (x % j == 0) {
        c = 0;
        while (x % j == 0) x /= j, c ^= 1;
        if (c) a[i] *= j;
      }
    if (x != 1) a[i] *= x;
  }
  sort(a + 1, a + n + 1);
  int cc = 1;
  for (int i = 2; i <= n; i++)
    if (a[i] == a[i - 1])
      cc++;
    else
      num[++len] = cc, cc = 1;
  num[++len] = cc;
  sort(num + 1, num + len + 1, greater<int>());
  f[1][num[1] - 1] = 1;
  int s = 0;
  for (int i = 1; i < len; i++) {
    s += num[i];
    for (int j = 0; j < n; j++)
      if (f[i][j])
        for (int p = 0; p < num[i + 1]; p++)
          for (int k = 0; k <= j && k <= num[i + 1] - p; k++)
            if (j - k + p < n)
              f[i + 1][j - k + p] =
                  ad(f[i + 1][j - k + p],
                     mu(mu(C[j][k], C[s + 1 - j][num[i + 1] - p - k]),
                        mu(C[num[i + 1] - 1][num[i + 1] - p - 1], f[i][j])));
  }
  for (int i = 1; i <= len; i++) f[len][0] = mu(f[len][0], fac[num[i]]);
  printf("%d\n", f[len][0]);
  return 0;
}

```