Shuffle

No attempts yetTime limit3sMemory limit128 MB

Problem

Byteasar owns a deck of nn cards. The slots that hold the cards are numbered 11 through nn. He has practiced one particular shuffle so thoroughly that it always rearranges the deck in exactly the same way: whatever card sits in slot kk is moved to slot aka_k. Because every card lands in a distinct slot, the sequence a1,a2,,ana_1, a_2, \dots, a_n is a permutation of 1,2,,n1, 2, \dots, n.

Byteasar applies this same shuffle ll times in a row. Write bkb_k for the slot that ends up holding the card which started in slot kk. Formally, set ak(1)=aka^{(1)}_k = a_k and ak(t)=aak(t1)a^{(t)}_k = a_{a^{(t-1)}_k} for t2t \ge 2; then bk=ak(l)b_k = a^{(l)}_k.

You are told nn, ll, and the whole sequence b1,b2,,bnb_1, b_2, \dots, b_n. Count how many shuffles are consistent with what Byteasar saw, that is, how many permutations aa satisfy ak(l)=bka^{(l)}_k = b_k for every kk. The number of such shuffles can be enormous, so report it modulo 109+710^9 + 7. If no shuffle can produce bb, the answer is 00.

Input

The first line contains two integers nn and ll (1n,l1061 \le n, l \le 10^6). Each of the next nn lines contains a single integer: the kk-th of them is bkb_k (1bkn1 \le b_k \le n), the slot holding the card from slot kk after the shuffle has been repeated ll times. The values b1,,bnb_1, \dots, b_n are guaranteed to form a permutation of 1,,n1, \dots, n.

Output

Print one integer: the number of shuffles aa (permutations of 1,,n1, \dots, n) for which repeating aa exactly ll times yields the given sequence bb, taken modulo 109+710^9 + 7. Print 00 if no such shuffle exists.