A - Spoiler

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 150

問題文

英小文字と | のみからなる文字列 S が与えられます。S| をちょうど 2 個含むことが保証されます。

2 つの | の間にある文字および |S から削除した文字列を出力してください。

制約

  • S は英小文字および | のみからなる長さ 2 以上 100 以下の文字列
  • S| をちょうど 2 個含む

入力

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

S

出力

答えを出力せよ。


入力例 1

atcoder|beginner|contest

出力例 1

atcodercontest

2 つの | に挟まれた文字を全て削除して出力してください。


入力例 2

|spoiler|

出力例 2



全ての文字が削除されることもあります。


入力例 3

||xyz

出力例 3

xyz

Score: 150 points

Problem Statement

You are given a string S consisting of lowercase English letters and |. S is guaranteed to contain exactly two |s.

Remove the characters between the two |s, including the |s themselves, and print the resulting string.

Constraints

  • S is a string of length between 2 and 100, inclusive, consisting of lowercase English letters and |.
  • S contains exactly two |s.

Input

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

S

Output

Print the answer.


Sample Input 1

atcoder|beginner|contest

Sample Output 1

atcodercontest

Remove all the characters between the two |s and print the result.


Sample Input 2

|spoiler|

Sample Output 2



It is possible that all characters are removed.


Sample Input 3

||xyz

Sample Output 3

xyz
B - Triple Four

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

長さ N の整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。

A の中に同じ要素が 3 つ以上連続する箇所が存在するか判定してください。

より厳密には、 1 以上 N-2 以下の整数 i であって A_i=A_{i+1}=A_{i+2} を満たすものが存在するか判定してください。

制約

  • 3\le N\le 100
  • 1\le A_i\le 100
  • 入力される値は全て整数

入力

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

N
A_1 A_2 \ldots A_N

出力

A の中に同じ要素が 3 つ以上連続する箇所が存在するならば Yes を、存在しないならば No を出力せよ。


入力例 1

5
1 4 4 4 2

出力例 1

Yes

A=(1,4,4,4,2) です。 43 つ連続している箇所が存在するので、 Yes を出力してください。


入力例 2

6
2 4 4 2 2 4

出力例 2

No

A=(2,4,4,2,2,4) です。同じ要素が 3 つ以上連続している箇所は存在しないので、 No を出力してください。


入力例 3

8
1 4 2 5 7 7 7 2

出力例 3

Yes

入力例 4

10
1 2 3 4 5 6 7 8 9 10

出力例 4

No

入力例 5

13
1 1 1 1 1 1 1 1 1 1 1 1 1

出力例 5

Yes

Score : 100 points

Problem Statement

You are given an integer sequence of length N: A = (A_1,A_2,\ldots,A_N).

Determine whether there is a place in A where the same element appears three or more times in a row.

More formally, determine whether there exists an integer i with 1 \le i \le N-2 such that A_i = A_{i+1} = A_{i+2}.

Constraints

  • 3 \le N \le 100
  • 1 \le A_i \le 100
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_N

Output

If there is a place in A where the same element appears three or more times in a row, print Yes. Otherwise, print No.


Sample Input 1

5
1 4 4 4 2

Sample Output 1

Yes

We have A=(1,4,4,4,2). There is a place where 4 appears three times in a row, so print Yes.


Sample Input 2

6
2 4 4 2 2 4

Sample Output 2

No

We have A=(2,4,4,2,2,4). There is no place where the same element appears three or more times in a row, so print No.


Sample Input 3

8
1 4 2 5 7 7 7 2

Sample Output 3

Yes

Sample Input 4

10
1 2 3 4 5 6 7 8 9 10

Sample Output 4

No

Sample Input 5

13
1 1 1 1 1 1 1 1 1 1 1 1 1

Sample Output 5

Yes
C - Election

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

選挙が行われています。

N 人が投票を行い、i\,(1 \leq i \leq N) 番目の人は S_i という名前の候補者に投票しました。

得票数が最大の候補者の名前を答えてください。なお、与えられる入力では得票数が最大の候補者は一意に定まります。

制約

  • 1 \leq N \leq 100
  • S_i は英小文字からなる長さ 1 以上 10 以下の文字列
  • N は整数
  • 得票数が最大の候補者は一意に定まる

