A - chukodai

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

英小文字からなる文字列 S が与えられます。

S の先頭から a 文字目と b 文字目を入れ替えて得られる文字列を出力してください。

制約

  • S は英小文字からなる文字列
  • S の長さ |S| は、 2 \leq |S| \leq 10 を満たす
  • 1 \leq a < b \leq |S|
  • a, b は整数

入力

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

S
a b

出力

答えを出力せよ。


入力例 1

chokudai
3 5

出力例 1

chukodai

chokudai3 文字目 o5 文字目 u を入れ替えると chukodai となります。


入力例 2

aa
1 2

出力例 2

aa

この入力例では、S1 文字目と 2 文字目を入れ替えて得られる文字列は、元の S と同じになります。


入力例 3

aaaabbbb
1 8

出力例 3

baaabbba

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English letters.

Swap the a-th and b-th characters from the beginning of S and print the resulting string.

Constraints

  • S is a string consisting of lowercase English letters.
  • The length of S, |S|, satisfies 2 \leq |S| \leq 10.
  • 1 \leq a < b \leq |S|
  • a and b are integers.

Input

Input is given from Standard Input in the following format:

S
a b

Output

Print the answer.


Sample Input 1

chokudai
3 5

Sample Output 1

chukodai

After swapping the 3-rd character o and 5-th character u of chokudai, we have chukodai.


Sample Input 2

aa
1 2

Sample Output 2

aa

In this sample, after swapping the 1-st and 2-nd characters of S, we have the same string as S.


Sample Input 3

aaaabbbb
1 8

Sample Output 3

baaabbba
B - On and Off

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

高橋君は、毎日 S0 分に部屋の電気をつけ、毎日 T0 分に消します。
電気をつけている間に日付が変わることもあります。

X30 分に部屋の電気がついているかどうか判定してください。

制約

  • 0 \leq S, T, X \leq 23
  • S \neq T
  • 入力は全て整数である。

入力

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

S T X

出力

X30 分に部屋の電気がついているならば Yes と、そうでなければ No と出力せよ。


入力例 1

7 20 12

出力例 1

Yes

部屋の電気がついているのは 70 分から 200 分までの間です。1230 分には電気がついているので、Yes と出力します。


入力例 2

20 7 12

出力例 2

No

部屋の電気がついているのは 00 分から 70 分までの間と、200 分から(次の日の)00 分までの間です。 1230 分には電気がついていないので、No と出力します。


入力例 3

23 0 23

出力例 3

Yes

Score : 100 points

Problem Statement

Takahashi turns on the light of his room at S o'clock (on the 24-hour clock) every day and turns it off at T o'clock every day.
The date may change while the light is on.

Determine whether the light is on at 30 minutes past X o'clock.

Constraints

  • 0 \leq S, T, X \leq 23
  • S \neq T
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

S T X

Output

If the light is on at 30 minutes past X o'clock, print Yes; otherwise, print No.


Sample Input 1

7 20 12

Sample Output 1

Yes

The light is on between 7 o'clock and 20 o'clock. At 30 minutes past 12 o'clock, it is on, so we print Yes.


Sample Input 2

20 7 12

Sample Output 2

No

The light is on between 0 o'clock and 7 o'clock, and between 20 o'clock and 0 o'clock (on the next day). At 30 minutes past 12 o'clock, it is off, so we print No.


Sample Input 3

23 0 23

Sample Output 3

Yes
C - Which is ahead?

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

N 人が 1 列に並んでおり、前から i 番目に並んでいる人は人 P_i です。

Q 個のクエリを処理して下さい。i 番目のクエリは以下のものです。

  • 整数 A_i,B_i が与えられる。人 A_i と人 B_i のうち、より前に並んでいる人の番号を出力せよ。

制約

  • 入力は全て整数
  • 1\leq N\leq 100
  • 1\leq P_i\leq N
  • P_i \neq P_j\ (i\neq j)
  • 1\leq Q \leq 100
  • 1\leq A_i<B_i\leq N

入力

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

