A - atcoder < S

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

英小文字からなる文字列 S が与えられます. すぬけくんは,S隣り合う 2 文字をスワップするという操作を行うことができます. 例えば,S=agc なら,1 回の操作で,Sgac (ag をスワップ) もしくは acg (gc をスワップ) に変換できます.

すぬけくんはこの操作を 0 回以上繰り返し, 辞書順で atcoder <S となるようにしたいです.

辞書順で x< y の定義

文字列 x,y が辞書順で x< y であるとは,以下のうちいずれかの条件を満たすことを意味します.

  • ある整数 i (1 \leq i \leq \mathrm{min}(|x|,|y|)) が存在して,x,y は先頭の i-1 文字が一致しており,かつ, xi 文字目は yi 文字目よりアルファベット順で真に小さい.
  • |x|< |y| であり,y の先頭の |x| 文字は x と等しい.

目標が達成可能かどうか判定し,可能な場合は必要な操作回数の最小値を求めてください.

1 つの入力ファイルにつき,T 個のテストケースを解いてください.

制約

  • 1 \leq T \leq 100
  • 1 \leq |S| \leq 1000
  • S は英小文字からなる文字列.

入力

入力は以下の形式で標準入力から与えられる. 入力の 1 行目は以下のとおりである.

T

そして,T 個のテストケースが続く. これらはそれぞれ以下の形式で与えられる.

S

出力

各テストケースについて,目標が達成不可能な場合は -1,可能な場合は必要な操作回数の最小値を出力せよ. 各テストケースごとに改行せよ.


入力例 1

3
atcodeer
codeforces
aaa

出力例 1

1
0
-1
  • 1 番目のテストケース: 例えば,末尾の 2 文字をスワップすることで,S=atcodere > atcoder となります.
  • 2 番目のテストケース: 操作を行うまでもなく,S=codeforces > atcoder です.
  • 3 番目のテストケース: どのように操作を行っても S> atcoder にはなりません.

Score : 300 points

Problem Statement

Given is a string S consisting of lowercase English letters. Snuke can do the operation of swapping two adjacent characters in S. For example, if S=agc, one operation can change it to gac (by swapping a and g) or acg (by swapping g and c).

Snuke wants to do this operation zero or more times so that atcoder <S holds lexicographically.

The definition of the lexicographic relation x< y

For strings x and y, it is said that x< y holds lexicographically if and only if one of the following conditions is satisfied:

  • There exists an integer i (1 \leq i \leq \mathrm{min}(|x|,|y|)) such that the first i-1 characters of x and those of y are equal and the i-th character of x is strictly smaller than that of y in alphabetical order.
  • |x|< |y| holds, and the first |x| characters of y are equal to x.

Determine whether the objective is achievable. If it is achievable, find the minimum number of operations needed.

Solve T test cases in an input file.

Constraints

  • 1 \leq T \leq 100
  • 1 \leq |S| \leq 1000
  • S is a string consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format. The first line of input is as follows:

T

Then, T test cases follow, each of which is in the following format:

S

Output

For each test case, print -1 if the objective is unachievable, and print the minimum number of operations needed if it is achievable. Use one line for each case.


Sample Input 1

3
atcodeer
codeforces
aaa

Sample Output 1

1
0
-1
  • The first test case: for example, swapping the last two characters makes S=atcodere > atcoder hold.
  • The second test case: before doing any operation, we already have S=codeforces > atcoder.
  • The third test case: no sequence of operations makes S> atcoder hold.
B - Bracket Score

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 700

問題文

この問題では,(,),[,] からなる文字列を考えます.

文字列 x は,以下のいずれかの条件を満たす時,良い括弧列と呼ばれます.

  • x は空文字列である.
  • ある良い括弧列 s が存在し,(,s,) をこの順に連結すると x が得られる.
  • ある良い括弧列 s が存在し,[,s,] をこの順に連結すると x が得られる.
  • ある空でない良い括弧列 s および t が存在し,s,t をこの順に連結すると x が得られる.

例えば,[], ([()]), ()[()] などは良い括弧列ですが,()), ([)] などは良い括弧列ではありません.

偶数 N と,長さ N の整数列 A および B が与えられます. ここで,長さ N の良い括弧列 s=s_1s_2\cdots s_N に対して,s のスコアを次のように定めます.

  • s のスコアは,各文字のスコアの合計である.
  • i 文字目 (1 \leq i \leq N) のスコアは,s_i( または ) ならば A_i であり,s_i[ または ] ならば B_i である.