入力

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

N
S_1
S_2
\vdots
S_N

出力

得票数が最大の候補者の名前を出力せよ。


入力例 1

5
snuke
snuke
takahashi
takahashi
takahashi

出力例 1

takahashi

takahashi3 票、snuke2 票獲得しました。よって takahashi を出力します。


入力例 2

5
takahashi
takahashi
aoki
takahashi
snuke

出力例 2

takahashi

入力例 3

1
a

出力例 3

a

Score : 200 points

Problem Statement

An election is taking place.

N people voted. The i-th person (1 \leq i \leq N) cast a vote to the candidate named S_i.

Find the name of the candidate who received the most votes. The given input guarantees that there is a unique candidate with the most votes.

Constraints

  • 1 \leq N \leq 100
  • S_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.
  • N is an integer.
  • There is a unique candidate with the most votes.

Input

Input is given from Standard Input in the following format:

N
S_1
S_2
\vdots
S_N

Output

Print the name of the candidate who received the most votes.


Sample Input 1

5
snuke
snuke
takahashi
takahashi
takahashi

Sample Output 1

takahashi

takahashi got 3 votes, and snuke got 2, so we print takahashi.


Sample Input 2

5
takahashi
takahashi
aoki
takahashi
snuke

Sample Output 2

takahashi

Sample Input 3

1
a

Sample Output 3

a
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 - Gap Existence

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

長さ N の数列 A=(A_1,\ldots,A_N) が与えられます。

1\leq i,j \leq N である組 (i,j) であって、A_i-A_j=X となるものが存在するかどうか判定してください。

制約

  • 2 \leq N \leq 2\times 10^5
  • -10^9 \leq A_i \leq 10^9
  • -10^9 \leq X \leq 10^9
  • 入力は全て整数である

入力

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

N X
A_1 \ldots A_N

出力

1\leq i,j \leq N である組 (i,j) であって、A_i-A_j=X となるものが存在するとき Yes、存在しないとき No と出力せよ。


入力例 1

6 5
3 1 4 1 5 9

出力例 1

Yes

A_6-A_3=9-4=5 です。


入力例 2

6 -4
-2 -7 -1 -8 -2 -8

出力例 2

No

A_i-A_j=-4 となる組 (i,j) は存在しません。


入力例 3

2 0
141421356 17320508

出力例 3

Yes

A_1-A_1=0 です。

Score : 300 points

Problem Statement

You are given a sequence of N numbers: A=(A_1,\ldots,A_N).

Determine whether there is a pair (i,j) with 1\leq i,j \leq N such that A_i-A_j=X.

Constraints

  • 2 \leq N \leq 2\times 10^5
  • -10^9 \leq A_i \leq 10^9
  • -10^9 \leq X \leq 10^9
  • All values in the input are integers.

Input

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

N X
A_1 \ldots A_N

Output

Print Yes if there is a pair (i,j) with 1\leq i,j \leq N such that A_i-A_j=X, and No otherwise.


Sample Input 1

6 5
3 1 4 1 5 9

Sample Output 1

Yes

We have A_6-A_3=9-4=5.


Sample Input 2

6 -4
-2 -7 -1 -8 -2 -8

Sample Output 2

No

There is no pair (i,j) such that A_i-A_j=-4.


Sample Input 3

2 0
141421356 17320508

Sample Output 3

Yes

We have A_1-A_1=0.

F - Illuminate Buildings

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 350

問題文

N 棟のビルが等間隔に一列に並んでいます。手前から i 番目のビルの高さは H_i です。

あなたは次の条件をともに満たすようにいくつかのビルを選んで電飾で飾ろうとしています。

  • 選んだビルたちは高さが等しい
  • 選んだビルたちは等間隔に並んでいる

最大でいくつのビルを選ぶことができますか? なお、ちょうど 1 つのビルを選んだときは条件を満たすとみなします。

制約

  • 1 \leq N \leq 3000
  • 1 \leq H_i \leq 3000
  • 入力は全て整数である

入力

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

N
H_1 \ldots H_N

出力

答えを出力せよ。


入力例 1

8
5 7 5 7 7 5 7 7

出力例 1

