#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr ll mod = 1e9 + 7;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  friend ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
  friend istream& operator>>(istream& is, mint& a) {
    ll t;
    is >> t;
    a = mint(t);
    return (is);
  }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  bool operator==(const mint a) const { return x == a.x; }
};
class combination {
 public:
  vector<mint> fact, inv, finv;
  combination(int N) {
    fact = inv = finv = vector<mint>(N + 1);
    fact[0] = fact[1] = 1;
    inv[0] = inv[1] = 1;
    finv[0] = finv[1] = 1;
    for (ll i = 2; i <= N; i++) {
      fact[i] = fact[i - 1] * i;
      inv[i] = (mint)mod - inv[mod % i] * (mod / i);
      finv[i] = finv[i - 1] * inv[i];
    }
  }
  mint f(int i) { return fact[i]; }
  mint comb(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fact[n] * finv[k] * finv[n - k];
  }
  mint hcomb(int n, int k) {
    if (n == 0 && k == 0) return 1;
    return comb(n + k - 1, k);
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  set<int> s;
  vec<map<int, int>> mp(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    int n = a;
    for (int j = 2; j * j <= a; j++) {
      while (n % j == 0) {
        s.insert(j);
        mp[i][j]++;
        n /= j;
      }
    }
    if (n != 1) {
      s.insert(n);
      mp[i][n]++;
    }
  }
  map<vec<int>, int> F;
  for (int i = 0; i < N; i++) {
    vec<int> v;
    for (auto& p : s) {
      v.push_back(mp[i][p] % 2);
    }
    F[v]++;
  }
  vec<mint> dp(N + 1);
  dp[0] = 1;
  combination C(N);
  int len = 0;
  for (auto& [p, c] : F) {
    vec<mint> ndp(N + 1);
    for (int j = 0; j <= len; j++)
      for (int r = 0; r <= j; r++) {
        for (int k = 1; k <= c; k++) {
          int dj = -r + (c - k);
          if (j + dj < 0 || j + dj > N) continue;
          ndp[j + dj] += dp[j] * C.comb(j, r) * C.comb(len + 1 - j, k - r) *
                         C.comb(c - 1, k - 1) * C.fact[c];
        }
      }
    len += c;
    dp.swap(ndp);
  }
  cout << dp[0] << "\n";
}

### Prompt

Construct a CPP code solution to the problem outlined:

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;
using ll = long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr ll mod = 1e9 + 7;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  friend ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
  friend istream& operator>>(istream& is, mint& a) {
    ll t;
    is >> t;
    a = mint(t);
    return (is);
  }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  bool operator==(const mint a) const { return x == a.x; }
};
class combination {
 public:
  vector<mint> fact, inv, finv;
  combination(int N) {
    fact = inv = finv = vector<mint>(N + 1);
    fact[0] = fact[1] = 1;
    inv[0] = inv[1] = 1;
    finv[0] = finv[1] = 1;
    for (ll i = 2; i <= N; i++) {
      fact[i] = fact[i - 1] * i;
      inv[i] = (mint)mod - inv[mod % i] * (mod / i);
      finv[i] = finv[i - 1] * inv[i];
    }
  }
  mint f(int i) { return fact[i]; }
  mint comb(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fact[n] * finv[k] * finv[n - k];
  }
  mint hcomb(int n, int k) {
    if (n == 0 && k == 0) return 1;
    return comb(n + k - 1, k);
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  set<int> s;
  vec<map<int, int>> mp(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    int n = a;
    for (int j = 2; j * j <= a; j++) {
      while (n % j == 0) {
        s.insert(j);
        mp[i][j]++;
        n /= j;
      }
    }
    if (n != 1) {
      s.insert(n);
      mp[i][n]++;
    }
  }
  map<vec<int>, int> F;
  for (int i = 0; i < N; i++) {
    vec<int> v;
    for (auto& p : s) {
      v.push_back(mp[i][p] % 2);
    }
    F[v]++;
  }
  vec<mint> dp(N + 1);
  dp[0] = 1;
  combination C(N);
  int len = 0;
  for (auto& [p, c] : F) {
    vec<mint> ndp(N + 1);
    for (int j = 0; j <= len; j++)
      for (int r = 0; r <= j; r++) {
        for (int k = 1; k <= c; k++) {
          int dj = -r + (c - k);
          if (j + dj < 0 || j + dj > N) continue;
          ndp[j + dj] += dp[j] * C.comb(j, r) * C.comb(len + 1 - j, k - r) *
                         C.comb(c - 1, k - 1) * C.fact[c];
        }
      }
    len += c;
    dp.swap(ndp);
  }
  cout << dp[0] << "\n";
}

```