#Lutece1056. Just a simple problem again
Just a simple problem again
Migrated from Lutece 1056 Just a simple problem again
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Suffix number i of a string is the suffix that starts with the character . For example, for abcde
suffix is abcde
and suffix is de
.
The suffix array of a string is defined as the permutation of suffix numbers that corresponds to their lexicographic order. For example, suppose that abca
. If we order all suffixes of lexicographically, we get the following: a
< abca
< bca
< ca
. The corresponding suffix numbers are , , , and , in this order. Thus, for this string S the suffix array would be . Note that the length of a suffix array is the same as the length of the original string.
Now Alice is given an array : the suffix array of an unknown string. She is wondering how many possible strings satisfying this array if the size of charset is .
As is known to everyone of you, Bob loves Alice very much. Could you tell Bob the answer to help Bob leave a good impression on Alice.
Input
The first line contains integers and , indicating the length of the suffix array and the size of charset.
The next line contains integers , indicating the element in the suffix array.
It is guaranteed that the suffix array is a permutation of , and
Output
Print the answer module 1000000007 in one line.
Samples
3 2
0 2 1
1
Resources
The 13th UESTC Programming Contest Final