N
P_1 \ldots P_N
Q
A_1 B_1
\vdots
A_Q B_Q

出力

Q 行出力せよ。i 行目には、i 番目のクエリの答えを出力せよ。


入力例 1

3
2 1 3
3
2 3
1 2
1 3

出力例 1

2
2
1

1 番目のクエリでは、人 2 は前から 1 番目、人 3 は前から 3 番目なので、人 2 がより前にいます。

2 番目のクエリでは、人 1 は前から 2 番目、人 2 は前から 1 番目なので、人 2 がより前にいます。

3 番目のクエリでは、人 1 は前から 2 番目、人 3 は前から 3 番目なので、人 1 がより前にいます。


入力例 2

7
3 7 2 1 6 5 4
13
2 3
1 2
1 3
3 6
3 7
2 4
3 7
1 3
4 7
1 6
2 4
1 3
1 3

出力例 2

3
2
3
3
3
2
3
3
7
1
2
3
3

Score: 200 points

Problem Statement

There are N people standing in a line. The person standing at the i-th position from the front is person P_i.

Process Q queries. The i-th query is as follows:

  • You are given integers A_i and B_i. Between person A_i and person B_i, print the person number of the person standing further to the front.

Constraints

  • All inputs are integers.
  • 1 \leq N \leq 100
  • 1 \leq P_i \leq N
  • P_i \neq P_j\ (i \neq j)
  • 1 \leq Q \leq 100
  • 1 \leq A_i < B_i \leq N

Input

The input is given from Standard Input in the following format:

N
P_1 \ldots P_N
Q
A_1 B_1
\vdots
A_Q B_Q

Output

Print Q lines. The i-th line should contain the response for the i-th query.


Sample Input 1

3
2 1 3
3
2 3
1 2
1 3

Sample Output 1

2
2
1

In the first query, person 2 is at the first position from the front, and person 3 is at the third position, so person 2 is further to the front.

In the second query, person 1 is at the second position from the front, and person 2 is at the first position, so person 2 is further to the front.

In the third query, person 1 is at the second position from the front, and person 3 is at the third position, so person 1 is further to the front.


Sample Input 2

7
3 7 2 1 6 5 4
13
2 3
1 2
1 3
3 6
3 7
2 4
3 7
1 3
4 7
1 6
2 4
1 3
1 3

Sample Output 2

3
2
3
3
3
2
3
3
7
1
2
3
3
D - Uppercase and Lowercase

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

英小文字と英大文字からなる文字列 S が与えられます。S の長さは奇数です。
S に含まれる大文字の個数が小文字の個数よりも多ければ、S に含まれる全ての小文字を大文字に変換してください。
そうでない場合は、S に含まれる全ての大文字を小文字に変換してください。

制約

  • S は英小文字および英大文字からなる文字列
  • S の長さは 1 以上 99 以下の奇数

入力

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

S

出力

問題文の指示に従って文字を変換した後の S を出力せよ。


入力例 1

AtCoder

出力例 1

atcoder

AtCoder に含まれる小文字の個数は 5 個、大文字の個数は 2 個です。よって AtCoder に含まれる全ての大文字を小文字に変換した atcoder が答えとなります。


入力例 2

SunTORY

出力例 2

SUNTORY

SunTORY に含まれる小文字の個数は 2 個、大文字の個数は 5 個です。よって SunTORY に含まれる全ての小文字を大文字に変換した SUNTORY が答えとなります。


入力例 3

a

出力例 3

a

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase and uppercase English letters. The length of S is odd.
If the number of uppercase letters in S is greater than the number of lowercase letters, convert all lowercase letters in S to uppercase.
Otherwise, convert all uppercase letters in S to lowercase.

Constraints

  • S is a string consisting of lowercase and uppercase English letters.
  • The length of S is an odd number between 1 and 99, inclusive.

Input

The input is given from Standard Input in the following format:

S

Output

Print the string S after converting the letters according to the problem statement.


Sample Input 1

AtCoder

Sample Output 1

atcoder

The string AtCoder contains five lowercase letters and two uppercase letters. Thus, convert all uppercase letters in AtCoder to lowercase, which results in atcoder.


