Impostors

Time limit: 1s Memory limit: 256MB Input: Output:

There are NN rooms in a row and NN impostors such that initially (at second t=0t = 0), the impostor ii is in room ii. From room ii, there is a directed vent to room pip_i, such that no two vents have the same destination (forming a permutation of integers from 11 to NN). The impostors move in the following way: the impostor who was in room ii at second tt will move ("vent") to room pip_i at second t+1t + 1.

After KK seconds you can track where each impostor is: the ithi^{th} is in room qiq_i. Now, you wonder: how many vent configurations (permutations pp) can lead to this? Since the answer can be very large, output it modulo 109+710^9 + 7. Note that your tracking device might be faulty, so the answer can be 00.

Task

Write a program that, knowing N,KN, K and the position of each impostor after KK seconds, calculates how many possible vent permutations exist.

Input Data

The first line of input contains two integers NN and KK.

The second line contains NN integers qiq_i (1qiN1 \leq q_i \leq N), representing the positions of the impostors after KK seconds. It is guaranteed that qq forms a permutation of integers from 11 to NN.

Output Data

The output consists of one integer: the number (modulo 109+710^9 + 7) of permutations pp, such that after KK seconds, impostor ii would be in room qiq_i for each ii.

Restrictions

  • 2N1052 \leq N \leq 10^5
  • 2K10182 \leq K \leq 10^{18}.
# Points Restrictions
1 11 N8N \leq 8 and K20K \leq 20
2 11 N14N \leq 14
3 28 K=2K = 2
4 16 N500N \leq 500
5 20 N104N \leq 10^4
6 14 No additional restrictions

Example 1

stdin

3 3
1 2 3

stdout

3

The valid permutations pp are (1,2,3),(2,3,1)(1, 2, 3), (2, 3, 1) and (3,1,2)(3, 1, 2).

Example 2

stdin

5 2
3 1 5 4 2

stdout

0

Log in or sign up to be able to send submissions!