

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
高橋王国にて、 から までの番号のついた 人の国民が競技プログラミングの試験に参加しました。
試験は 回からなり、人 は 回目の試験で 位、 回目の試験で 位となりました。
なお、どちらの試験においても、複数人が同じ順位になることはありませんでした。すなわち、順位を表す数列 はそれぞれ の順列です。
高橋王国の大統領であるいろはちゃんは、この試験の結果に基づいて、 人の中から競技プログラミングの世界大会に出場する 人の代表を決めることになりました。
代表を決めるにあたって、以下が成立していなければなりません。
- 人 が代表であり、人 が代表でないような人の組 であって、 かつ であるようなものが存在してはならない。
- 言い換えると、 回の試験の双方で人 が人 よりも小さい順位を取っているにも拘らず、人 が代表で人 が代表でないということがあってはならない。
いろはちゃんは、ひとまず上記の条件を満たす代表の選び方の数を知りたいので、この数を求めてください。
ただし、この数は非常に大きくなる場合もあるので、 で割った余りを出力してください。
制約
- 入力は全て整数
- は の順列である。
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを整数として出力せよ。
入力例 1Copy
4 2 2 4 3 1 2 1 4 3
出力例 1Copy
3
- 人 と人 を代表にすることは問題ありません。
- 人 と人 を代表にすると、双方の試験で人 が人 よりも小さい順位を取っているため、 に対して問題文中の条件に違反します。
- 人 と人 を代表にすることは問題ありません。
- 人 と人 を代表にすると、 に対して問題文中の条件に違反します。
- 人 と人 を代表にすることは問題ありません。
- 人 と人 を代表にすると、 に対して問題文中の条件に違反します。
結局、求める答えは 通りです。
入力例 2Copy
33 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
出力例 2Copy
168558757
人から 人を選ぶ 通りの全てにおいて、問題文中の条件を満たします。
よって、 を で割った余りである を出力することとなります。
入力例 3Copy
15 7 4 9 7 5 6 13 2 11 3 1 12 14 15 10 8 4 14 9 12 7 15 1 2 8 11 3 5 13 6 10
出力例 3Copy
23
Score : points
Problem Statement
In the Kingdom of Takahashi, citizens numbered to took an examination of competitive programming.
There were two tests, and Citizen ranked -th in the first test and -th in the second test.
There were no ties in either test. That is, each of the sequences and is a permutation of .
Iroha, the president of the kingdom, is going to select citizens for the national team at the coming world championship of competitive programming.
The members of the national team must be selected so that the following is satisfied.
- There should not be a pair of citizens where Citizen is selected and Citizen is not selected such that and .
- In other words, if Citizen got a rank smaller than that of Citizen in both tests, it is not allowed to select Citizen while not selecting Citizen .
To begin with, Iroha wants to know the number of ways to select citizens for the national team that satisfy the condition above. Find it to help her.
Since this number can be enormous, print it modulo .
Constraints
- All values in input are integers.
- Each of and is a permutation of .
Input
Input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1Copy
4 2 2 4 3 1 2 1 4 3
Sample Output 1Copy
3
- It is fine to select Citizen and Citizen for the team.
- If Citizen and Citizen are selected, Citizen ranked higher than Citizen did in both tests, so the pair would violate the condition in the Problem Statement.
- It is fine to select Citizen and Citizen .
- If Citizen and Citizen are selected, the pair would violate the condition.
- It is fine to select Citizen and Citizen .
- If Citizen and Citizen are selected, the pair would violate the condition.
The final answer is .
Sample Input 2Copy
33 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Sample Output 2Copy
168558757
All ways of selecting from the citizens satisfy the requirement.
Therefore, we should print modulo , that is, .
Sample Input 3Copy
15 7 4 9 7 5 6 13 2 11 3 1 12 14 15 10 8 4 14 9 12 7 15 1 2 8 11 3 5 13 6 10
Sample Output 3Copy
23