Galois

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Third time Evariste is attempting the entrance examination for the École Polytechnique. He managed to solve all the tasks very quickly, but the examiner accuses him of lack of explanations. He tries to make Evariste fail and gives him the following task: for the given permutation pp of size NN, count the number of even permutations qq of size NN such that p_q_i=q_p_ip\_{q\_i} = q\_{p\_i} for all ii from 11 to NN. As this number can be very large, the examiner wants to know it modulo 109+710^9 + 7.

A permutation is said to be even if it contains an even number of inversions. An inversion of a permutation pp is a pair of indices (i,j)(i, j) such that i<ji < j and p_i>p_jp\_i > p\_j

Unfortunately for the examiner, who has no idea about the correct answer, Galois managed to solve the problem in only one second. You should help examiner and tell him the answer, or young Evariste will be denied again.

입력

The first line of the input contains a single integer NN, which denotes the length of the permutation (1N500,0001 \le N \le 500\\,000).

The second line describes the permutation pp itself and contains NN integers p_ip\_i (1p_iN1 \leq p\_i \leq N, p_ip_jp\_i \ne p\_j for all iji \ne j).

출력

Count the number of even permutations qq that satisfy the condition p_q_i=q_p_ip\_{q\_i} = q\_{p\_i}, and output it modulo 109+710^9 + 7.

힌트

In the first example there are three appropriate permutations: (1, 2, 3), (2, 3, 1), (3, 1, 2). All of them are even.

In the second example there are two appropriate permutations: (1, 2, 3), (2, 1, 3). However, only first of these permutations is even.