Sample Input 2

SunTORY

Sample Output 2

SUNTORY

The string SunTORY contains two lowercase letters and five uppercase letters. Thus, convert all lowercase letters in SunTORY to uppercase, which results in SUNTORY.


Sample Input 3

a

Sample Output 3

a
E - Rotate Colored Subsequence

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

英小文字からなる長さ N の文字列 S が与えられます。 S の各文字は色 1 、色 2\ldots 、色 MM 色のうちのいずれかで塗られており、 i = 1, 2, \ldots, N について、Si 文字目は色 C_i で塗られています。

i = 1, 2, \ldots, M について、この順番に下記の操作を行います。

  • S の色 i で塗られた文字からなる部分を、右に 1 つ巡回シフトする。 すなわち、S の 色 i で塗られた文字の位置が先頭のものから順に p_1, p_2, p_3, \ldots, p_k 文字目であるとき、 Sp_1, p_2, p_3, \ldots, p_k 文字目を、それぞれ、Sp_k, p_1,p_2, \ldots, p_{k-1} 文字目で同時に置き換える。

上記の操作をすべて行った後の、最終的な S を出力してください。

なお、M 色あるどの色についても、その色で塗られた S の文字が必ず 1 つ以上存在することが、制約として保証されます。

制約

  • 1 \leq M \leq N \leq 2 \times 10^5
  • 1 \leq C_i \leq M
  • N, M, C_i はすべて整数
  • S は英小文字からなる長さ N の文字列
  • 任意の整数 1 \leq i \leq M に対して、ある整数 1 \leq j \leq N が存在して C_j = i が成り立つ

入力

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

N M
S
C_1 C_2 \ldots C_N

出力

答えを出力せよ。


入力例 1

8 3
apzbqrcs
1 2 3 1 2 2 1 2

出力例 1

cszapqbr

はじめ、S = apzbqrcs です。

  • i = 1 に対する操作では、S1, 4, 7 文字目からなる部分を右に 1 つ巡回シフトします。その結果、S = cpzaqrbs となります。
  • i = 2 に対する操作では、S2, 5, 6, 8 文字目からなる部分を右に 1 つ巡回シフトします。その結果、S = cszapqbr となります。
  • i = 3 に対する操作では、S3 文字目からなる部分を右に 1 つ巡回シフトします。その結果、S = cszapqbr となります(操作の前後で S は変わりません)。

よって、最終的な S である cszapqbr を出力します。


入力例 2

2 1
aa
1 1

出力例 2

aa

Score : 300 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters. Each character of S is painted in one of the M colors: color 1, color 2, ..., color M; for each i = 1, 2, \ldots, N, the i-th character of S is painted in color C_i.

For each i = 1, 2, \ldots, M in this order, let us perform the following operation.

  • Perform a right circular shift by 1 on the part of S painted in color i. That is, if the p_1-th, p_2-th, p_3-th, \ldots, p_k-th characters are painted in color i from left to right, then simultaneously replace the p_1-th, p_2-th, p_3-th, \ldots, p_k-th characters of S with the p_k-th, p_1-th, p_2-th, \ldots, p_{k-1}-th characters of S, respectively.

Print the final S after the above operations.

The constraints guarantee that at least one character of S is painted in each of the M colors.

Constraints

  • 1 \leq M \leq N \leq 2 \times 10^5
  • 1 \leq C_i \leq M
  • N, M, and C_i are all integers.
  • S is a string of length N consisting of lowercase English letters.
  • For each integer 1 \leq i \leq M, there is an integer 1 \leq j \leq N such that C_j = i.

Input

The input is given from Standard Input in the following format:

N M
S
C_1 C_2 \ldots C_N

Output

Print the answer.


Sample Input 1

8 3
apzbqrcs
1 2 3 1 2 2 1 2

Sample Output 1

cszapqbr

