

Time Limit: 8 sec / Memory Limit: 256 MiB
配点 : 点
問題文
joisinoお姉ちゃんは、高橋町を観光する計画を立てています。 高橋町は、正方形の区画が東西南北に敷き詰められた形をしており、 西から 番目、北から 番目の区画を区画 と呼ぶことにします。
joisinoお姉ちゃんは、以下の条件を満たす観光計画を、よい観光計画だと思っています。
-
観光を始める区画を区画 としたときに、 , を満たしている。
-
お昼ごはんを食べる区画を区画 としたときに、 , を満たしている。
-
観光を終了する区画を区画 としたときに、 , を満たしている。
-
観光の開始地点から終了地点まで、お昼ごはんを食べる区画を通りながら、隣接する(辺を共有する)区画への移動を繰り返して、最短距離で移動している。
ある二つの観光計画は、観光を開始する区画、お昼ご飯を食べる区画、観光を終了する区画、または途中で訪れる区画が異なる時、異なる観光計画とみなされます。 joisinoお姉ちゃんは、よい観光計画が何通りあるかを知りたくなりました。 よい観光計画が何通りあるかを求めてください。 なお、答えは非常に大きくなることがあるので、 で割った余りを求めてください。
制約
入力
入力は以下の形式で標準入力から与えられる。
出力
よい観光計画が何通りあるかを求め、その値を で割った余りを出力せよ。
入力例 1Copy
1 1 2 2 3 4 1 1 2 2 3 3
出力例 1Copy
10
観光を開始する区画は必ず区画 に、お昼ご飯を食べる区画は必ず区画 になります。 観光を終了する区画が区画 のとき、移動する方法は 通りあります。 観光を終了する区画が区画 のとき、移動する方法は 通りあります。 よって、この例の答えは 通りになります。
入力例 2Copy
1 2 3 4 5 6 1 2 3 4 5 6
出力例 2Copy
2346
入力例 3Copy
77523 89555 420588 604360 845669 973451 2743 188053 544330 647651 709337 988194
出力例 3Copy
137477680
Score : points
Problem Statement
Joisino is planning on touring Takahashi Town. The town is divided into square sections by north-south and east-west lines. We will refer to the section that is the -th from the west and the -th from the north as .
Joisino thinks that a touring plan is good if it satisfies the following conditions:
-
Let be the section where she starts the tour. Then, and hold.
-
Let be the section where she has lunch. Then, and hold.
-
Let be the section where she ends the tour. Then, and hold.
-
By repeatedly moving to the adjacent section (sharing a side), she travels from the starting section to the ending section in the shortest distance, passing the lunch section on the way.
Two touring plans are considered different if at least one of the following is different: the starting section, the lunch section, the ending section, and the sections that are visited on the way. Joisino would like to know how many different good touring plans there are. Find the number of the different good touring plans. Since it may be extremely large, find the count modulo .
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the number of the different good touring plans, modulo .
Sample Input 1Copy
1 1 2 2 3 4 1 1 2 2 3 3
Sample Output 1Copy
10
The starting section will always be , and the lunch section will always be . There are four good touring plans where is the ending section, and six good touring plans where is the ending section. Therefore, the answer is .
Sample Input 2Copy
1 2 3 4 5 6 1 2 3 4 5 6
Sample Output 2Copy
2346
Sample Input 3Copy
77523 89555 420588 604360 845669 973451 2743 188053 544330 647651 709337 988194
Sample Output 3Copy
137477680