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 mo = 1000000007;
int ans, n, t, x, y, k, b[1000005], u[1000005], d[1000005], p[1000005],
    a[1000005], o[1000005], e[1000005], s[1000005], c1[1000005], c2[1000005];
int main() {
  scanf("%d", &n);
  u[1] = o[1] = 1;
  for (int i = 2; i <= n; ++i) {
    if (!o[i]) p[++t] = i, o[i] = i, u[i] = i;
    for (int j = 1; j <= t; ++j) {
      x = p[j] * i;
      if (x > n) break;
      o[x] = p[j];
      if (i % p[j] == 0) {
        u[x] = u[i];
        break;
      } else
        u[x] = u[i] * p[j];
    }
  }
  e[1] = 1;
  for (int i = 1, j; i <= t; i = j)
    for (j = i; j <= t && n / p[j] == n / p[i]; ++j) e[p[j]] = p[i];
  for (int i = 1; i <= t; ++i)
    if (n / p[i] == 1) e[p[i]] = 1;
  b[1] = 1;
  for (int i = 2; i <= n; ++i) {
    k = 0;
    for (x = i; x != 1; x /= o[x]) d[++k] = o[x];
    for (int j = 1; j <= k; ++j)
      if (d[j] != d[j - 1]) x = x * e[d[j]];
    b[i] = d[k];
  }
  for (int i = 1; i <= n; ++i) ++s[u[i]];
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i]) {
      x = b[i];
      y = b[a[i]];
      if (u[i / x * e[x]] != u[a[i] / y * e[y]]) {
        puts("0");
        return 0;
      }
      if (c1[x] && c1[x] != y || c2[y] && c2[y] != x) {
        puts("0");
        return 0;
      }
      c1[x] = y;
      c2[y] = x;
      --s[u[i]];
    }
  }
  d[0] = ans = 1;
  for (int i = 1; i <= n; ++i) d[i] = 1ll * d[i - 1] * i % mo;
  for (int i = 1; i <= n; ++i) ans = 1ll * ans * d[s[i]] % mo;
  for (int i = 1; i <= n; ++i) s[i] = 0;
  for (int i = 1; i <= n; ++i)
    if (o[i] == i && !c1[i]) ++s[e[i]];
  for (int i = 1; i <= n; ++i) ans = 1ll * ans * d[s[i]] % mo;
  printf("%d\n", ans);
  return 0;
}