Initially, S = apzbqrcs.

  • For i = 1, perform a right circular shift by 1 on the part of S formed by the 1-st, 4-th, 7-th characters, resulting in S = cpzaqrbs.
  • For i = 2, perform a right circular shift by 1 on the part of S formed by the 2-nd, 5-th, 6-th, 8-th characters, resulting in S = cszapqbr.
  • For i = 3, perform a right circular shift by 1 on the part of S formed by the 3-rd character, resulting in S = cszapqbr (here, S is not changed).

Thus, you should print cszapqbr, the final S.


Sample Input 2

2 1
aa
1 1

Sample Output 2

aa
F - Dango

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

正の整数 L に対して、 レベル L のダンゴ文字列とは、以下の条件を満たす文字列です。

  • o- からなる長さ L+1 の文字列である。
  • 先頭の文字と末尾の文字のうちちょうど一方が - であり、そのほかの L 文字はすべて o である。

例えば、ooo- はレベル 3 のダンゴ文字列ですが、-ooo-ooo-oo- などはダンゴ文字列ではありません(より正確には、どのような正の整数 L に対してもレベル L のダンゴ文字列ではありません)。

2 種類の文字 o - からなる、長さ N の文字列 S が与えられます。 次の条件を満たすような正整数 X のうち、最大のものを求めてください。

  • S の連続する部分文字列であって、レベル X のダンゴ文字列であるものが存在する。

ただし、そのような整数が存在しない場合、-1 と出力してください。

制約

  • 1\leq N\leq 2\times10^5
  • So - からなる長さ N の文字列

入力

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

N
S

出力

S にレベル X のダンゴ文字列が含まれるような最大の X の値を 1 行で出力せよ。 そのような値が存在しない場合、-1 を出力せよ。


入力例 1

10
o-oooo---o

出力例 1

4

たとえば、S3 文字目から 7 文字目までに対応する部分文字列 oooo- は、レベル 4 のダンゴ文字列です。 S の部分文字列であってレベル 5 以上のダンゴ文字列であるようなものは存在しないため、4 と出力してください。


入力例 2

1
-

出力例 2

-1

S の連続する部分文字列は空文字列と -2 種類だけです。 これらはダンゴ文字列ではないため、-1 と出力してください。


入力例 3

30
-o-o-oooo-oo-o-ooooooo--oooo-o

出力例 3

7

Score : 300 points

Problem Statement

For a positive integer L, a level-L dango string is a string that satisfies the following conditions.

  • It is a string of length L+1 consisting of o and -.
  • Exactly one of the first character and the last character is -, and the other L characters are o.

For instance, ooo- is a level-3 dango string, but none of -ooo-, oo, and o-oo- is a dango string (more precisely, none of them is a level-L dango string for any positive integer L).

You are given a string S of length N consisting of the two characters o and -. Find the greatest positive integer X that satisfies the following condition.

  • There is a contiguous substring of S that is a level-X dango string.

If there is no such integer, print -1.

Constraints

  • 1\leq N\leq 2\times10^5
  • S is a string of length N consisting of o and -.

Input

The input is given from Standard Input in the following format:

N
S

Output

Print the greatest positive integer X such that S contains a level-X dango string, or -1 if there is no such integer.


Sample Input 1

10
o-oooo---o

Sample Output 1

4

For instance, the substring oooo- corresponding to the 3-rd through 7-th characters of S is a level-4 dango string. No substring of S is a level-5 dango string or above, so you should print 4.


Sample Input 2

1
-

Sample Output 2

-1

Only the empty string and - are the substrings of S. They are not dango strings, so you should print -1.


Sample Input 3

30
-o-o-oooo-oo-o-ooooooo--oooo-o

Sample Output 3

7
G - Root M Leaper

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

N \times N のマス目があります。上から i 行目、左から j 列目のマスを (i,j) と表します。

始め、(1,1) に駒が 1 個置かれています。あなたは以下の操作を何度でも行うことができます。

  • 今駒が置かれているマスと距離がちょうど \sqrt{M} であるマスに駒を移動させる。

ここで、マス (i,j) とマス (k,l) の距離は \sqrt{(i-k)^2+(j-l)^2} とします。