長さ N の良い括弧列のスコアとしてあり得る最大の値を求めてください.

制約

  • 2 \leq N \leq 10^5
  • N は偶数
  • 1 \leq A_i \leq 10^9
  • 1 \leq B_i \leq 10^9
  • 入力される数はすべて整数.

入力

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

N
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

出力

答えを出力せよ.


入力例 1

4
4 2 3 1
2 3 2 4

出力例 1

12

s=()[] とするとスコアが A_1+A_2+B_3+B_4=12 になり,これが最大です.


入力例 2

10
866111664 844917655 383133839 353498483 472381277 550309930 378371075 304570952 955719384 705445072
178537096 218662351 231371336 865935868 579910117 62731178 681212831 16537461 267238505 318106937

出力例 2

6629738472

Score : 700 points

Problem Statement

In this problem, we consider strings consisting of (, ), [, and ].

A string x is said to be a good parentheses sequence if and only if one of the following conditions is satisfied:

  • x is an empty sequence.
  • There is a good parentheses sequence s such that concatenating (, s, and ) in this order results in x.
  • There is a good parentheses sequence s such that concatenating [, s, and ] in this order results in x.
  • There are non-empty good parentheses sequences s and t such that concatenating s and t in this order results in x.

For example, [], ([()]), and ()[()] are good parentheses sequences, but neither ()) nor ([)] is a good parentheses sequence.

Given are an even number N and integer sequences A and B of length N each. Here, we define a score for a good parentheses sequence of length N, s=s_1s_2\cdots s_N, as follows:

  • The score for s is the sum of the scores of its characters.
  • The score for the i-th character (1 \leq i \leq N) is A_i if s_i is ( or ), and B_i if s_i is [ or ].

Find the maximum possible score for a good parentheses sequence of length N.

Constraints

  • 2 \leq N \leq 10^5
  • N is an even number.
  • 1 \leq A_i \leq 10^9
  • 1 \leq B_i \leq 10^9
  • All numbers in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

Output

Print the answer.


Sample Input 1

4
4 2 3 1
2 3 2 4

Sample Output 1

12

For s=()[], the score is A_1+A_2+B_3+B_4=12, which is the maximum possible value.


Sample Input 2

10
866111664 844917655 383133839 353498483 472381277 550309930 378371075 304570952 955719384 705445072
178537096 218662351 231371336 865935868 579910117 62731178 681212831 16537461 267238505 318106937

Sample Output 2

6629738472
C - Penguin Skating

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 700

問題文

L 個のマスが横一列に並んでいます. マスは左から順に 1,2,\ldots,L と番号が振られています.

N 匹のペンギンがマス目の上にいます. ペンギンは左から順に 1,2,\ldots,N と番号が振られています. 最初,ペンギン i はマス A_i の上にいます. ここで,1 \leq A_1 < A_2 < \ldots < A_N \leq L です.

あなたは,次の操作を好きな回数行うことができます.

  • ペンギンを 1 匹選び,左または右へ向かって滑らせる. ペンギンは,目の前に空マスがある限り滑り続ける. 別のペンギンのいるマスの直前のマスに到達する,もしくは目の前にマスが存在しなくなったら,ペンギンは停止する.

例えば,N=3,L=10 で,ペンギンのいるマスが (2,3,7) であるとします. このとき,ペンギン 2 を右に滑らせると,ペンギン 2 はマス 6 まで移動します. また,ペンギン 3 を右に滑らせると,ペンギン 3 はマス 10 まで移動します.

あなたの目標は,すべての i について,ペンギン i がマス B_i の上にいるようにすることです. ここで,1 \leq B_1 < B_2 < \ldots < B_N \leq L です. 目標が達成可能か判定し,可能ならば必要な操作回数の最小値を求めてください.

制約

  • 1 \leq N \leq 10^5
  • N \leq L \leq 10^9
  • 1 \leq A_1 < A_2 < \ldots < A_N \leq L
  • 1 \leq B_1 < B_2 < \ldots < B_N \leq L
  • 入力される数はすべて整数.

入力

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

N L
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

出力

目標が達成不可能な場合は -1 を,可能な場合は必要な操作回数の最小値を出力せよ.