3

手前から 2,5,8 番目のビルを選ぶと条件を満たします。


入力例 2

10
100 200 300 400 500 600 700 800 900 1000

出力例 2

1

1つのビルを選んだときは条件を満たすとみなします。


入力例 3

32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

出力例 3

3

Score : 350 points

Problem Statement

There are N buildings arranged in a line at equal intervals. The height of the i-th building from the front is H_i.

You want to decorate some of these buildings with illuminations so that both of the following conditions are satisfied:

  • The chosen buildings all have the same height.
  • The chosen buildings are arranged at equal intervals.

What is the maximum number of buildings you can choose? If you choose exactly one building, it is considered to satisfy the conditions.

Constraints

  • 1 \leq N \leq 3000
  • 1 \leq H_i \leq 3000
  • All input values are integers.

Input

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

N
H_1 \ldots H_N

Output

Print the answer.


Sample Input 1

8
5 7 5 7 7 5 7 7

Sample Output 1

3

Choosing the 2nd, 5th, and 8th buildings from the front satisfies the conditions.


Sample Input 2

10
100 200 300 400 500 600 700 800 900 1000

Sample Output 2

1

Choosing just one building is considered to satisfy the conditions.


Sample Input 3

32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Sample Output 3

3
G - Robot Arms 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

長さ N の正整数列 A = (A_1, A_2, \dots, A_N) および整数 x, y が与えられます。
次の条件をすべて満たすように、xy 座標平面上に N+1 個の点 p_1, p_2, \dots, p_N, p_{N+1} を配置することができるか判定してください。(同じ座標に 2 個以上の点を配置してもよいです。)

  • p_1 = (0, 0)
  • p_2 = (A_1, 0)
  • p_{N+1} = (x, y)
  • p_i と点 p_{i+1} の距離は A_i (1 \leq i \leq N)
  • 線分 p_i p_{i+1} と線分 p_{i+1} p_{i+2} のなす角は 90 度 (1 \leq i \leq N - 1)

制約

  • 2 \leq N \leq 10^3
  • 1 \leq A_i \leq 10
  • |x|, |y| \leq 10^4
  • 入力される値はすべて整数

入力

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

N x y
A_1 A_2 \dots A_N

出力

問題文の条件をすべて満たすように p_1, p_2, \dots, p_N, p_{N+1} を配置することができる場合は Yes を、そうでない場合は No を出力せよ。


入力例 1

3 -1 1
2 1 3

出力例 1

Yes

xy 座標平面に p_1 = (0, 0), p_2 = (2, 0), p_3 = (2, 1), p_4 = (-1, 1) として点を配置したのが以下の図です。これは問題文の条件をすべて満たしています。


入力例 2

5 2 0
2 2 2 2 2

出力例 2

Yes

p_1 = (0, 0), p_2 = (2, 0), p_3 = (2, 2), p_4 = (0, 2), p_5 = (0, 0), p_6 = (2, 0) とすれば問題文の条件をすべて満たすことができます。同じ座標に複数の点を置いてもよいのに注意してください。


入力例 3

4 5 5
1 2 3 4

出力例 3

No

入力例 4

3 2 7
2 7 4

出力例 4

No

入力例 5

10 8 -7
6 10 4 1 5 9 8 6 5 1

出力例 5

Yes

Score : 400 points

Problem Statement

You are given a sequence A = (A_1, A_2, \dots, A_N) of length N consisting of positive integers, and integers x and y.
Determine whether it is possible to place N+1 points p_1, p_2, \dots, p_N, p_{N+1} in the xy-coordinate plane to satisfy all of the following conditions. (It is allowed to place two or more points at the same coordinates.)

  • p_1 = (0, 0).
  • p_2 = (A_1, 0).
  • p_{N+1} = (x, y).
  • The distance between the points p_i and p_{i+1} is A_i. (1 \leq i \leq N)
  • The segments p_i p_{i+1} and p_{i+1} p_{i+2} form a 90 degree angle. (1 \leq i \leq N - 1)

Constraints

  • 2 \leq N \leq 10^3
  • 1 \leq A_i \leq 10
  • |x|, |y| \leq 10^4
  • All values in the input are integers.

Input

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