全てのマス (i,j) に対して、以下の問題を解いてください。

  • 駒を (1,1) から (i,j) に移動させることができるかを判定し、できる場合は操作回数の最小値を求めてください。

制約

  • 1 \le N \le 400
  • 1 \le M \le 10^6
  • 入力は全て整数

入力

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

N M

出力

N 行出力せよ。i 行目には N 個の整数を出力せよ。i 行目の j 個目の出力は、マス (i,j) に駒を移動させることができるのであれば操作回数の最小値を、そうでないのであれば -1 を出力せよ。


入力例 1

3 1

出力例 1

0 1 2
1 2 3
2 3 4

駒は上下左右の 4 個のマスに移動することができます。

例えば (2,2) に移動するには、以下のように 2 回の操作を行えばよいです。

  • 今駒は (1,1) に置かれている。(1,1)(1,2) の距離はちょうど \sqrt{1} であるため、駒を (1,2) に移動させる。
  • 今駒は (1,2) に置かれている。(1,2)(2,2) の距離はちょうど \sqrt{1} であるため、駒を (2,2) に移動させる。

入力例 2

10 5

出力例 2

0 3 2 3 2 3 4 5 4 5
3 4 1 2 3 4 3 4 5 6
2 1 4 3 2 3 4 5 4 5
3 2 3 2 3 4 3 4 5 6
2 3 2 3 4 3 4 5 4 5
3 4 3 4 3 4 5 4 5 6
4 3 4 3 4 5 4 5 6 5
5 4 5 4 5 4 5 6 5 6
4 5 4 5 4 5 6 5 6 7
5 6 5 6 5 6 5 6 7 6

Score : 400 points

Problem Statement

There is a grid with N \times N squares. We denote by (i, j) the square at the i-th row from the top and j-th column from the left.

Initially, a piece is placed on (1, 1). You may repeat the following operation any number of times:

  • Let (i, j) be the square the piece is currently on. Move the piece to the square whose distance from (i, j) is exactly \sqrt{M}.

Here, we define the distance between square (i, j) and square (k, l) as \sqrt{(i-k)^2+(j-l)^2}.

For all squares (i, j), determine if the piece can reach (i, j). If it can, find the minimum number of operations required to do so.

Constraints

  • 1 \le N \le 400
  • 1 \le M \le 10^6
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

N M

Output

Print N lines. The i-th line should contain N integers. If the piece can reach (i, j), the j-th integer in the i-th line should be the minimum number of operations required to do so; otherwise, it should be -1.


Sample Input 1

3 1

Sample Output 1

0 1 2
1 2 3
2 3 4

You can move the piece to four adjacent squares.

For example, we can move the piece to (2,2) with two operations as follows.

  • The piece is now on (1,1). The distance between (1,1) and (1,2) is exactly \sqrt{1}, so move the piece to (1,2).
  • The piece is now on (1,2). The distance between (1,2) and (2,2) is exactly \sqrt{1}, so move the piece to (2,2).

Sample Input 2

10 5

Sample Output 2

0 3 2 3 2 3 4 5 4 5
3 4 1 2 3 4 3 4 5 6
2 1 4 3 2 3 4 5 4 5
3 2 3 2 3 4 3 4 5 6
2 3 2 3 4 3 4 5 4 5
3 4 3 4 3 4 5 4 5 6
4 3 4 3 4 5 4 5 6 5
5 4 5 4 5 4 5 6 5 6
4 5 4 5 4 5 6 5 6 7
5 6 5 6 5 6 5 6 7 6
H - 7x7x7

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 475

問題文

座標空間上に一辺 7 の立方体を 3 つ、ちょうど 1,2,3 個の立方体に含まれる領域の体積がそれぞれ V_1,V_2,V_3 となるように配置したいです。

3 つの整数 a,b,c に対し、(a\leq x\leq a+7) \land (b\leq y\leq b+7) \land (c\leq z\leq c+7) で表される立方体領域を C(a,b,c) とおきます。

