#include <bits/stdc++.h>
static const int MAXN = 302;
static const int MODULUS = 1e9 + 7;
long long fact[MAXN], fact_inv[MAXN];
long long part[MAXN][MAXN] = {{0}};
inline long long qpow(long long base, int exp) {
  long long ans = 1;
  for (; exp; exp >>= 1, (base *= base) %= MODULUS)
    if (exp & 1) (ans *= base) %= MODULUS;
  return ans;
}
void prepare_magic() {
  fact[0] = 1;
  for (int i = 1; i < MAXN; ++i) fact[i] = fact[i - 1] * i % MODULUS;
  fact_inv[MAXN - 1] = qpow(fact[MAXN - 1], MODULUS - 2);
  for (int i = MAXN - 2; i >= 0; --i)
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % MODULUS;
  part[1][1] = 1;
  for (int i = 2; i < MAXN; ++i)
    for (int j = 1; j <= i; ++j)
      part[i][j] =
          (part[i - 1][j - 1] + part[i - 1][j] * (i - 1 + j)) % MODULUS;
}
inline long long binom(int n, int m) {
  if (n < m || m < 0) return 0;
  return fact[n] * fact_inv[m] % MODULUS * fact_inv[n - m] % MODULUS;
}
int n, a[MAXN];
std::vector<int> b[MAXN];
std::map<std::vector<int>, int> ct;
std::vector<int> c;
long long f[MAXN] = {0};
long long g[MAXN];
int main() {
  prepare_magic();
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    for (int j = 2; j * j <= a[i]; ++j)
      if (a[i] % j == 0) {
        bool parity = false;
        do {
          a[i] /= j;
          parity ^= 1;
        } while (a[i] % j == 0);
        if (parity) b[i].push_back(j);
      }
    if (a[i] > 1) b[i].push_back(a[i]);
    ++ct[b[i]];
  }
  for (auto p : ct) c.push_back(p.second);
  int accum = c.front();
  c.erase(c.begin());
  f[accum - 1] = fact[accum];
  for (int u : c) {
    memset(g, 0, sizeof g);
    for (int i = 0; i < accum; ++i)
      for (int j = 1; j <= u; ++j)
        for (int k = 0; k <= i && k <= j; ++k)
          (g[i - k + (u - j)] += f[i] * part[u][j] % MODULUS * binom(j, k) %
                                 MODULUS * binom(i, k) % MODULUS * fact[k] %
                                 MODULUS * binom(accum - i + 1, j - k) %
                                 MODULUS * fact[j - k] % MODULUS) %= MODULUS;
    memcpy(f, g, sizeof g);
    accum += u;
  }
  printf("%I64d\n", f[0]);
  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>
static const int MAXN = 302;
static const int MODULUS = 1e9 + 7;
long long fact[MAXN], fact_inv[MAXN];
long long part[MAXN][MAXN] = {{0}};
inline long long qpow(long long base, int exp) {
  long long ans = 1;
  for (; exp; exp >>= 1, (base *= base) %= MODULUS)
    if (exp & 1) (ans *= base) %= MODULUS;
  return ans;
}
void prepare_magic() {
  fact[0] = 1;
  for (int i = 1; i < MAXN; ++i) fact[i] = fact[i - 1] * i % MODULUS;
  fact_inv[MAXN - 1] = qpow(fact[MAXN - 1], MODULUS - 2);
  for (int i = MAXN - 2; i >= 0; --i)
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % MODULUS;
  part[1][1] = 1;
  for (int i = 2; i < MAXN; ++i)
    for (int j = 1; j <= i; ++j)
      part[i][j] =
          (part[i - 1][j - 1] + part[i - 1][j] * (i - 1 + j)) % MODULUS;
}
inline long long binom(int n, int m) {
  if (n < m || m < 0) return 0;
  return fact[n] * fact_inv[m] % MODULUS * fact_inv[n - m] % MODULUS;
}
int n, a[MAXN];
std::vector<int> b[MAXN];
std::map<std::vector<int>, int> ct;
std::vector<int> c;
long long f[MAXN] = {0};
long long g[MAXN];
int main() {
  prepare_magic();
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    for (int j = 2; j * j <= a[i]; ++j)
      if (a[i] % j == 0) {
        bool parity = false;
        do {
          a[i] /= j;
          parity ^= 1;
        } while (a[i] % j == 0);
        if (parity) b[i].push_back(j);
      }
    if (a[i] > 1) b[i].push_back(a[i]);
    ++ct[b[i]];
  }
  for (auto p : ct) c.push_back(p.second);
  int accum = c.front();
  c.erase(c.begin());
  f[accum - 1] = fact[accum];
  for (int u : c) {
    memset(g, 0, sizeof g);
    for (int i = 0; i < accum; ++i)
      for (int j = 1; j <= u; ++j)
        for (int k = 0; k <= i && k <= j; ++k)
          (g[i - k + (u - j)] += f[i] * part[u][j] % MODULUS * binom(j, k) %
                                 MODULUS * binom(i, k) % MODULUS * fact[k] %
                                 MODULUS * binom(accum - i + 1, j - k) %
                                 MODULUS * fact[j - k] % MODULUS) %= MODULUS;
    memcpy(f, g, sizeof g);
    accum += u;
  }
  printf("%I64d\n", f[0]);
  return 0;
}

```