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).
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class F_Coprime_Permutation {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        static final long MODULO = (long) (1e9 + 7);

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] p = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                p[i] = in.nextInt();
            }
            int[] invp = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                if (p[i] > 0) {
                    invp[p[i]] = i;
                }
            }
            int[] fact = new int[n + 1];
            fact[0] = 1;
            for (int i = 1; i <= n; ++i) {
                fact[i] = (int) (i * (long) fact[i - 1] % MODULO);
            }
            int[] smallestDivisor = new int[n + 1];
            int[] freedomByFrac = new int[n + 1];
            for (int prime = 2; prime <= n; ++prime)
                if (smallestDivisor[prime] == 0) {
                    smallestDivisor[prime] = prime;
                    if (prime * (long) prime <= n) {
                        for (int j = prime * prime; j <= n; j += prime) {
                            if (smallestDivisor[j] == 0) {
                                smallestDivisor[j] = prime;
                            }
                        }
                    }
                    ++freedomByFrac[n / prime];
                }
            int[] startFreedomByFrac = freedomByFrac.clone();
            int oneGroupFreedoms = 1 + freedomByFrac[1];
            for (int i = 1; i <= n; ++i) {
                if (i == 1 || (2 * i > n && smallestDivisor[i] == i)) {
                    int j = p[i];
                    if (j > 0) {
                        if (j == 1 || (2 * j > n && smallestDivisor[j] == j)) {
                            --oneGroupFreedoms;
                        } else {
                            out.println(0);
                            return;
                        }
                    }
                    j = invp[i];
                    if (j > 0) {
                        if (j == 1 || (2 * j > n && smallestDivisor[j] == j)) {
                        } else {
                            out.println(0);
                            return;
                        }
                    }
                }
            }
            int[] trickyDirect = new int[n + 1];
            int[] trickyInverse = new int[n + 1];
            int[] freedomInGroup = new int[n + 1];
            for (int i = 2; i <= n; ++i) {
                if (2 * i > n && smallestDivisor[i] == i) {
                    continue;
                }
                int group = 1;
                int tmp = i;
                int largest = -1;
                while (tmp > 1) {
                    int d = smallestDivisor[tmp];
                    largest = d;
                    group *= d;
                    while (tmp % d == 0) {
                        tmp /= d;
                    }
                }
                if (p[i] == 0) {
                    ++freedomInGroup[group];
                } else {
                    int group2 = 1;
                    int tmp2 = p[i];
                    int largest2 = -1;
                    while (tmp2 > 1) {
                        int d = smallestDivisor[tmp2];
                        largest2 = d;
                        group2 *= d;
                        while (tmp2 % d == 0) {
                            tmp2 /= d;
                        }
                    }
                    if (n / largest != n / largest2) {
                        out.println(0);
                        return;
                    }
                    if (group / largest != group2 / largest2) {
                        out.println(0);
                        return;
                    }
                    if (startFreedomByFrac[n / largest] > 1) {
                        if (trickyDirect[largest] != 0) {
                            if (trickyDirect[largest] != largest2) {
                                out.println(0);
                                return;
                            }
                        } else {
                            trickyDirect[largest] = largest2;
                            --freedomByFrac[n / largest];
                        }
                        if (trickyInverse[largest2] != 0) {
                            if (trickyInverse[largest2] != largest) {
                                out.println(0);
                                return;
                            }
                        } else {
                            trickyInverse[largest2] = largest;
                        }
                    } else {
                        if (largest != largest2) {
                            out.println(0);
                            return;
                        }
                    }
                }
            }
            long res = fact[oneGroupFreedoms];
            for (int i = 2; i <= n; ++i) {
                int cur = freedomInGroup[i];
                if (cur > 1) {
                    res = res * fact[cur] % MODULO;
                }
            }
            for (int i = 2; i <= n; ++i) {
                int cur = freedomByFrac[i];
                if (cur > 1) {
                    res = res * fact[cur] % MODULO;
                }
            }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