N x y
A_1 A_2 \dots A_N

Output

If it is possible to place p_1, p_2, \dots, p_N, p_{N+1} to satisfy all of the conditions in the Problem Statement, print Yes; otherwise, print No.


Sample Input 1

3 -1 1
2 1 3

Sample Output 1

Yes

The figure below shows a placement where p_1 = (0, 0), p_2 = (2, 0), p_3 = (2, 1), and p_4 = (-1, 1). All conditions in the Problem Statement are satisfied.


Sample Input 2

5 2 0
2 2 2 2 2

Sample Output 2

Yes

Letting p_1 = (0, 0), p_2 = (2, 0), p_3 = (2, 2), p_4 = (0, 2), p_5 = (0, 0), and p_6 = (2, 0) satisfies all the conditions. Note that multiple points may be placed at the same coordinates.


Sample Input 3

4 5 5
1 2 3 4

Sample Output 3

No

Sample Input 4

3 2 7
2 7 4

Sample Output 4

No

Sample Input 5

10 8 -7
6 10 4 1 5 9 8 6 5 1

Sample Output 5

Yes
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 - Blocked Roads

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

N 頂点 M 辺の有向グラフが与えられます。頂点には 1 から N の番号、辺には 1 から M の番号がついています。辺 i\,(1 \leq i \leq M) は頂点 s_i から頂点 t_i に向かう長さ 1 の辺です。

i\,(1 \leq i \leq M) について、辺 i のみ通れないときの頂点 1 から頂点 N までの最短距離を求めてください。ただし、頂点 1 から頂点 N にたどり着けない場合は -1 を出力してください。

制約

  • 2 \leq N \leq 400
  • 1 \leq M \leq N(N-1)
  • 1 \leq s_i,t_i \leq N
  • s_i \neq t_i
  • (s_i,t_i) \neq (s_j,t_j) (i \neq j)
  • 入力は全て整数である。

入力

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

N M
s_1 t_1
s_2 t_2
\vdots
s_M t_M

出力

M 行出力せよ。

i 行目には、辺 i のみ通れないときの頂点 1 から頂点 N までの最短距離を出力せよ。ただし、頂点 1 から頂点 N にたどり着けない場合は -1 を出力せよ。


入力例 1

3 3
1 2
1 3
2 3

出力例 1

1
2
1

入力例 2

4 4
1 2
2 3
2 4
3 4

出力例 2

-1
2
3
2

1 のみ通れないとき、頂点 1 から頂点 N にたどり着けないので -1 を出力します。


入力例 3

5 10
1 2
1 4
1 5
2 1
2 3
3 1
3 2
3 5
4 2
4 3

出力例 3

1
1
3
1
1
1
1
1
1
1

入力例 4

4 1
1 2

出力例 4

-1

Score : 500 points

Problem Statement

You are given a directed graph with N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i (1 \leq i \leq M) goes from Vertex s_i to Vertex t_i and has a length of 1.

For each i (1 \leq i \leq M), find the shortest distance from Vertex 1 to Vertex N when all edges except Edge i are passable, or print -1 if Vertex N is unreachable from Vertex 1.

Constraints

  • 2 \leq N \leq 400
  • 1 \leq M \leq N(N-1)
  • 1 \leq s_i,t_i \leq N
  • s_i \neq t_i
  • (s_i,t_i) \neq (s_j,t_j) (i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
s_1 t_1
s_2 t_2
\vdots
s_M t_M

Output

Print M lines.

The i-th line should contain the shortest distance from Vertex 1 to Vertex N when all edges except Edge i are passable, or -1 if Vertex N is unreachable from Vertex 1.


Sample Input 1

3 3
1 2
1 3
2 3

Sample Output 1

1
2
1

Sample Input 2

4 4
1 2
2 3
2 4
3 4

Sample Output 2

-1
2
3
2

Vertex N is unreachable from Vertex 1 when all edges except Edge 1 are passable, so the corresponding line contains -1.


Sample Input 3

5 10
1 2
1 4
1 5
2 1
2 3
3 1
3 2
3 5
4 2
4 3

Sample Output 3

1
1
3
1
1
1
1
1
1
1

Sample Input 4

4 1
1 2

Sample Output 4

-1