#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, p = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') p = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * p;
}
inline void File() {
  freopen("C.in", "r", stdin);
  freopen("C.out", "w", stdout);
}
const int N = 300 + 10, mod = 1e9 + 7;
int dp[N][N], C[N][N], n, a[N], m, sz[N];
int sum, ans, fac[N];
inline int add(int a, int b) { return a + b > mod ? a + b - mod : a + b; }
inline void Init() {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
  for (int i = 0; i <= n; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; ++i)
    if (a[i] ^ a[i - 1])
      sz[++m] = 1;
    else
      ++sz[m];
}
int main() {
  n = read();
  for (int i = 1, x; i <= n; ++i) {
    x = read();
    for (int j = 2; j * j <= x; ++j)
      while (x % (j * j) == 0) x /= j * j;
    a[i] = x;
  }
  Init();
  dp[1][sz[1] - 1] = 1;
  for (int i = 2; i <= m; ++i) {
    sum += sz[i - 1];
    for (int j = 0; j <= sum - 1; ++j) {
      for (int k = 1; k <= sz[i]; ++k) {
        int r = min(k, j);
        for (int u = 0; u <= r; ++u)
          dp[i][j - u + sz[i] - k] =
              add(dp[i][j - u + sz[i] - k],
                  1ll * dp[i - 1][j] * C[sz[i] - 1][k - 1] % mod * C[j][u] %
                      mod * C[sum - j + 1][k - u] % mod);
      }
    }
  }
  int ans = dp[m][0];
  for (int i = 1; i <= m; ++i) ans = 1ll * ans * fac[sz[i]] % mod;
  cout << ans << endl;
  return 0;
}

### Prompt

Please create a solution in Cpp 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;
inline int read() {
  int x = 0, p = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') p = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * p;
}
inline void File() {
  freopen("C.in", "r", stdin);
  freopen("C.out", "w", stdout);
}
const int N = 300 + 10, mod = 1e9 + 7;
int dp[N][N], C[N][N], n, a[N], m, sz[N];
int sum, ans, fac[N];
inline int add(int a, int b) { return a + b > mod ? a + b - mod : a + b; }
inline void Init() {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
  for (int i = 0; i <= n; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; ++i)
    if (a[i] ^ a[i - 1])
      sz[++m] = 1;
    else
      ++sz[m];
}
int main() {
  n = read();
  for (int i = 1, x; i <= n; ++i) {
    x = read();
    for (int j = 2; j * j <= x; ++j)
      while (x % (j * j) == 0) x /= j * j;
    a[i] = x;
  }
  Init();
  dp[1][sz[1] - 1] = 1;
  for (int i = 2; i <= m; ++i) {
    sum += sz[i - 1];
    for (int j = 0; j <= sum - 1; ++j) {
      for (int k = 1; k <= sz[i]; ++k) {
        int r = min(k, j);
        for (int u = 0; u <= r; ++u)
          dp[i][j - u + sz[i] - k] =
              add(dp[i][j - u + sz[i] - k],
                  1ll * dp[i - 1][j] * C[sz[i] - 1][k - 1] % mod * C[j][u] %
                      mod * C[sum - j + 1][k - u] % mod);
      }
    }
  }
  int ans = dp[m][0];
  for (int i = 1; i <= m; ++i) ans = 1ll * ans * fac[sz[i]] % mod;
  cout << ans << endl;
  return 0;
}

```