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>
namespace IO {
const int maxin = 1000000;
const int maxout = 5000000;
char _Input[maxin + 10], *_beg, *_end;
char _Output[maxout], *_pointer = _Output;
inline void init() {
  int _ = fread(_Input, 1, maxin, stdin);
  _beg = _Input, _end = _Input + _;
}
inline void Getchar() {
  if (++_beg == _end) {
    int _ = fread(_Input, 1, maxin, stdin);
    _beg = _Input, _end = _Input + _;
  }
}
template <typename Type>
inline Type read() {
  Type x = 0, f = 1;
  while (!isdigit(*_beg)) {
    if (*_beg == '-') f = -1;
    Getchar();
  }
  while (isdigit(*_beg)) {
    x = x * 10 + *_beg - '0';
    Getchar();
  }
  return x * f;
}
template <typename Type>
inline void Write(Type x, char ln = '\n') {
  static Type owo[54], qwq = 0;
  if (x < 0) x = -x, *_pointer++ = '-';
  do owo[++qwq] = x % 10;
  while (x /= 10);
  while (qwq) *_pointer++ = '0' + owo[qwq--];
  *_pointer++ = ln;
}
inline int gets(char *s) {
  char *t = s;
  while (!isalpha(*_beg))
    ;
  do *s++ = *_beg;
  while (Getchar(), isalpha(*_beg));
  *s = 0;
  return s - t;
}
inline void puts(char *s, char ln = '\n') {
  while (*s) *_pointer++ = *s++;
  *_pointer++ = ln;
}
inline void output() {
  fwrite(_Output, _pointer - _Output, 1, stdout);
  _pointer = _Output;
}
}  // namespace IO
const int maxn = 1000000 + 10;
const int mod = 1e9 + 7;
int n;
int a[maxn];
int fac[maxn], sz[maxn];
int prime[maxn], cnt;
int max[maxn], divs[maxn];
int base[maxn], rem[maxn];
int range[maxn], tot[maxn];
int pot[maxn], bel[maxn];
bool vis[maxn];
inline void init() {
  fac[0] = rem[1] = base[1] = max[1] = divs[1] = 1;
  for (int i = 1; i < maxn; i++) fac[i] = (long long)fac[i - 1] * i % mod;
  for (int i = 2; i < maxn; i++) {
    if (!vis[i]) {
      prime[++cnt] = i;
      divs[i] = 1;
      max[i] = base[i] = i;
    }
    for (int j = 1, k; (k = prime[j] * i) < maxn; j++) {
      vis[k] = 1;
      max[k] = max[i];
      divs[k] = divs[i];
      base[k] = base[i];
      if (i % prime[j] == 0) break;
      divs[k]++;
      base[k] *= prime[j];
    }
    rem[i] = base[i] / max[i];
  }
  prime[cnt + 1] = maxn;
}
inline void exec() {
  int ans = 0;
  n = IO::read<int>();
  memset(sz, 0, sizeof(sz));
  memset(tot, 0, sizeof(tot));
  memset(pot, 0, sizeof(pot));
  memset(bel, 0, sizeof(bel));
  for (int i = 1; i <= n; a[i++] = IO::read<int>())
    ;
  for (int i = 1; i <= n; ++sz[base[i++]])
    ;
  for (int i = 1; prime[i] <= n; i++) tot[range[prime[i]] = n / prime[i]]++;
  tot[range[1] = 1]++;
  for (int i = 1; i <= n; i++) {
    if (!a[i]) continue;
    int val = a[i], loc = i;
    sz[base[val]]--;
    if (divs[val] != divs[loc]) goto WQNMLGDSBCNM;
    if (rem[val] != rem[loc]) goto WQNMLGDSBCNM;
    val = max[val], loc = max[loc];
    if (range[val] != range[loc]) goto WQNMLGDSBCNM;
    if (bel[val] && bel[val] != loc) goto WQNMLGDSBCNM;
    if (pot[loc] && pot[loc] != val) goto WQNMLGDSBCNM;
    tot[range[val]] -= !bel[val];
    bel[pot[loc] = val] = loc;
  }
  ans = 1;
  for (int i = 1; i <= n; i++)
    ans = (long long)ans * fac[sz[i]] % mod * fac[tot[i]] % mod;
WQNMLGDSBCNM:
  IO::Write(ans);
}
int main() {
  if (fopen("perm.in", "r") != NULL) {
    freopen("perm.in", "r", stdin);
    freopen("perm.out", "w", stdout);
  }
  IO::init();
  init();
  exec();
  IO::output();
  return 0;
}
