A - Diverse Word

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 300

問題文

ゴトウは辞書をもらいました。ところが、その辞書は知らない言語で書かれていました。 分析した結果、その辞書にはありうるすべての 多彩 な単語が辞書順に載っていることがわかりました。

単語は、それが英小文字からなる空でない文字列であって、単語内の文字がすべて異なる場合、そしてその場合に限って 多彩 であると呼ばれます。例えば、atcoderzscoderagc は多彩な単語ですが、gotouconnect は多彩な単語ではありません。

多彩な単語 S が与えられるので、この辞書で S の次に載っている単語、すなわち、S より辞書順で大きいような、辞書順で最小の多彩な単語を求めてください。あるいは、そのような単語は存在しないと判定してください。

なお、X = x_{1}x_{2}...x_{n}Y = y_{1}y_{2}...y_{m} を二つの異なる文字列とするとき、YX の接頭辞であるか、jx_{j} \neq y_{j} であるような最小の整数として x_{j} > y_{j} である場合、そしてその場合に限って XY より辞書順で大きいといいます。

制約

  • 1 \leq |S| \leq 26
  • S は多彩な単語である。

入力

入力は標準入力から以下の形式で与えられる。

S

出力

辞書で S の次に載っている単語を出力せよ。ただし、そのような単語が存在しない場合は -1 と出力せよ。


入力例 1

atcoder

出力例 1

atcoderb

atcoder より辞書順で大きいような、辞書順で最小の多彩な単語は atcoderb です。atcoderbb より辞書順で小さいことに注意してください。


入力例 2

abc

出力例 2

abcd

入力例 3

zyxwvutsrqponmlkjihgfedcba

出力例 3

-1

これが辞書順で最も大きい多彩な単語なので、答えは -1 です。


入力例 4

abcdefghijklmnopqrstuvwzyx

出力例 4

abcdefghijklmnopqrstuvx

Score : 300 points

Problem Statement

Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible diverse words in lexicographical order.

A word is called diverse if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, atcoder, zscoder and agc are diverse words while gotou and connect aren't diverse words.

Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist.

Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Constraints

  • 1 \leq |S| \leq 26
  • S is a diverse word.

Input

Input is given from Standard Input in the following format:

S

Output

Print the next word that appears after S in the dictionary, or -1 if it doesn't exist.


Sample Input 1

atcoder

Sample Output 1

atcoderb

atcoderb is the lexicographically smallest diverse word that is lexicographically larger than atcoder. Note that atcoderb is lexicographically smaller than b.


Sample Input 2

abc

Sample Output 2

abcd

Sample Input 3

zyxwvutsrqponmlkjihgfedcba

Sample Output 3

-1

This is the lexicographically largest diverse word, so the answer is -1.


Sample Input 4

abcdefghijklmnopqrstuvwzyx

Sample Output 4

abcdefghijklmnopqrstuvx
B - GCD Sequence

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 600

問題文

ナガセは高校の優等生です。ある日のこと、ナガセは正の整数からなる特別な集合のとある性質を分析しています。

ナガセの考えでは、異なる 正の整数の集合 S = \{a_{1}, a_{2}, ..., a_{N}\} は、以下の条件を満たす場合に 特別 であると呼ばれます。条件:どの 1 \leq i \leq N についても、a_{i} と、S のその他の要素の和の最大公約数は 1 ではない

ナガセは、要素数 N特別 な集合を求めたいです。ところがこれは簡単すぎるので、難易度を上げることにしました。要素数 N特別 な集合であって、すべての要素の最大公約数が 1 であり、どの要素も 30000 以下であるものを求めてみよ、とのことです。

制約

  • 3 \leq N \leq 20000

入力

入力は標準入力から以下の形式で与えられる。

N

出力

S の要素を表す N 個の整数を空白で区切って出力せよ。S は以下の条件を満たさなければならない。

  • 要素は 30000 以下の 異なる 正の整数でなければならない。
  • S のすべての要素の最大公約数は 1 である。すなわち、S のすべての要素を割り切るような整数 d > 1 は存在しない。
  • S特別 な集合である。

