#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int mod = 1e9 + 7;
const int MX = 305;
long long F[MX], invF[MX];
long long power(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = (ret * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ret;
}
void init() {
  F[0] = 1;
  for (int i = 1; i < MX; i++) F[i] = (F[i - 1] * i) % mod;
  invF[MX - 1] = power(F[MX - 1], mod - 2);
  for (int i = MX - 2; i >= 0; i--) {
    invF[i] = invF[i + 1] * (i + 1) % mod;
  }
}
long long C(int n, int m) {
  if (n < 0 || m < 0 || m > n) return 0;
  if (m == 0 || m == n) return 1;
  return F[n] * invF[n - m] % mod * invF[m] % mod;
}
long long a[MX];
int cnt[MX], vis[MX];
bool check(long long first) {
  long long l = 1, r = 1e9;
  while (l <= r) {
    long long m = (l + r) >> 1;
    if (m * m == first) return 1;
    if (m * m < first)
      l = m + 1;
    else
      r = m - 1;
  }
  return r * r == first;
}
long long dp[MX][MX];
int pre[MX];
inline long long mul(long long a, long long b, long long c) {
  return a * b % mod * c % mod;
}
int main() {
  init();
  int n;
  cin >> n;
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int sz = 0;
  for (int i = 0; i < (n); ++i)
    if (!vis[i]) {
      for (int j = i; j < (n); ++j)
        if (!vis[j] && check(a[i] * a[j])) cnt[sz]++, vis[j] = 1;
      sz++;
    }
  pre[0] = cnt[0];
  for (int i = 1; i < (sz); ++i) pre[i] = pre[i - 1] + cnt[i];
  dp[0][cnt[0] - 1] = F[cnt[0]];
  for (int i = 1; i < (sz); ++i) {
    for (int j = 0; j < (pre[i - 1]); ++j) {
      for (int q = 1; q < (cnt[i] + 1); ++q)
        for (int p = 0; p < (min(j + 1, q + 1)); ++p) {
          int k = j - p + cnt[i] - q;
          dp[i][k] +=
              dp[i - 1][j] *
              mul(C(cnt[i] - 1, q - 1), C(j, p), C(pre[i - 1] + 1 - j, q - p)) %
              mod;
          if (dp[i][k] >= mod) dp[i][k] -= mod;
        }
    }
    for (int j = 0; j < (pre[i]); ++j) dp[i][j] = dp[i][j] * F[cnt[i]] % mod;
  }
  cout << dp[sz - 1][0] << 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 int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int mod = 1e9 + 7;
const int MX = 305;
long long F[MX], invF[MX];
long long power(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = (ret * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ret;
}
void init() {
  F[0] = 1;
  for (int i = 1; i < MX; i++) F[i] = (F[i - 1] * i) % mod;
  invF[MX - 1] = power(F[MX - 1], mod - 2);
  for (int i = MX - 2; i >= 0; i--) {
    invF[i] = invF[i + 1] * (i + 1) % mod;
  }
}
long long C(int n, int m) {
  if (n < 0 || m < 0 || m > n) return 0;
  if (m == 0 || m == n) return 1;
  return F[n] * invF[n - m] % mod * invF[m] % mod;
}
long long a[MX];
int cnt[MX], vis[MX];
bool check(long long first) {
  long long l = 1, r = 1e9;
  while (l <= r) {
    long long m = (l + r) >> 1;
    if (m * m == first) return 1;
    if (m * m < first)
      l = m + 1;
    else
      r = m - 1;
  }
  return r * r == first;
}
long long dp[MX][MX];
int pre[MX];
inline long long mul(long long a, long long b, long long c) {
  return a * b % mod * c % mod;
}
int main() {
  init();
  int n;
  cin >> n;
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int sz = 0;
  for (int i = 0; i < (n); ++i)
    if (!vis[i]) {
      for (int j = i; j < (n); ++j)
        if (!vis[j] && check(a[i] * a[j])) cnt[sz]++, vis[j] = 1;
      sz++;
    }
  pre[0] = cnt[0];
  for (int i = 1; i < (sz); ++i) pre[i] = pre[i - 1] + cnt[i];
  dp[0][cnt[0] - 1] = F[cnt[0]];
  for (int i = 1; i < (sz); ++i) {
    for (int j = 0; j < (pre[i - 1]); ++j) {
      for (int q = 1; q < (cnt[i] + 1); ++q)
        for (int p = 0; p < (min(j + 1, q + 1)); ++p) {
          int k = j - p + cnt[i] - q;
          dp[i][k] +=
              dp[i - 1][j] *
              mul(C(cnt[i] - 1, q - 1), C(j, p), C(pre[i - 1] + 1 - j, q - p)) %
              mod;
          if (dp[i][k] >= mod) dp[i][k] -= mod;
        }
    }
    for (int j = 0; j < (pre[i]); ++j) dp[i][j] = dp[i][j] * F[cnt[i]] % mod;
  }
  cout << dp[sz - 1][0] << endl;
  return 0;
}

```