以下の条件を全て満たすような 9 つの整数 a_1,b_1,c_1,a_2,b_2,c_2,a_3,b_3,c_3 が存在するか判定し、存在するならば実際に 1 つ求めてください。

  • |a_1|,|b_1|,|c_1|,|a_2|,|b_2|,|c_2|,|a_3|,|b_3|,|c_3| \leq 100
  • C_i = C(a_i,b_i,c_i)\ (i=1,2,3) とおいたとき、
    • C_1,C_2,C_3 のうちちょうど 1 個に含まれる領域の体積は V_1 である。
    • C_1,C_2,C_3 のうちちょうど 2 個に含まれる領域の体積は V_2 である。
    • C_1,C_2,C_3 の全てに含まれる領域の体積は V_3 である。

制約

  • 0\leq V_1,V_2,V_3 \leq 3\times 7^3
  • 入力は全て整数

入力

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

V_1 V_2 V_3

出力

問題文中の条件を全て満たすような 9 つの整数 a_1,b_1,c_1,a_2,b_2,c_2,a_3,b_3,c_3 が存在しないならば No を出力し、存在するならば以下の形式で出力せよ。 複数存在する場合はそのどれを出力してもよい。

Yes
a_1 b_1 c_1 a_2 b_2 c_2 a_3 b_3 c_3

入力例 1

840 84 7

出力例 1

Yes
0 0 0 0 6 0 6 0 0

(a_1,b_1,c_1,a_2,b_2,c_2,a_3,b_3,c_3)=(0,0,0,0,6,0,6,0,0) の場合を考えます。

この図は C_1,C_2,C_3 の位置関係を表したもので、それぞれ橙、水色、緑の立方体に対応しています。

このとき、

  • |a_1|,|b_1|,|c_1|,|a_2|,|b_2|,|c_2|,|a_3|,|b_3|,|c_3| は全て 100 以下
  • C_1,C_2,C_3 の全てに含まれる領域は (6\leq x\leq 7)\land (6\leq y\leq 7) \land (0\leq z\leq 7) であり、その体積は (7-6)\times(7-6)\times(7-0)=7
  • C_1,C_2,C_3 のうちちょうど 2 個に含まれる領域は ((0\leq x < 6)\land (6\leq y\leq 7) \land (0\leq z\leq 7))\lor((6\leq x\leq 7)\land (0\leq y< 6) \land (0\leq z\leq 7)) であり、 その体積は (6-0)\times(7-6)\times(7-0)\times 2=84
  • C_1,C_2,C_3 のうちちょうど 1 個に含まれる領域の体積は 840

であり、条件を全て満たします。

(a_1,b_1,c_1,a_2,b_2,c_2,a_3,b_3,c_3)=(-10, 0, 0, -10, 0, 6, -10, 6, 1) なども同様に条件を全て満たすため、正当な出力として判定されます。


入力例 2

343 34 3

出力例 2

No

条件を全て満たすような 9 つの整数 a_1,b_1,c_1,a_2,b_2,c_2,a_3,b_3,c_3 は存在しません。

Score: 475 points

Problem Statement

In a coordinate space, we want to place three cubes with a side length of 7 so that the volumes of the regions contained in exactly one, two, three cube(s) are V_1, V_2, V_3, respectively.

For three integers a, b, c, let C(a,b,c) denote the cubic region represented by (a\leq x\leq a+7) \land (b\leq y\leq b+7) \land (c\leq z\leq c+7).

Determine whether there are nine integers a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3 that satisfy all of the following conditions, and find one such tuple if it exists.

  • |a_1|, |b_1|, |c_1|, |a_2|, |b_2|, |c_2|, |a_3|, |b_3|, |c_3| \leq 100
  • Let C_i = C(a_i, b_i, c_i)\ (i=1,2,3).
    • The volume of the region contained in exactly one of C_1, C_2, C_3 is V_1.
    • The volume of the region contained in exactly two of C_1, C_2, C_3 is V_2.
    • The volume of the region contained in all of C_1, C_2, C_3 is V_3.

Constraints

  • 0 \leq V_1, V_2, V_3 \leq 3 \times 7^3
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

