#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ans = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) ans = ans * 10 + (c - '0'), c = getchar();
  return ans;
}
int vis[70], in[70], base[70], _st[70], n, m, T[1 << 22], lg[1 << 22],
    sz[1 << 22], size[1 << 22];
bool able[1 << 22];
long long fac[70], inv_fac[70], dp[1 << 22];
queue<int> q;
inline int bit(int S, int w) { return (S >> w - 1) & 1; }
inline long long ksm(long long x, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) (ans *= x) %= 1000000007;
    (x *= x) %= 1000000007;
    b >>= 1;
  }
  return ans;
}
struct node {
  int st[70], cnt[70], id[70], to[70], SZ;
  long long ans;
  node() {
    ans = SZ = 0;
    memset(st, 0, sizeof(st));
    memset(cnt, 0, sizeof(cnt));
    memset(id, 0, sizeof(id));
    memset(to, 0, sizeof(to));
  }
  inline void solve(int x) {
    q.push(x);
    vis[x] = 1;
    while (!q.empty()) {
      int x = q.front();
      st[++st[0]] = x;
      q.pop();
      for (int i = 1; i <= x - 1; i++)
        if (x % i == 0) cnt[i]++;
      for (int i = 1; i <= m; i++)
        if (in[i] && !vis[i] && (i % x == 0 || x % i == 0)) {
          vis[i] = 1;
          q.push(i);
        }
    }
    for (int i = 1; i <= m; i++)
      if (base[i] && cnt[i] >= 2) id[++id[0]] = i;
    memset(cnt, 0, sizeof(cnt));
    memset(_st, 0, sizeof(_st));
    for (int i = 1; i <= st[0]; i++)
      if (!base[st[i]]) {
        ++_st[0];
        for (int w = 1; w <= id[0]; w++)
          _st[_st[0]] |= (st[i] % id[w] == 0) << w - 1;
      }
    memset(st, 0, sizeof(st));
    sort(_st + 1, _st + _st[0] + 1);
    for (int i = 1; i <= _st[0]; i++) {
      if (_st[i] != st[st[0]]) st[++st[0]] = _st[i];
      cnt[st[0]]++;
      if (st[0]) SZ++;
    }
    able[0] = 1;
    for (int i = 1; i <= st[0]; i++)
      for (int w = 1; w <= st[0]; w++) to[i] |= ((st[i] & st[w]) != 0) << w - 1;
    int N = (1 << st[0]) - 1;
    memset(dp, 0, sizeof(dp));
    memset(size, 0, sizeof(size));
    memset(T, 0, sizeof(T));
    memset(able, 0, sizeof(able));
    for (int S = 0; S <= N; S++) {
      int fr = S ^ (S & -S), x = lg[S & -S];
      size[S] = size[fr] + cnt[x];
    }
    for (int S = 0; S <= N; S++) dp[S] = 0;
    able[0] = dp[0] = 1;
    for (int S = 0; S <= N; S++) {
      int fr = S ^ (S & -S), x = lg[S & -S];
      size[S] = size[fr] + cnt[x];
      able[S] = able[fr] && !bit(T[fr], x);
      if (able[S]) {
        T[S] = T[fr] | to[x];
        for (int x = 1; x <= st[0]; x++)
          if (bit(S, x)) {
            int F = S ^ (1 << x - 1);
            (dp[S] += dp[F] * cnt[x] % 1000000007 * fac[size[T[S]] - 1] %
                      1000000007 * inv_fac[size[T[F]]]) %= 1000000007;
          }
        (ans += ((sz[S] & 1) ? -1ll : 1ll) *
                (fac[size[N] - 1] * inv_fac[size[T[S]]] % 1000000007 * dp[S] %
                 1000000007 * size[N ^ T[S]])) %= 1000000007;
      }
      if (!st[0]) ans = 1;
    }
  }
  inline void pr() {
    printf("\nprime : ");
    for (int i = 1; i <= id[0]; i++) printf("%d ", id[i]);
    printf("\n");
    for (int i = 1; i <= st[0]; i++) {
      for (int w = 1; w <= id[0]; w++) printf("%d", bit(st[i], w));
      printf(" : cnt %d to %d\n", cnt[i], to[i]);
    }
    printf("size %d : ans %d\n_____\n", SZ, ans);
  }
} a[70];
int tot;
int main() {
  for (int i = 1; i <= (1 << 22) - 1; i++)
    lg[i] = lg[i >> 1] + 1, sz[i] = sz[i >> 1] + (i & 1);
  n = read();
  m = 60;
  fac[0] = 1;
  for (int i = 1; i <= m; i++) fac[i] = fac[i - 1] * i % 1000000007;
  inv_fac[0] = 1;
  for (int i = 1; i <= m; i++)
    inv_fac[i] = inv_fac[i - 1] * ksm(i, 1000000007 - 2) % 1000000007;
  for (int i = 1; i <= n; i++) in[read()] = 1;
  for (int i = 1; i <= m; i++)
    if (in[i] && !vis[i]) {
      base[i] = 1;
      for (int j = 1; j <= m / i; j++) vis[i * j] = 1;
    }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= m; i++)
    if (in[i] && !vis[i]) a[++tot].solve(i);
  long long ans = 1;
  int sum = 0;
  for (int i = 1; i <= tot; i++)
    if (a[i].SZ)
      (ans *= a[i].ans * ksm(fac[a[i].SZ - 1], 1000000007 - 2) % 1000000007) %=
          1000000007,
          sum += a[i].SZ - 1;
  (ans *= fac[sum]) %= 1000000007;
  printf("%lld\n", (ans + 1000000007) % 1000000007);
}
