#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int INF = 0x7f7f7f7f;
const long long INFLL = 0x7f7f7f7f7f7f7f7f;
vector<int> primes;
void init() {
  bitset<40000> notprime;
  notprime[0] = notprime[1] = true;
  for (int i = 2; i < 200; i++) {
    if (notprime[i]) {
      for (int j = i * i; j < 40000; j += i) notprime[j] = true;
    }
  }
  for (int i = 0; i < 40000; i++)
    if (notprime[i] == false) primes.push_back(i);
}
int nonsquare(int n) {
  int ans = 1;
  int lim = sqrt(n);
  for (int i = 0; primes[i] <= lim; i++) {
    if (n % primes[i] == 0) {
      int count = 0;
      while (n % primes[i] == 0) {
        n /= primes[i];
        count++;
      }
      if (count % 2 == 1) ans *= primes[i];
    }
  }
  if (n > 1) {
    ans *= n;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
Easy_DP:
  init();
  int n;
  cin >> n;
  int arr[n];
  map<int, int> group;
  vector<int> count;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    int res = nonsquare(arr[i]);
    if (!group.count(res)) {
      group.insert(pair<int, int>(res, count.size()));
      count.push_back(1);
    } else {
      count[group[res]]++;
    }
  }
  sort(count.begin(), count.end(), greater<int>());
  vector<int> num;
  vector<int> begin;
  int start = 0;
  for (int i = 0; i < count.size(); i++) {
    for (int j = 0; j < count[i]; j++) {
      begin.push_back(start);
      num.push_back(i);
    }
    start += count[i];
  }
  long long dp[n + 2][n + 2][n + 2];
  memset(dp, 0, sizeof(dp));
  dp[1][0][0] = 1;
  for (int i = 1; i < n; i++) {
    if (num[i] != num[i - 1]) {
      for (int j = 0; j < i; j++) {
        for (int k = 1; k <= j; k++) {
          dp[i][j][0] += dp[i][j][k];
          dp[i][j][k] = 0;
        }
      }
    }
    for (int j = 0; j < i; j++) {
      for (int k = 0; k <= j; k++) {
        dp[i + 1][j + 1][k + 1] =
            (dp[i + 1][j + 1][k + 1] +
             (dp[i][j][k] * (2 * (i - begin[i]) - k)) % MOD) %
            MOD;
        if (j > 0)
          dp[i + 1][j - 1][k] =
              (dp[i + 1][j - 1][k] + (dp[i][j][k] * (j - k)) % MOD) % MOD;
        dp[i + 1][j][k] =
            (dp[i + 1][j][k] +
             (dp[i][j][k] * (i + 1 - (2 * (i - begin[i]) - k + j - k))) % MOD) %
            MOD;
      }
    }
  }
  cout << dp[n][0][0] << endl;
  return 0;
}