入力例 1

4 11
3 4 6 10
1 5 6 11

出力例 1

3

次のように操作すればよいです.

  • ペンギン 1 を左に滑らせる.ペンギンの位置は,(1,4,6,10) になる.
  • ペンギン 2 を右に滑らせる.ペンギンの位置は,(1,5,6,10) になる.
  • ペンギン 4 を右に滑らせる.ペンギンの位置は,(1,5,6,11) になる.

入力例 2

1 3
1
2

出力例 2

-1

入力例 3

10 1000000000
65110170 68805223 123016442 275946481 661490312 760727752 764540566 929355340 930658577 947099792
1 2 123016442 661490311 929355337 930658574 999999997 999999998 999999999 1000000000

出力例 3

13

Score : 700 points

Problem Statement

There are L squares lining up horizontally in a row, numbered 1, 2, \ldots, L from left to right.

On those squares are N penguins, numbered 1, 2, \ldots, N from left to right. Initially, Penguin i is on Square A_i. Here, 1 \leq A_1 < A_2 < \ldots < A_N \leq L holds.

You can do the following operations any number of times:

  • Choose one penguin and slide it to the left or the right. The penguin will keep sliding as long as there is an empty square ahead. It will stop when it reaches a square just before a square occupied by another penguin, or there is no square ahead.

For example, assume that N=3, L=10, and the penguins are on the squares (2,3,7). Here, if we slide Penguin 2 to the right, it will move to Square 6; if we slide Penguin 3 to the right, it will move to Square 10.

Your objective is to put Penguin i on Square B_i for every i. Here, 1 \leq B_1 < B_2 < \ldots < B_N \leq L holds. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations needed.

Constraints

  • 1 \leq N \leq 10^5
  • N \leq L \leq 10^9
  • 1 \leq A_1 < A_2 < \ldots < A_N \leq L
  • 1 \leq B_1 < B_2 < \ldots < B_N \leq L
  • All numbers in input are integers.

Input

Input is given from Standard Input in the following format:

N L
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

Output

If the objective is unachievable, print -1; if it is achievable, print the minimum number of operations needed.


Sample Input 1

4 11
3 4 6 10
1 5 6 11

Sample Output 1

3

The following sequence of operations achieves the objective:

  • Slide Penguin 1 to the left. The penguins are now on the squares (1,4,6,10).
  • Slide Penguin 2 to the right. The penguins are now on the squares (1,5,6,10).
  • Slide Penguin 4 to the right. The penguins are now on the squares (1,5,6,11).

Sample Input 2

1 3
1
2

Sample Output 2

-1

Sample Input 3

10 1000000000
65110170 68805223 123016442 275946481 661490312 760727752 764540566 929355340 930658577 947099792
1 2 123016442 661490311 929355337 930658574 999999997 999999998 999999999 1000000000

Sample Output 3

13
D - Pocky Game

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 900

問題文

N 個の山が横一列に並んでいます. 左から i 番目の山には A_i 個の石があります.

FirstLeft くんと SecondRight くんがゲームをします. FirstLeft くんから始めて,二人は交互に手番をプレイします. それぞれの手番では,以下の操作を行います.

  • FirstLeft くんの手番: FirstLeft くんは,石が 1 個以上ある山の中で最もにある山から,1 個以上の石を取り除く.
  • SecondRight くんの手番: SecondRight くんは,石が 1 個以上ある山の中で最もにある山から,1 個以上の石を取り除く.

自分の手番で操作できなくなったプレイヤーの負けです. 二人が最適に行動する時,どちらが勝利するか判定してください.

1 つの入力ファイルにつき,T 個のテストケースを解いてください.

制約

  • 1 \leq T \leq 100
  • 1 \leq N \leq 100
  • 1 \leq A_i \leq 10^9

入力

入力は以下の形式で標準入力から与えられる. 入力の 1 行目は以下のとおりである.

T

そして,T 個のテストケースが続く. これらはそれぞれ以下の形式で与えられる.

N
A_1 A_2 \cdots A_N

出力

各テストケースについて,FirstLeft くんが勝つ場合は First,SecondRight くんが勝つ場合は Second と出力せよ. 各テストケースごとに改行せよ.


入力例 1

3
1
10
2
3 2
3
2 1 2

出力例 1

