Third grader's task
문제
While looking at the kitchen fridge, little boy Tyler noticed magnets with symbols, that can be aligned into a string .
Tyler likes strings, and especially those that are lexicographically less than string . After playing with magnets on the fridge he is wondering, how many distinct strings can be composed out of letters of string by rearranging them, so that the the resulting string is lexicographically less than string . Tyler is studying only in the third grade, so he can not answer this question. Help him to calculate the number of permutations of letters of string , that are lexicographically less than string .
We call string lexicographically less than string if one of the followings conditions is fulfilled:
- There exists such position of symbol that is presented in both strings, so that before -th symbol the strings are equal, and the -th symbol of string is less than -th symbol of string .
- String is the prefix of string .
Because the answer can be too large, print it modulo .
입력
The first line contains two integers and () --- lengths of strings and .
The second line contains integers () --- symbols of string .
The third line contains integers () --- symbols of string .
출력
Print the single integer --- the number of strings that are lexicographically less than , that can be composed by rearranging letters of string modulo .
힌트
In the first sample, we should count strings [1 2 2] and [2 1 2]. String [2 2 1] is lexicographically grater than string [2 1 2 1], so we do not count it.
In the second sample we should count all strings except [4 3 2 1], so the answer is .
In the third sample we should count only string [1 1 1 2].
예제
예제 1
3 4 1 2 2 2 1 2 1
2
예제 2
4 4 1 2 3 4 4 3 2 1
23
예제 3
4 3 1 1 1 2 1 1 2
1