#include <bits/stdc++.h>
using namespace std;
const int FACT_MAX = 200005;
long long fact[FACT_MAX], fact_inv[FACT_MAX];
long long modpow(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2) {
    return ((a % 1000000007) * (modpow(a, n - 1) % 1000000007)) % 1000000007;
  } else {
    return modpow((a * a) % 1000000007, n / 2) % 1000000007;
  }
}
void make_fact() {
  long long val = 1;
  fact[0] = 1;
  for (int i = 1; i < FACT_MAX; i++) {
    val *= i;
    val %= 1000000007;
    fact[i] = val;
  }
  fact_inv[FACT_MAX - 1] = modpow(fact[FACT_MAX - 1], 1000000007 - 2);
  for (int i = FACT_MAX - 2; i >= 0; i--) {
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % 1000000007;
  }
}
long long comb(long long n, long long k) {
  if (n < k || n < 0 || k < 0) return 0;
  long long ret = 1;
  ret *= fact[n];
  ret *= fact_inv[k], ret %= 1000000007;
  ret *= fact_inv[n - k], ret %= 1000000007;
  return ret;
}
long long n;
long long a[305];
long long dp[305][305];
map<long long, long long> mp;
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  make_fact();
  cin >> n;
  for (long long(i) = (1); (i) <= (n); (i)++) cin >> a[i];
  for (long long(i) = (1); (i) <= (n); (i)++) {
    map<long long, long long> mp;
    for (int j = 2; j * j <= a[i]; j++) {
      while (a[i] % j == 0) {
        mp[j]++;
        a[i] /= j;
      }
    }
    if (a[i] > 1) mp[a[i]]++;
    long long mul = 1;
    for (auto x : mp)
      if (x.second % 2) mul *= x.first;
    a[i] = mul;
  }
  for (long long(i) = (1); (i) <= (n); (i)++) mp[a[i]]++;
  vector<long long> vec;
  for (auto x : mp) vec.push_back(x.second);
  long long m = vec.size();
  dp[0][0] = 1;
  long long sum = 0;
  for (long long(i) = (0); (i) <= (m - 1); (i)++) {
    long long N = vec[i];
    for (long long(j) = (0); (j) <= (n); (j)++) {
      for (long long(k) = (0); (k) <= (N); (k)++) {
        for (long long(l) = (0); (l) <= (N); (l)++) {
          long long mul = comb(sum + 1 - j, k) * comb(j, l) % 1000000007;
          mul *= comb(N - 1, k + l - 1), mul %= 1000000007;
          mul *= fact[N], mul %= 1000000007;
          long long nj = j - l + N - (k + l);
          if (nj >= 0 && nj <= n)
            (dp[i + 1][nj] += mul * dp[i][j] % 1000000007) %= 1000000007;
        }
      }
    }
    sum += N;
  }
  cout << dp[m][0] << endl;
  return 0;
}

### Prompt

Generate 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;
const int FACT_MAX = 200005;
long long fact[FACT_MAX], fact_inv[FACT_MAX];
long long modpow(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2) {
    return ((a % 1000000007) * (modpow(a, n - 1) % 1000000007)) % 1000000007;
  } else {
    return modpow((a * a) % 1000000007, n / 2) % 1000000007;
  }
}
void make_fact() {
  long long val = 1;
  fact[0] = 1;
  for (int i = 1; i < FACT_MAX; i++) {
    val *= i;
    val %= 1000000007;
    fact[i] = val;
  }
  fact_inv[FACT_MAX - 1] = modpow(fact[FACT_MAX - 1], 1000000007 - 2);
  for (int i = FACT_MAX - 2; i >= 0; i--) {
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % 1000000007;
  }
}
long long comb(long long n, long long k) {
  if (n < k || n < 0 || k < 0) return 0;
  long long ret = 1;
  ret *= fact[n];
  ret *= fact_inv[k], ret %= 1000000007;
  ret *= fact_inv[n - k], ret %= 1000000007;
  return ret;
}
long long n;
long long a[305];
long long dp[305][305];
map<long long, long long> mp;
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  make_fact();
  cin >> n;
  for (long long(i) = (1); (i) <= (n); (i)++) cin >> a[i];
  for (long long(i) = (1); (i) <= (n); (i)++) {
    map<long long, long long> mp;
    for (int j = 2; j * j <= a[i]; j++) {
      while (a[i] % j == 0) {
        mp[j]++;
        a[i] /= j;
      }
    }
    if (a[i] > 1) mp[a[i]]++;
    long long mul = 1;
    for (auto x : mp)
      if (x.second % 2) mul *= x.first;
    a[i] = mul;
  }
  for (long long(i) = (1); (i) <= (n); (i)++) mp[a[i]]++;
  vector<long long> vec;
  for (auto x : mp) vec.push_back(x.second);
  long long m = vec.size();
  dp[0][0] = 1;
  long long sum = 0;
  for (long long(i) = (0); (i) <= (m - 1); (i)++) {
    long long N = vec[i];
    for (long long(j) = (0); (j) <= (n); (j)++) {
      for (long long(k) = (0); (k) <= (N); (k)++) {
        for (long long(l) = (0); (l) <= (N); (l)++) {
          long long mul = comb(sum + 1 - j, k) * comb(j, l) % 1000000007;
          mul *= comb(N - 1, k + l - 1), mul %= 1000000007;
          mul *= fact[N], mul %= 1000000007;
          long long nj = j - l + N - (k + l);
          if (nj >= 0 && nj <= n)
            (dp[i + 1][nj] += mul * dp[i][j] % 1000000007) %= 1000000007;
        }
      }
    }
    sum += N;
  }
  cout << dp[m][0] << endl;
  return 0;
}

```