First
First
Second

例えば,3 個目のゲームにおいて,次のようなシナリオが考えられます.

  • FirstLeft くんが一番左の山から石を 2 個とる.山にある石の個数は (0,1,2) になる.
  • SecondRight くんが一番右の山から石を 1 個とる.山にある石の個数は (0,1,1) になる.
  • FirstLeft くんが真ん中の山から石を 1 個とる.山にある石の個数は (0,0,1) になる.
  • SecondRight くんが一番右の山から石を 1 個とる.山にある石の個数は (0,0,0) になる.
  • FirstLeft くんは操作を行うことができず,敗北する.

Score : 900 points

Problem Statement

There are N piles of stones lying in a row. The i-th pile from the left contains A_i stones.

Two players, FirstLeft and SecondRight, play a game. They alternately play a turn, with FirstLeft going first. In each turn, the player does the following operation:

  • In FirstLeft's turn: he removes one or more stones from the leftmost pile with one or more stones.
  • In SecondRight's turn: he removes one or more stones from the rightmost pile with one or more stones.

The player who becomes unable to play his turn loses. Determine the winner of the game when the players act optimally.

Solve T test cases in an input file.

Constraints

  • 1 \leq T \leq 100
  • 1 \leq N \leq 100
  • 1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format. The first line of input is as follows:

T

Then, T test cases follow, each of which is in the following format:

N
A_1 A_2 \cdots A_N

Output

For each test case, print First if FirstLeft wins, and print Second if SecondRight wins. Use one line for each case.


Sample Input 1

3
1
10
2
3 2
3
2 1 2

Sample Output 1

First
First
Second

For example, in the third game, one possible scenario is as follows:

  • FirstLeft takes 2 stones from the leftmost pile. The piles now contain 0,1,2 stone(s).
  • SecondRight takes 1 stone from the rightmost pile. The piles now contain 0,1,1 stone(s).
  • FirstLeft takes 1 stone from the middle pile. The piles now contain 0,0,1 stone(s).
  • SecondRight takes 1 stone from the rightmost pile. The piles now contain 0,0,0 stones.
  • FirstLeft is unable to do his operation and loses.
E - Strange Relation

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 1500

問題文

長さ N の整数列 A=(A_1,A_2,\cdots,A_N), および整数 T に対して,f(A,T) を,つぎのように定義します.

  • f(A,T) は,以下の条件をすべて満たす整数列 x の中で,辞書順最大のものである. なおこの問題の制約下では,条件を満たす数列は必ず存在し,またその個数は有限であることが証明できる.よって,f(A,T) は必ず定義できる.

    • x は長さ N の非負整数列である.
    • i (1 \leq i \leq N) について,y_i を,j<i かつ A_j+T \times x_j < A_i+T \times x_i を満たす j の個数,と定義する.このとき,y_i=x_i である.

例えば,A=(6,5,1),T=3 であるとします. この時,条件を満たす数列 x として,(0,0,0),(0,0,2),(0,1,0) が考えられます. よって,f(A,T) の値は,この中で辞書順最大の (0,1,0) です.

すぬけくんは今,N 個の整数列 B_1,B_2,\cdots,B_N と,整数 T を持っています. B_i (1 \leq i \leq N) はすべて長さ K の整数列です.

これからすぬけくんは,長さ N の整数列 A を作り,f(A,T) を求めようとしています. A_i の値は,B_{i,1},B_{i,2},\cdots,B_{i,K} から選ぶことにします. ここで,B_i の値に重複があっても,それらの値を区別することにします. つまり,A の作り方は K^N 通り存在します.

すべての i (1 \leq i \leq N) について,次の問題を解いてください.

  • K^N 通りすべての A について f(A,T) を求め,その i 項目の値を記録する. これらの値の総和を \bmod (10^9+7) で求めよ.

制約

  • 1 \leq N \leq 50
  • 1 \leq K \leq 50
  • 1 \leq T \leq 10^7
  • 1 \leq B_{i,j} \leq 10^9

入力

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

N K T
B_{1,1} B_{1,2} \cdots B_{1,K}
B_{2,1} B_{2,2} \cdots B_{2,K}
\vdots
B_{N,1} B_{N,2} \cdots B_{N,K}

出力

すべての i について,答えを一行ごとに出力せよ.


入力例 1

2 2 1
1 2
1 2