V_1 V_2 V_3

Output

If no nine integers a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3 satisfy all of the conditions in the problem statement, print No. Otherwise, print such integers in the following format. If multiple solutions exist, you may print any of them.

Yes
a_1 b_1 c_1 a_2 b_2 c_2 a_3 b_3 c_3

Sample Input 1

840 84 7

Sample Output 1

Yes
0 0 0 0 6 0 6 0 0

Consider the case (a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3) = (0, 0, 0, 0, 6, 0, 6, 0, 0).

The figure represents the positional relationship of C_1, C_2, and C_3, corresponding to the orange, cyan, and green cubes, respectively.

Here,

  • All of |a_1|, |b_1|, |c_1|, |a_2|, |b_2|, |c_2|, |a_3|, |b_3|, |c_3| are not greater than 100.
  • The region contained in all of C_1, C_2, C_3 is (6\leq x\leq 7)\land (6\leq y\leq 7) \land (0\leq z\leq 7), with a volume of (7-6)\times(7-6)\times(7-0)=7.
  • The region contained in exactly two of C_1, C_2, C_3 is ((0\leq x < 6)\land (6\leq y\leq 7) \land (0\leq z\leq 7))\lor((6\leq x\leq 7)\land (0\leq y < 6) \land (0\leq z\leq 7)), with a volume of (6-0)\times(7-6)\times(7-0)\times 2=84.
  • The region contained in exactly one of C_1, C_2, C_3 has a volume of 840.

Thus, all conditions are satisfied.

(a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3) = (-10, 0, 0, -10, 0, 6, -10, 6, 1) also satisfies all conditions and would be a valid output.


Sample Input 2

343 34 3

Sample Output 2

No

No nine integers a_1, b_1, c_1, a_2, b_2, c_2, a_3, b_3, c_3 satisfy all of the conditions.

I - Teleporter and Closed off

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

N 個の都市があり、都市 1, 都市 2, \ldots, 都市 N と番号づけられています。
いくつかの異なる都市の間は一方通行のテレポーターによって移動できます。 都市 i (1\leq i\leq N) からテレポーターによって直接移動できる都市は 01 からなる長さ M の文字列 S_i によって表されます。具体的には、1\leq j\leq N に対して、

  • 1\leq j-i\leq M かつ S_i(j-i) 文字目が 1 ならば、都市 i から都市 j に直接移動できる。
  • そうでない時、都市 i から都市 j へは直接移動できない。

k=2,3,\ldots, N-1 に対して次の問題を解いてください。

テレポータを繰り返し使用することによって、都市 k を通らずに都市 1 から 都市 N へ移動できるか判定し、 できるならばそのために必要なテレポーターの使用回数の最小値を、 できないならば -1 を出力せよ。

制約

  • 3 \leq N \leq 10^5
  • 1\leq M\leq 10
  • M<N
  • S_i01 のみからなる長さ M の文字列
  • i+j>N ならば S_ij 文字目は 0
  • N,M は整数

入力

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

N M
S_1
S_2
\vdots
S_N

出力

N-2 個の整数を空白区切りで一行に出力せよ。 i (1\leq i\leq N-2) 番目には、k=i+1 に対する問題の答えを出力せよ。


入力例 1

5 2
11
01
11
10
00

出力例 1

2 3 2

テレポータによって各都市からはそれぞれ以下の都市へ直接移動する事ができます。

  • 都市 1 からは都市 2,3 へ移動できる。
  • 都市 2 からは都市 4 へ移動できる。
  • 都市 3 からは都市 4,5 へ移動できる。
  • 都市 4 からは都市 5 へ移動できる。
  • 都市 5 から移動できる都市は存在しない。

よって、都市 1 から都市 5 へ移動する方法は、

  • 経路 1 : 都市 1 \to 都市 2 \to 都市 4 \to 都市 5
  • 経路 2 : 都市 1 \to 都市 3 \to 都市 4 \to 都市 5
  • 経路 3 : 都市 1 \to 都市 3 \to 都市 5