複数の解が存在する場合は、そのうちどれを出力してもよい。また、S の要素はどのような順番で出力してもよい。なお、与えられた制約の下で解が少なくとも一つ存在することが保証される。


入力例 1

3

出力例 1

2 5 63

\{2, 5, 63\} は特別です。なぜなら、gcd(2, 5 + 63) = 2, gcd(5, 2 + 63) = 5, gcd(63, 2 + 5) = 7 であり、さらに gcd(2, 5, 63) = 1 であるため、すべての判定条件を満たすからです。

なお、\{2, 4, 6\} は解として認められません。gcd(2, 4, 6) = 2 > 1 であるからです。


入力例 2

4

出力例 2

2 5 20 63

\{2, 5, 20, 63\} は特別です。なぜなら、gcd(2, 5 + 20 + 63) = 2, gcd(5, 2 + 20 + 63) = 5, gcd(20, 2 + 5 + 63) = 10, gcd(63, 2 + 5 + 20) = 9 であり、さらに gcd(2, 5, 20, 63) = 1 であるため、すべての判定条件を満たすからです。

Score : 600 points

Problem Statement

Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.

She thinks that a set S = \{a_{1}, a_{2}, ..., a_{N}\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.

Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.

Constraints

  • 3 \leq N \leq 20000

Input

Input is given from Standard Input in the following format:

N

Output

Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :

  • The elements must be distinct positive integers not exceeding 30000.
  • The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
  • S is a special set.

If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.


Sample Input 1

3

Sample Output 1

2 5 63

\{2, 5, 63\} is special because gcd(2, 5 + 63) = 2, gcd(5, 2 + 63) = 5, gcd(63, 2 + 5) = 7. Also, gcd(2, 5, 63) = 1. Thus, this set satisfies all the criteria.

Note that \{2, 4, 6\} is not a valid solution because gcd(2, 4, 6) = 2 > 1.


Sample Input 2

4

Sample Output 2

2 5 20 63

\{2, 5, 20, 63\} is special because gcd(2, 5 + 20 + 63) = 2, gcd(5, 2 + 20 + 63) = 5, gcd(20, 2 + 5 + 63) = 10, gcd(63, 2 + 5 + 20) = 9. Also, gcd(2, 5, 20, 63) = 1. Thus, this set satisfies all the criteria.

C - Remainder Game

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 700

問題文

アオキは数列 a_{1}, a_{2}, ..., a_{N} で遊んでいます。1 秒ごとに、アオキは次の操作を行います。

  • 正の整数 k を選ぶ。数列のそれぞれの要素 v について、アオキは v を「vk で割った余り」に置き換えるか、v をそのままにするかを選べる。この一連の操作のコストは(書き換えた要素の数によらず)2^{k} である。

アオキは、数列を b_{1}, b_{2}, ..., b_{N} に変えたいです(要素の順番も考慮します)。この目的を達成することが可能か判定し、可能である場合は必要な最小のコストを求めてください。

制約

  • 1 \leq N \leq 50
  • 0 \leq a_{i}, b_{i} \leq 50
  • 入力中の値はすべて整数である。

入力

入力は標準入力から以下の形式で与えられる。

N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}

出力

はじめの数列を b_{1}, b_{2}, ..., b_{N} に変えるのに必要な最小のコストを出力せよ。目的の達成が不可能である場合は、代わりに -1 と出力せよ。


入力例 1

3
19 10 14
0 3 4

出力例 1

160

操作手順の例を挙げます。

  • k = 7 を選ぶ。195 に、103 に置き換えて 14 はそのままにする。数列は 5, 3, 14 となる。
  • k = 5 を選ぶ。50 に置き換え、3 はそのままにして 144 に置き換える。数列は 0, 3, 4 となる。

合計コストは 2^{7} + 2^{5} = 160 です。


