#include <bits/stdc++.h>
using namespace std;
const long long P = 1000000007;
int n;
int v[310];
long long f[2][310][310];
inline void upd(long long &x, const long long &y) {
  x += y;
  if (x >= P) x %= P;
}
int main() {
  scanf("%d", &n);
  int i, j, k, d = 0, tmp = 0, t;
  for (i = 1; i <= n; i++) {
    scanf("%d", &t), v[i] = 1;
    for (j = 2; j * j <= t; j++)
      if (t % j == 0) {
        tmp = 0;
        while (t % j == 0) tmp ^= 1, t /= j;
        if (tmp) v[i] *= j;
      }
    if (t > 1) v[i] *= t;
  }
  sort(v + 1, v + n + 1);
  f[0][0][0] = 1;
  for (i = 1; i <= n; i++) {
    if (v[i] > v[i - 1]) {
      for (j = 0; j <= i; j++)
        for (k = 1; k <= tmp; k++) upd(f[d][j][0], f[d][j][k]), f[d][j][k] = 0;
      tmp = 0;
    }
    d ^= 1, memset(f[d], 0, sizeof(f[d]));
    for (j = 0; j <= i; j++)
      for (k = 0; k <= tmp && k <= j; k++) {
        upd(f[d][j + 1][k + 1], f[d ^ 1][j][k] * (2 * tmp - k));
        if (j) upd(f[d][j - 1][k], f[d ^ 1][j][k] * (j - k));
        upd(f[d][j][k], f[d ^ 1][j][k] * (i - (2 * tmp - k) - (j - k)));
      }
    tmp++;
  }
  printf("%lld", f[d][0][0]);
  return 0;
}

### 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>
using namespace std;
const long long P = 1000000007;
int n;
int v[310];
long long f[2][310][310];
inline void upd(long long &x, const long long &y) {
  x += y;
  if (x >= P) x %= P;
}
int main() {
  scanf("%d", &n);
  int i, j, k, d = 0, tmp = 0, t;
  for (i = 1; i <= n; i++) {
    scanf("%d", &t), v[i] = 1;
    for (j = 2; j * j <= t; j++)
      if (t % j == 0) {
        tmp = 0;
        while (t % j == 0) tmp ^= 1, t /= j;
        if (tmp) v[i] *= j;
      }
    if (t > 1) v[i] *= t;
  }
  sort(v + 1, v + n + 1);
  f[0][0][0] = 1;
  for (i = 1; i <= n; i++) {
    if (v[i] > v[i - 1]) {
      for (j = 0; j <= i; j++)
        for (k = 1; k <= tmp; k++) upd(f[d][j][0], f[d][j][k]), f[d][j][k] = 0;
      tmp = 0;
    }
    d ^= 1, memset(f[d], 0, sizeof(f[d]));
    for (j = 0; j <= i; j++)
      for (k = 0; k <= tmp && k <= j; k++) {
        upd(f[d][j + 1][k + 1], f[d ^ 1][j][k] * (2 * tmp - k));
        if (j) upd(f[d][j - 1][k], f[d ^ 1][j][k] * (j - k));
        upd(f[d][j][k], f[d ^ 1][j][k] * (i - (2 * tmp - k) - (j - k)));
      }
    tmp++;
  }
  printf("%lld", f[d][0][0]);
  return 0;
}

```