3 つがあり、

  • 都市 2 を通らない経路は経路 2, 経路 32つであり、そのうちテレポーターの使用回数が最小となるのは経路 3 で、この時 2 回使用する。
  • 都市 3 を通らない経路は経路 1 のみであり、この時テレポーターは 3 回使用する。
  • 都市 4 を通らない経路は経路 3 のみであり、この時テレポーターは 2 回使用する。

となります。よって、2,3,2 をこの順に空白区切りで出力します。


入力例 2

6 3
101
001
101
000
100
000

出力例 2

-1 3 3 -1

都市 1 から都市 6 へ移動する方法は、都市 1 \to 都市 2 \to 都市 5 \to 都市 6 のみであるため、
k=2,5 の場合には都市 k を通らずに都市 1 から都市 6 へ移動する方法は存在せず、
k=3,4 の場合には上の方法が条件をみたし、テレポーターを 3 回使用します。

よって、-1,3,3,-1 をこの順に空白区切りで出力します。

テレポーターは一方通行であるため、 都市 3 から都市 4 へはテレポーターによって移動できますが、 都市 4 から都市 3 へは移動できず、
都市 1 \to 都市 4 \to 都市 3 \to 都市 6 のような移動はできない事に注意してください。

Score : 500 points

Problem Statement

There are N cities numbered city 1, city 2, \ldots, and city N.
There are also one-way teleporters that send you to different cities. Whether a teleporter can send you directly from city i (1\leq i\leq N) to another is represented by a length-M string S_i consisting of 0 and 1. Specifically, for 1\leq j\leq N,

  • if 1\leq j-i\leq M and the (j-i)-th character of S_i is 1, then a teleporter can send you directly from city i to city j;
  • otherwise, it cannot send you directly from city i to city j.

Solve the following problem for k=2,3,\ldots, N-1:

Can you travel from city 1 to city N without visiting city k by repeatedly using a teleporter? If you can, print the minimum number of times you need to use a teleporter; otherwise, print -1.

Constraints

  • 3 \leq N \leq 10^5
  • 1\leq M\leq 10
  • M<N
  • S_i is a string of length M consisting of 0 and 1.
  • If i+j>N, then the j-th character of S_i is 0.
  • N and M are integers.

Input

The input is given from Standard Input in the following format:

N M
S_1
S_2
\vdots
S_N

Output

Print (N-2) integers, separated by spaces, in a single line. The i-th (1\leq i\leq N-2) integer should be the answer to the problem for k=i+1.


Sample Input 1

5 2
11
01
11
10
00

Sample Output 1

2 3 2

A teleporter sends you

  • from city 1 to cities 2 and 3;
  • from city 2 to city 4;
  • from city 3 to cities 4 and 5;
  • from city 4 to city 5; and
  • from city 5 to nowhere.

Therefore, there are three paths to travel from city 1 to city 5:

  • path 1 : city 1 \to city 2 \to city 4 \to city 5;
  • path 2 : city 1 \to city 3 \to city 4 \to city 5; and
  • path 3 : city 1 \to city 3 \to city 5.

Among these paths,

  • two paths, path 2 and path 3, do not visit city 2. Among them, path 3 requires the minimum number of teleporter uses (twice).
  • Path 1 is the only path without city 3. It requires using a teleporter three times.
  • Path 3 is the only path without city 4. It requires using a teleporter twice.

Thus, 2, 3, and 2, separated by spaces, should be printed.


Sample Input 2

6 3
101
001
101
000
100
000

Sample Output 2

-1 3 3 -1

The only path from city 1 to city 6 is city 1 \to city 2 \to city 5 \to city 6.
For k=2,5, there is no way to travel from city 1 to city 6 without visiting city k.
For k=3,4, the path above satisfies the condition; it requires using a teleporter three times.

Thus, -1, 3, 3, and -1, separated by spaces, should be printed.

Note that a teleporter is one-way; a teleporter can send you from city 3 to city 4, but not from city 4 to city 3,
so the following path, for example, is invalid: city 1 \to city 4 \to city 3 \to city 6.