入力例 2

3
19 15 14
0 0 0

出力例 2

2

k = 1 を選び、すべてを 0 に変えるとよいです。コストは 2^{1} = 2 です。


入力例 3

2
8 13
5 13

出力例 3

-1

与えられた操作では 85 に変えることができないため、目的の達成は不可能です。


入力例 4

4
2 0 1 8
2 0 1 8

出力例 4

0

この場合は何もする必要がありません。コストは 0 です。


入力例 5

1
50
13

出力例 5

137438953472

オーバーフローにご注意。

Score : 700 points

Problem Statement

Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation :

  • Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes).

Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required.

Constraints

  • 1 \leq N \leq 50
  • 0 \leq a_{i}, b_{i} \leq 50
  • All values in the input are integers.

Input

Input is given from Standard Input in the following format:

N
a_{1} a_{2} ... a_{N}
b_{1} b_{2} ... b_{N}

Output

Print the minimum cost required to turn the original sequence into b_{1}, b_{2}, ..., b_{N}. If the task is impossible, output -1 instead.


Sample Input 1

3
19 10 14
0 3 4

Sample Output 1

160

Here's a possible sequence of operations :

  • Choose k = 7. Replace 19 with 5, 10 with 3 and do nothing to 14. The sequence is now 5, 3, 14.

  • Choose k = 5. Replace 5 with 0, do nothing to 3 and replace 14 with 4. The sequence is now 0, 3, 4.

The total cost is 2^{7} + 2^{5} = 160.


Sample Input 2

3
19 15 14
0 0 0

Sample Output 2

2

Aoki can just choose k = 1 and turn everything into 0. The cost is 2^{1} = 2.


Sample Input 3

2
8 13
5 13

Sample Output 3

-1

The task is impossible because we can never turn 8 into 5 using the given operation.


Sample Input 4

4
2 0 1 8
2 0 1 8

Sample Output 4

0

Aoki doesn't need to do anything here. The cost is 0.


Sample Input 5

1
50
13

Sample Output 5

137438953472

Beware of overflow issues.

D - Shopping

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 1600

問題文

ユイは買い物好きです。ユイはヤマボシ市に住んでいて、この市では鉄道が運行しています。ヤマボシ市はとても長い数直線としてモデル化することができ、ユイの家は座標 0 にあります。

ヤマボシ市には N 件のショッピングセンターがあり、それぞれ座標 x_{1}, x_{2}, ..., x_{N} にあります。鉄道の駅は N + 2 駅あり、座標 0 に一駅、座標 L に一駅、そして各ショッピングセンターに一駅ずつあります。

時刻 0 に、鉄道列車が座標 0 から正の方向に出発します。列車は毎秒 1 単位距離という一定の速さで移動します。時刻 L に、列車は終着駅、すなわち座標 L の駅に到着します。その直後に、列車は反対の方向に同じ速さで走り始めます。時刻 2L に、列車は座標 0 の駅に到着し、再び反対の方向に走り始めます。この行程が永遠に繰り返されます。

列車がユイのいる駅に到着したとき、ユイは直ちに列車に乗ったり降りたりすることができます。時刻 0 には、ユイは座標 0 の駅にいます。

ユイは N 件すべてのショッピングセンターに買い物に行きたいです。順番はなんでもよく、買い物が終わったら帰りたいです。座標 x_{i} のセンターでの買い物には t_{i} 秒がかかります。あるセンターで買い物を始めたら、次のセンターに行く前にそこでの買い物を完了しなければなりません。 センターのある駅に到着したら直ちに買い物を始めることができ、買い物が終わったら直ちに電車に乗ることができます。

ユイは、買い物にかかる時間を最短にしたいです。最短で何秒で買い物を済ませられるか、ユイが判断するのを手伝ってくれませんか?

制約

  • 1 \leq N \leq 300000
  • 1 \leq L \leq 10^{9}
  • 0 < x_{1} < x_{2} < ... < x_{N} < L
  • 1 \leq t_{i} \leq 10^{9}
  • 入力中のすべての値は整数である。

