#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize(2)
using namespace std;
const int maxn = 305;
const int inf32 = 1e9;
const long long inf64 = 1e18;
const int mod = 1e9 + 7;
int add(int first, int second) {
  long long ans = first;
  ans += second;
  if (ans >= mod) ans -= mod;
  return ans;
}
int mul(int first, int second) { return (long long)first * second % mod; }
int a[maxn], fa[maxn], M, N, t[maxn], sz[maxn];
int find(int first) {
  return first == fa[first] ? first : fa[first] = find(fa[first]);
}
void unite(int first, int second) {
  first = find(first);
  second = find(second);
  if (first != second) {
    fa[first] = second;
  }
}
int g[maxn][maxn], dp[maxn][maxn], C[maxn][maxn], F[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> a[i], fa[i] = i;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      if (i == j) continue;
      long long v = (long long)a[i] * a[j];
      long long vv = sqrt(v);
      if (vv * vv == v) {
        unite(i, j);
      }
    }
  }
  for (int i = 1; i <= N; ++i) {
    ++t[find(i)];
  }
  M = 0;
  for (int i = 1; i <= N; ++i) {
    if (t[i]) {
      ++M;
      sz[M] = t[i];
    }
  }
  g[0][0] = 1;
  C[0][0] = 1;
  F[0] = 1;
  for (int i = 1; i <= N; ++i) {
    F[i] = mul(F[i - 1], i);
    for (int j = 1; j <= i; ++j) {
      g[i][j] = add(g[i][j], g[i - 1][j - 1]);
      g[i][j] = add(g[i][j], mul(g[i - 1][j], i + j - 1));
    }
    for (int j = 0; j <= i; ++j) {
      if (j == 0 || j == i) {
        C[i][j] = 1;
      } else {
        C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);
      }
    }
  }
  int prefix = 0;
  dp[0][0] = 1;
  for (int i = 0; i < M; ++i) {
    for (int j = 0; j <= prefix; ++j) {
      for (int first = 1; first <= sz[i + 1]; ++first) {
        for (int second = 0; second <= min(j, first); ++second) {
          int nj = j + sz[i + 1] - first - second;
          int val = g[sz[i + 1]][first];
          val = mul(val, C[first][second]);
          val = mul(val, C[j][second]);
          val = mul(val, F[second]);
          val = mul(val, C[prefix + 1 - j][first - second]);
          val = mul(val, F[first - second]);
          dp[i + 1][nj] = add(dp[i + 1][nj], mul(val, dp[i][j]));
        }
      }
    }
    prefix += sz[i + 1];
  }
  cout << dp[M][0] << endl;
}

### Prompt

Please provide a cpp coded solution to the problem described below:

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>
#pragma GCC optimize(3)
#pragma GCC optimize(2)
using namespace std;
const int maxn = 305;
const int inf32 = 1e9;
const long long inf64 = 1e18;
const int mod = 1e9 + 7;
int add(int first, int second) {
  long long ans = first;
  ans += second;
  if (ans >= mod) ans -= mod;
  return ans;
}
int mul(int first, int second) { return (long long)first * second % mod; }
int a[maxn], fa[maxn], M, N, t[maxn], sz[maxn];
int find(int first) {
  return first == fa[first] ? first : fa[first] = find(fa[first]);
}
void unite(int first, int second) {
  first = find(first);
  second = find(second);
  if (first != second) {
    fa[first] = second;
  }
}
int g[maxn][maxn], dp[maxn][maxn], C[maxn][maxn], F[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> a[i], fa[i] = i;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      if (i == j) continue;
      long long v = (long long)a[i] * a[j];
      long long vv = sqrt(v);
      if (vv * vv == v) {
        unite(i, j);
      }
    }
  }
  for (int i = 1; i <= N; ++i) {
    ++t[find(i)];
  }
  M = 0;
  for (int i = 1; i <= N; ++i) {
    if (t[i]) {
      ++M;
      sz[M] = t[i];
    }
  }
  g[0][0] = 1;
  C[0][0] = 1;
  F[0] = 1;
  for (int i = 1; i <= N; ++i) {
    F[i] = mul(F[i - 1], i);
    for (int j = 1; j <= i; ++j) {
      g[i][j] = add(g[i][j], g[i - 1][j - 1]);
      g[i][j] = add(g[i][j], mul(g[i - 1][j], i + j - 1));
    }
    for (int j = 0; j <= i; ++j) {
      if (j == 0 || j == i) {
        C[i][j] = 1;
      } else {
        C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);
      }
    }
  }
  int prefix = 0;
  dp[0][0] = 1;
  for (int i = 0; i < M; ++i) {
    for (int j = 0; j <= prefix; ++j) {
      for (int first = 1; first <= sz[i + 1]; ++first) {
        for (int second = 0; second <= min(j, first); ++second) {
          int nj = j + sz[i + 1] - first - second;
          int val = g[sz[i + 1]][first];
          val = mul(val, C[first][second]);
          val = mul(val, C[j][second]);
          val = mul(val, F[second]);
          val = mul(val, C[prefix + 1 - j][first - second]);
          val = mul(val, F[first - second]);
          dp[i + 1][nj] = add(dp[i + 1][nj], mul(val, dp[i][j]));
        }
      }
    }
    prefix += sz[i + 1];
  }
  cout << dp[M][0] << endl;
}

```