Byteasar owns a deck of n cards. The slots that hold the cards are numbered 1 through n. He has practiced one particular shuffle so thoroughly that it always rearranges the deck in exactly the same way: whatever card sits in slot k is moved to slot ak. Because every card lands in a distinct slot, the sequence a1,a2,…,an is a permutation of 1,2,…,n.
Byteasar applies this same shuffle l times in a row. Write bk for the slot that ends up holding the card which started in slot k. Formally, set ak(1)=ak and ak(t)=aak(t−1) for t≥2; then bk=ak(l).
You are told n, l, and the whole sequence b1,b2,…,bn. Count how many shuffles are consistent with what Byteasar saw, that is, how many permutations a satisfy ak(l)=bk for every k. The number of such shuffles can be enormous, so report it modulo 109+7. If no shuffle can produce b, the answer is 0.
The first line contains two integers n and l (1≤n,l≤106). Each of the next n lines contains a single integer: the k-th of them is bk (1≤bk≤n), the slot holding the card from slot k after the shuffle has been repeated l times. The values b1,…,bn are guaranteed to form a permutation of 1,…,n.
Print one integer: the number of shuffles a (permutations of 1,…,n) for which repeating a exactly l times yields the given sequence b, taken modulo 109+7. Print 0 if no such shuffle exists.