部分点

  • 1 \leq N \leq 3000 を満たすデータセットに正解すると、1000 点が与えられる。

入力

入力は標準入力から以下の形式で与えられる。

N L
x_{1} x_{2} ... x_{N}
t_{1} t_{2} ... t_{N}

出力

ユイが N 件すべてのショッピングセンターで買い物を済ませて帰宅するまでに必要な最短の時間を(秒単位で)出力せよ。


入力例 1

2 10
5 8
10 4

出力例 1

40

ユイが買い物を済ませる行程の例を示します。

  • 列車で座標 8 の駅まで移動する。時刻 8 に座標 8 に到着する。

  • 座標 8 のショッピングセンターで買い物をする。時刻 12 に買い物が完了する。

  • 時刻 12 に電車が座標 8 に到着する。負の方向に進んでいる電車に乗る。

  • 時刻 15 に座標 5 に到着する。時刻 25 に買い物が完了する。

  • 時刻 25 に電車が座標 5 に到着する。正の方向に進んでいる電車に乗る。

  • 時刻 30 に座標 L = 10 に到着する。列車は直ちに反対方向に走り始める。

  • 時刻 40 に座標 0 に到着し、行程を終了する。


入力例 2

2 10
5 8
10 5

出力例 2

60

入力例 3

5 100
10 19 28 47 68
200 200 200 200 200

出力例 3

1200

入力例 4

8 1000000000
2018 123456 1719128 1929183 9129198 10100101 77777777 120182018
99999999 1000000000 1000000000 11291341 1 200 1 123812831

出力例 4

14000000000

オーバーフローにご注意。

Score : 1600 points

Problem Statement

Yui loves shopping. She lives in Yamaboshi City and there is a train service in the city. The city can be modelled as a very long number line. Yui's house is at coordinate 0.

There are N shopping centres in the city, located at coordinates x_{1}, x_{2}, ..., x_{N} respectively. There are N + 2 train stations, one located at coordinate 0, one located at coordinate L, and one located at each shopping centre.

At time 0, the train departs from position 0 to the positive direction. The train travels at a constant speed of 1 unit per second. At time L, the train will reach the last station, the station at coordinate L. The train immediately moves in the opposite direction at the same speed. At time 2L, the train will reach the station at coordinate 0 and it immediately moves in the opposite direction again. The process repeats indefinitely.

When the train arrives at a station where Yui is located, Yui can board or leave the train immediately. At time 0, Yui is at the station at coordinate 0.

Yui wants to go shopping in all N shopping centres, in any order, and return home after she finishes her shopping. She needs to shop for t_{i} seconds in the shopping centre at coordinate x_{i}. She must finish her shopping in one shopping centre before moving to the next shopping centre. Yui can immediately start shopping when she reaches a station with a shopping centre and she can immediately board the train when she finishes shopping.

Yui wants to spend the minimum amount of time to finish her shopping. Can you help her determine the minimum number of seconds required to complete her shopping?

Constraints

  • 1 \leq N \leq 300000
  • 1 \leq L \leq 10^{9}
  • 0 < x_{1} < x_{2} < ... < x_{N} < L
  • 1 \leq t_{i} \leq 10^{9}
  • All values in the input are integers.

Partial Score

  • 1000 points will be awarded for passing the testset satisfying 1 \leq N \leq 3000.

Input

Input is given from Standard Input in the following format:

N L
x_{1} x_{2} ... x_{N}
t_{1} t_{2} ... t_{N}

Output

Print the minimum time (in seconds) required for Yui to finish shopping at all N shopping centres and return home.


Sample Input 1

2 10
5 8
10 4

Sample Output 1

40

