#include <bits/stdc++.h>
using namespace std;
int n, cnt, a[305];
int dp[305][305][305];
void del(int &x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % (i * i) == 0)
      while (x % (i * i) == 0) x /= i * i;
}
void add(int &x, int y) { x = (x + y) % 1000000007; }
int mul(int x, int y) { return (long long)x * y % 1000000007; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    del(a[i]);
  }
  sort(a + 1, a + n + 1);
  dp[1][0][0] = 1, cnt = 1;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != a[i - 1]) {
      for (int j = 0; j <= i; ++j)
        for (int k = 1; k <= cnt; ++k) {
          add(dp[i - 1][j][0], dp[i - 1][j][k]);
          dp[i - 1][j][k] = 0;
        }
      cnt = 0;
    }
    for (int j = 0; j <= i; ++j)
      for (int k = 0; k <= min(j, cnt); ++k) {
        if (j && k)
          add(dp[i][j][k], mul(dp[i - 1][j - 1][k - 1], cnt + cnt - k + 1));
        add(dp[i][j][k], mul(dp[i - 1][j + 1][k], j + 1 - k));
        add(dp[i][j][k], mul(dp[i - 1][j][k], i - j - (cnt + cnt - k - k)));
      }
    ++cnt;
  }
  printf("%d\n", dp[n][0][0]);
  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;
int n, cnt, a[305];
int dp[305][305][305];
void del(int &x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % (i * i) == 0)
      while (x % (i * i) == 0) x /= i * i;
}
void add(int &x, int y) { x = (x + y) % 1000000007; }
int mul(int x, int y) { return (long long)x * y % 1000000007; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    del(a[i]);
  }
  sort(a + 1, a + n + 1);
  dp[1][0][0] = 1, cnt = 1;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != a[i - 1]) {
      for (int j = 0; j <= i; ++j)
        for (int k = 1; k <= cnt; ++k) {
          add(dp[i - 1][j][0], dp[i - 1][j][k]);
          dp[i - 1][j][k] = 0;
        }
      cnt = 0;
    }
    for (int j = 0; j <= i; ++j)
      for (int k = 0; k <= min(j, cnt); ++k) {
        if (j && k)
          add(dp[i][j][k], mul(dp[i - 1][j - 1][k - 1], cnt + cnt - k + 1));
        add(dp[i][j][k], mul(dp[i - 1][j + 1][k], j + 1 - k));
        add(dp[i][j][k], mul(dp[i - 1][j][k], i - j - (cnt + cnt - k - k)));
      }
    ++cnt;
  }
  printf("%d\n", dp[n][0][0]);
  return 0;
}

```