出力例 1

0
3
  • A=(1,1) の場合: f(A,T)=(0,1)
  • A=(1,2) の場合: f(A,T)=(0,1)
  • A=(2,1) の場合: f(A,T)=(0,0)
  • A=(2,2) の場合: f(A,T)=(0,1)

よって,i=1 のときの答えは 0+0+0+0=0 であり, i=2 のときの答えは 1+1+0+1=3 です.


入力例 2

3 2 3
6 2
5 3
1 4

出力例 2

0
6
13

入力例 3

10 15 45
129 82 26 185 217 258 22 192 24 117 167 255 91 180 203
171 73 168 26 208 169 115 164 121 214 154 196 172 66 230
185 178 241 220 243 143 111 124 10 62 56 117 254 43 81
201 74 213 163 204 35 44 203 207 73 218 60 243 51 250
229 117 212 245 112 152 206 96 266 165 105 94 231 41 27
261 201 258 111 100 72 239 31 199 203 226 151 72 268 44
94 19 47 243 133 174 141 82 190 62 175 256 126 123 210
186 64 73 82 68 183 261 120 265 212 18 24 36 152 92
205 101 186 91 172 153 91 242 141 97 247 193 45 245 66
225 97 162 213 61 219 184 195 80 203 79 72 269 258 199

出力例 3

0
248044096
333666695
536381826
8787512
11659012
661959013
166067001
529828166
526544756

Score : 1500 points

Problem Statement

For an integer sequence of length N, A=(A_1,A_2,\cdots,A_N), and an integer T, let f(A,T) defined as follows:

  • f(A, T) is the lexicographically greatest integer sequence x that satisfies all of the conditions below. Here, under the constraints in this problem, it can be proved that there always are sequences that satisfy the conditions and that the number of those sequences is finite. Thus, f(A, T) can always be defined.

    • x is a sequence of length N consisting of non-negative integers.
    • For each i (1 \leq i \leq N), let y_i be the number of indices j such that j<i and A_j+T \times x_j < A_i+T \times x_i. Then, y_i=x_i holds.

For example, assume that A=(6,5,1) and T=3. Then, the sequences x that satisfy the conditions are: (0,0,0), (0,0,2), and (0,1,0). Thus, the value of f(A, T) is the lexicographically maximum among them: (0,1,0).

Now, Snuke has N integer sequences B_1,B_2,\cdots,B_N and an integer T. Each of the sequences B_i (1 \leq i \leq N) is an integer sequence of length K.

He will create an integer sequence A of length N and compute f(A, T). The value of A_i will be chosen from B_{i,1},B_{i,2},\cdots,B_{i,K}. Here, if B_i contains the same value multiple times, we will distinguish those occurrences; that is, there are K^N ways to create A.

For every i (1 \leq i \leq N), solve the following problem:

  • For all K^N choices of A, we will compute f(A,T) and record the value of its i-th element. Find the sum of these values, modulo (10^9+7).

Constraints

  • 1 \leq N \leq 50
  • 1 \leq K \leq 50
  • 1 \leq T \leq 10^7
  • 1 \leq B_{i,j} \leq 10^9

Input

Input is given from Standard Input in the following format:

N K T
B_{1,1} B_{1,2} \cdots B_{1,K}
B_{2,1} B_{2,2} \cdots B_{2,K}
\vdots
B_{N,1} B_{N,2} \cdots B_{N,K}

Output

For every i, print the answer in its own line.


Sample Input 1

2 2 1
1 2
1 2

Sample Output 1

0
3
  • For A=(1,1): f(A,T)=(0,1)
  • For A=(1,2): f(A,T)=(0,1)
  • For A=(2,1): f(A,T)=(0,0)
  • For A=(2,2): f(A,T)=(0,1)

Thus, the answer is 0+0+0+0=0 for i=1 and 1+1+0+1=3 for i=2.


Sample Input 2

3 2 3
6 2
5 3
1 4

Sample Output 2

0
6
13

Sample Input 3