Here's one possible way for Yui to finish her shopping :

  • Travel to the station at coordinate 8 with the train. She arrives at coordinate 8 at time 8.

  • Shop in the shopping centre at coordinate 8. She finishes her shopping at time 12.

  • The train arrives at coordinate 8 at time 12. She boards the train which is currently moving in the negative direction.

  • She arrives at coordinate 5 at time 15. She finishes her shopping at time 25.

  • The train arrives at coordinate 5 at time 25. She boards the train which is currently moving in the positive direction.

  • She arrives at coordinate L = 10 at time 30. The train starts moving in the negative direction immediately.

  • She arrives at coordinate 0 at time 40, ending the trip.


Sample Input 2

2 10
5 8
10 5

Sample Output 2

60

Sample Input 3

5 100
10 19 28 47 68
200 200 200 200 200

Sample Output 3

1200

Sample Input 4

8 1000000000
2018 123456 1719128 1929183 9129198 10100101 77777777 120182018
99999999 1000000000 1000000000 11291341 1 200 1 123812831

Sample Output 4

14000000000

Beware of overflow issues.

E - Median Replace

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 1600

問題文

タイチは、01 からなる奇数長 N の文字列 X は次の条件を満たすとき 美しい と考えています。条件:次の操作を \frac{N-1}{2} 回行って、最終的な文字列の唯一の文字を 1 にすることができる。

  • X連続する 3 つのビットを選び、それらの中央値でそれらを置き換える。例えば、00110 の中央の 3 ビットに操作を適用すると、この文字列は 010 となる。

タイチは 01? からなる文字列を持っています。この文字列の ? をそれぞれ 10 に置き換える方法であって、美しい文字列が得られるものの個数を 10^{9} + 7 で割った余りをタイチは知りたいです。

制約

  • 1 \leq |S| \leq 300000
  • |S| は奇数である。
  • S のすべての文字は 01? のいずれかである。

入力

入力は標準入力から以下の形式で与えられる。

S

出力

? を置き換える方法であって、美しい文字列が得られるものの個数を 10^{9} + 7 で割った余りを出力せよ。


入力例 1

1??00

出力例 1

2

?01 で置き換える方法は以下の 4 通りあります。

  • 11100 : この文字列は美しいです。なぜなら、まず最後の 3 ビットに操作を適用して 110 とし、次に文字列全体に操作を適用すると 1 となるからです。

  • 11000 : この文字列は美しいです。なぜなら、まず最後の 3 ビットに操作を適用して 110 とし、次に文字列全体に操作を適用すると 1 となるからです。

  • 10100 : この文字列は美しくありません。なぜなら、最終的に文字列が 1 となるような操作手順が存在しないからです。

  • 10000 : この文字列は美しくありません。なぜなら、最終的に文字列が 1 となるような操作手順が存在しないからです。

よって、美しい文字列を得る方法は 2 通りです。


入力例 2

?

出力例 2

1

この場合、1 が唯一の美しい文字列です。


入力例 3

?0101???10???00?1???????????????0????????????1????0

出力例 3

402589311

答えを 10^{9} + 7 で割った余りを出力することを忘れずに。

Score : 1600 points

Problem Statement

Taichi thinks a binary string X of odd length N is beautiful if it is possible to apply the following operation \frac{N-1}{2} times so that the only character of the resulting string is 1 :

  • Choose three consecutive bits of X and replace them by their median. For example, we can turn 00110 into 010 by applying the operation to the middle three bits.

Taichi has a string S consisting of characters 0, 1 and ?. Taichi wants to know the number of ways to replace the question marks with 1 or 0 so that the resulting string is beautiful, modulo 10^{9} + 7.

Constraints

  • 1 \leq |S| \leq 300000
  • |S| is odd.
  • All characters of S are either 0, 1 or ?.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of ways to replace the question marks so that the resulting string is beautiful, modulo 10^{9} + 7.


Sample Input 1

1??00

Sample Output 1

2

