

Time Limit: 4 sec / Memory Limit: 256 MB
配点 : 点
問題文
下図のように, 辺が 個の点からなる正三角形状に, 個の点が並んでいます. 上から 段目の左から 番目の点を で表すことにします(, ). また, を のすぐ左下の点, を のすぐ右下の点と呼ぶことにします.
高橋君は,この点を結んで, 個の折れ線 を描くことにしました. 各折れ線は, から始めて,「現在いる点のすぐ左下の点かすぐ右下の点を選び,現在いる点と選んだ点を直線で結んだのち,選んだ点へ移動する」 ことを 回繰り返すことで得られます. すなわち,ある が存在して,次が成り立ちます:
- 折れ線 は, 個の点 をこの順で結んでいる.
- に対して, または が成り立つ.
高橋君は,折れ線 が折れ線 の左に来ることはないように折れ線を描きたいです. つまり, に対して, が成り立ちます.
また,高橋君は,折れ線の曲がり方について 個の条件を満たすように折れ線を描かなければなりません. 番目の条件は で表され,これは次を意味します:
- のときは,折れ線 を描くとき, 回目の移動においては,その時いる点のすぐ左下の点を選ぶ.
- のときは,折れ線 を描くとき, 回目の移動においては,その時いる点のすぐ右下の点を選ぶ.
すなわち, を意味します.
高橋君が 個の折れ線を描く方法が何通りあるかを mod で求めてください.
注意
提出を行う前に,「コードテスト」を利用して実行時間を計測することを強く推奨する.
制約
- として同じ組は複数回与えられない.
入力
入力は以下の形式で標準入力から与えられる。
:
出力
高橋君が 個の折れ線を描く方法は何通りあるかを mod で出力せよ.
入力例 1Copy
3 2 1 1 2 0
出力例 1Copy
6
下図に示すように, 通りの描き方があります.ただし,赤線は折れ線 ,緑線は折れ線 を表します:
入力例 2Copy
3 2 2 1 1 1 2 1 0
出力例 2Copy
0
入力例 3Copy
5 4 2 1 3 1 4 2 0
出力例 3Copy
172
入力例 4Copy
20 20 0
出力例 4Copy
881396682
Score : points
Problem Statement
There are dots arranged to form an equilateral triangle whose sides consist of dots, as shown below. The -th dot from the left in the -th row from the top is denoted by (, ). Also, we will call immediately lower-left to , and immediately lower-right to .
Takahashi is drawing polygonal lines by connecting these dots. Each starts at , and visits the dot that is immediately lower-left or lower-right to the current dots times. More formally, there exist such that:
- connects the points , in this order.
- For each , either or holds.
Takahashi would like to draw these lines so that no part of is to the left of . That is, for each , must hold.
Additionally, there are conditions on the shape of the lines that must be followed. The -th condition is denoted by , which means:
- If , must visit the immediately lower-left dot for the -th move.
- If , must visit the immediately lower-right dot for the -th move.
That is, must hold.
In how many ways can Takahashi draw polygonal lines? Find the count modulo .
Notes
Before submission, it is strongly recommended to measure the execution time of your code using "Custom Test".
Constraints
- or
- No pair appears more than once as .
Input
Input is given from Standard Input in the following format:
:
Output
Print the number of ways for Takahashi to draw polygonal lines, modulo .
Sample Input 1Copy
3 2 1 1 2 0
Sample Output 1Copy
6
There are six ways to draw lines, as shown below. Here, red lines represent , and green lines represent .
Sample Input 2Copy
3 2 2 1 1 1 2 1 0
Sample Output 2Copy
0
Sample Input 3Copy
5 4 2 1 3 1 4 2 0
Sample Output 3Copy
172
Sample Input 4Copy
20 20 0
Sample Output 4Copy
881396682