10 15 45
129 82 26 185 217 258 22 192 24 117 167 255 91 180 203
171 73 168 26 208 169 115 164 121 214 154 196 172 66 230
185 178 241 220 243 143 111 124 10 62 56 117 254 43 81
201 74 213 163 204 35 44 203 207 73 218 60 243 51 250
229 117 212 245 112 152 206 96 266 165 105 94 231 41 27
261 201 258 111 100 72 239 31 199 203 226 151 72 268 44
94 19 47 243 133 174 141 82 190 62 175 256 126 123 210
186 64 73 82 68 183 261 120 265 212 18 24 36 152 92
205 101 186 91 172 153 91 242 141 97 247 193 45 245 66
225 97 162 213 61 219 184 195 80 203 79 72 269 258 199

Sample Output 3

0
248044096
333666695
536381826
8787512
11659012
661959013
166067001
529828166
526544756
F - 01 Record

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 2200

問題文

すぬけくんは大きな黒板をもらいました. これに喜んだすぬけくんは,まず,黒板にいくつかの正整数を書きました. 次にすぬけくんは,黒板に書かれている整数がなくなるまで,以下の操作を繰り返し行いました.

  • 黒板に書かれている整数を 1 つ選び,消す. 消した整数を x とする. 次に,x2 で割ったあまりをノートに記録する. 最後に,x \geq 2 である場合は,新たに x-1 を黒板に書き加える.

すぬけくんの記録は,01 からなる文字列 S によって表されます. これは,すぬけくんが i 回目の操作で選んだ整数を 2 で割ったあまりが S_i であることを表します.

すぬけくんは,最初に黒板に書いた正整数の組み合わせを忘れてしまいました. 文字列 S の情報から,最初に黒板に書いた正整数の組み合わせとしてありうるものが何通りあるか求めてください. ここで,正整数の組み合わせ ab が異なるとは,ある整数 v が存在して,a に含まれる v の個数と b に含まれる v の個数が異なることを意味します. なお,答えは非常に大きくなることがあるので,10^9+7 で割ったあまりを求めてください. また,すぬけくんの記録が間違っており,条件を満たす正整数の組み合わせが存在しないこともありますが,その場合は単に 0 と答えてください.

制約

  • 1 \leq |S| \leq 300
  • S01 からなる文字列.

入力

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

S

出力

最初に黒板に書いた正整数の組み合わせとしてありうるものの数を 10^9+7 で割ったあまりを出力せよ.


入力例 1

101

出力例 1

2

最初に黒板に書いた整数の組み合わせとしてあり得るのは,\{1,2\},\ \{3\}2 つです.


入力例 2

100

出力例 2

0

最初に黒板に書いた整数の組み合わせとしてあり得るものはありません.


入力例 3

010101

出力例 3

3

最初に黒板に書いた整数の組み合わせとしてあり得るのは,\{2,2,2\},\ \{2,4\},\ \{6\}3 つです.


入力例 4

11101000111110111101001011110010111110101111110111

出力例 4

3904

Score : 2200 points

Problem Statement

Snuke received a big blackboard. Being pleased with this present, he first wrote some positive integers. Then, he repeated the following operation until there was no integer written on the blackboard:

  • Choose one integer written on the blackboard and erase it. Let x be the erased integer. Then, record the remainder of x divided by 2 on his notebook. Finally, if x \geq 2, write a new integer x-1 on the blackboard.

Snuke's record is represented by a string S consisting of 0 and 1, where S_i is the remainder of the chosen integer divided by 2 in the i-th operation.

Snuke forgot the combination of positive integers he first wrote on the blackboard. From the information given as the string S, find the number of possible combinations of positive integers he first wrote on the blackboard. Here, we consider combinations a and b of positive integers different when there is an integer v such that the numbers of times v occurs in a and v occurs in b differ. Since the count can be enormous, compute it modulo (10^9+7). Also, it is possible that Snuke's record is incorrect and that no combination of positive integers satisfies the condition. In such a case, just answer 0.

Constraints

  • 1 \leq |S| \leq 300
  • S is a string consisting of 0 and 1.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of possible combinations of positive integers written on the blackboard, modulo (10^9+7).


Sample Input 1

101

Sample Output 1

2

There are two possible combinations of integers written on the blackboard: \{1,2\} and \{3\}.


Sample Input 2

100

Sample Output 2

0

There is no possible combination of integers written on the blackboard.


Sample Input 3

010101

Sample Output 3

3

There are three possible combinations of integers written on the blackboard: \{2,2,2\}, \{2,4\}, and \{6\}.


Sample Input 4

11101000111110111101001011110010111110101111110111

Sample Output 4

3904