There are 4 ways to replace the question marks with 0 or 1 :

  • 11100 : This string is beautiful because we can first perform the operation on the last 3 bits to get 110 and then on the only 3 bits to get 1.

  • 11000 : This string is beautiful because we can first perform the operation on the last 3 bits to get 110 and then on the only 3 bits to get 1.

  • 10100 : This string is not beautiful because there is no sequence of operations such that the final string is 1.

  • 10000 : This string is not beautiful because there is no sequence of operations such that the final string is 1.

Thus, there are 2 ways to form a beautiful string.


Sample Input 2

?

Sample Output 2

1

In this case, 1 is the only beautiful string.


Sample Input 3

?0101???10???00?1???????????????0????????????1????0

Sample Output 3

402589311

Remember to output your answer modulo 10^{9} + 7.

F - Checkers

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 1600

問題文

X = 10^{100} とします。イナバは N 個の駒を数直線上に置いていて、i 個目の駒は座標 X^{i} にあります。

1 秒ごとに、イナバは 2 個の駒 AB を選び、AB に関して対称な点に動かし、その後 B を取り除きます(AB が同じ位置にあっても構わず、A が移動後に他の駒と同じ位置にあっても構いません)。

N - 1 秒後には、駒が 1 個だけ残ります。その駒の位置としてありうるものは何通りあるか、その数を 10^{9} + 7 で割った余りを求めてください。

制約

  • 1 \leq N \leq 50
  • N は整数である。

入力

入力は標準入力から以下の形式で与えられる。

N

出力

最後に残る駒の位置としてありうるものの数を 10^{9} + 7 で割った余りを出力せよ。


入力例 1

3

出力例 1

12

駒が 3 個あり、それぞれ座標 10^{100}, 10^{200}, 10^{300} に置かれています。これらをそれぞれ ABC と呼びます。

考えられる駒の動かし方(12 通り)のうち 2 つを示します。

  • 最初の 1 秒で AB を飛び越えさせ、次の 1 秒で AC を飛び越えさせる。A の最終的な位置は 2 \times 10^{300} - 2 \times 10^{200} + 10^{100} となる。

  • 最初の 1 秒で CA を飛び越えさせ、次の 1 秒で BC を飛び越えさせる。B の最終的な位置は -2 \times 10^{300} - 10^{200} + 4 \times 10^{100} となる。

駒の動かし方は合計で 3 \times 2 \times 2 = 12 通りあり、そのすべてで最後の駒は異なる位置に残ります。


入力例 2

4

出力例 2

84

入力例 3

22

出力例 3

487772376

答えを 10^{9} + 7 で割った余りを出力することを忘れずに。

Score : 1600 points

Problem Statement

Let X = 10^{100}. Inaba has N checker pieces on the number line, where the i-th checker piece is at coordinate X^{i} for all 1 \leq i \leq N.

Every second, Inaba chooses two checker pieces, A and B, and move A to the symmetric point of its current position with respect to B. After that, B is removed. (It is possible that A and B occupy the same position, and it is also possible for A to occupy the same position as another checker piece after the move).

After N - 1 seconds, only one checker piece will remain. Find the number of distinct possible positions of that checker piece, modulo 10^{9} + 7.

Constraints

  • 1 \leq N \leq 50
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of distinct possible positions of the final checker piece, modulo 10^{9} + 7.


Sample Input 1

3

Sample Output 1

12

There are 3 checker pieces, positioned at 10^{100}, 10^{200}, 10^{300} respectively. Call them A, B, C respectively.

Here are two (of the 12) possible sequence of moves :

  • Let A jump over B in the first second, and let A jump over C in the second second. The final position of A is 2 \times 10^{300} - 2 \times 10^{200} + 10^{100}.

  • Let C jump over A in the first second, and let B jump over C in the second second. The final position of B is -2 \times 10^{300} - 10^{200} + 4 \times 10^{100}.

There are a total of 3 \times 2 \times 2 = 12 possible sequence of moves, and the final piece are in different positions in all of them.


Sample Input 2

4

Sample Output 2

84

Sample Input 3

22

Sample Output 3

487772376

Remember to output your answer modulo 10^{9} + 7.