Two positive integers are coprime if and only if they don't have a common divisor greater than 1.

Some bear doesn't want to tell Radewoosh how to solve some algorithmic problem. So, Radewoosh is going to break into that bear's safe with solutions. To pass through the door, he must enter a permutation of numbers 1 through n. The door opens if and only if an entered permutation p1, p2, ..., pn satisfies:

<image>

In other words, two different elements are coprime if and only if their indices are coprime. 

Some elements of a permutation may be already fixed. In how many ways can Radewoosh fill the remaining gaps so that the door will open? Print the answer modulo 109 + 7.

Input

The first line of the input contains one integer n (2 ≤ n ≤ 1 000 000).

The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n) where pi = 0 means a gap to fill, and pi ≥ 1 means a fixed number.

It's guaranteed that if i ≠ j and pi, pj ≥ 1 then pi ≠ pj.

Output

Print the number of ways to fill the gaps modulo 109 + 7 (i.e. modulo 1000000007).

Examples

Input

4
0 0 0 0


Output

4


Input

5
0 0 1 2 0


Output

2


Input

6
0 0 1 2 0 0


Output

0


Input

5
5 3 4 2 1


Output

0

Note

In the first sample test, none of four element is fixed. There are four permutations satisfying the given conditions: (1,2,3,4), (1,4,3,2), (3,2,1,4), (3,4,1,2).

In the second sample test, there must be p3 = 1 and p4 = 2. The two permutations satisfying the conditions are: (3,4,1,2,5), (5,4,1,2,3).
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
int to[maxn], bp[maxn], cnt[maxn], cnt2[maxn], fac[maxn];
int who[maxn], rwho[maxn], n;
void add(int a, int b) {
  if ((n / a) != (n / b)) cout << 0 << endl, exit(0);
  if (who[a] == 0) who[a] = b, cnt2[n / a]--;
  if (rwho[b] == 0) rwho[b] = a;
  if (who[a] != b) cout << 0 << endl, exit(0);
  if (rwho[b] != a) cout << 0 << endl, exit(0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    to[i] = 1;
    fac[i] = 1ll * i * fac[i - 1] % mod;
  }
  cnt[1]++;
  for (int i = 2; i <= n; i++) {
    if (to[i] == 1) {
      cnt2[n / i]++;
      for (int j = i; j <= n; j += i) to[j] *= i, bp[j] = i;
      if (2 * i > n) to[i] = 1;
    }
    cnt[to[i]]++;
  }
  int SQ = sqrt(n) + 1;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x != 0) {
      if (to[x] != to[i]) {
        if (to[i] == 1 || to[x] == 1) return cout << 0 << endl, 0;
        int A = bp[x], B = bp[i];
        if (A >= SQ && B >= SQ && to[x / A] == to[i / B])
          add(A, B);
        else
          return cout << 0 << endl, 0;
      } else if (to[i] != 1) {
        if (bp[i] >= SQ) add(bp[i], bp[i]);
      }
      cnt[to[i]]--;
    }
  }
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    ans = 1ll * ans * fac[cnt[i]] % mod;
  }
  for (int i = 2; i <= n; i++) {
    ans = 1ll * ans * fac[cnt2[i]] % mod;
  }
  return cout << ans << endl, 0;
}
