A - Swap Odd and Even

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

英小文字からなる長さが偶数の文字列 S が与えられます。S の長さを |S|Si 文字目を S_i で表します。

i = 1, 2, \ldots, \frac{|S|}{2} の順に以下の操作を行い、すべての操作を終えた後の S を出力してください。

  • S_{2i-1}S_{2i} を入れ替える

制約

  • S は英小文字からなる長さが偶数の文字列
  • S の長さは 100 以下

入力

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

S

出力

答えを出力せよ。


入力例 1

abcdef

出力例 1

badcfe

操作を行う前は S = abcdef です。
i = 1 について操作を行うと、S_1S_2 が入れ替わるので S = bacdef になります。
i = 2 について操作を行うと、S_3S_4 が入れ替わるので S = badcef になります。
i = 3 について操作を行うと、S_5S_6 が入れ替わるので S = badcfe になります。
したがって、badcfe を出力します。


入力例 2

aaaa

出力例 2

aaaa

入力例 3

atcoderbeginnercontest

出力例 3

taocedbrgeniencrnoetts

Score : 100 points

Problem Statement

You are given a string S of even length consisting of lowercase English letters. Let |S| be the length of S, and S_i be the i-th character of S.

Perform the following operation for each i = 1, 2, \ldots, \frac{|S|}{2} in this order, and print the final S.

  • Swap S_{2i-1} and S_{2i}.

Constraints

  • S is a string of even length consisting of lowercase English letters.
  • The length of S is at most 100.

Input

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

S

Output

Print the answer.


Sample Input 1

abcdef

Sample Output 1

badcfe

Initially, S = abcdef.
Performing the operation for i = 1 swaps S_1 and S_2, making S = bacdef.
Performing the operation for i = 2 swaps S_3 and S_4, making S = badcef.
Performing the operation for i = 3 swaps S_5 and S_6, making S = badcfe.
Thus, badcfe should be printed.


Sample Input 2

aaaa

Sample Output 2

aaaa

Sample Input 3

atcoderbeginnercontest

Sample Output 3

taocedbrgeniencrnoetts
B - N-choice question

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

整数 A,B が与えられるので、 A+B の値を答えてください。
但し、この問題は N 択問題であり、 i 番の選択肢は C_i です。
正解となる 選択肢の番号 を出力してください。

制約

  • 入力は全て整数
  • 1 \le N \le 300
  • 1 \le A,B \le 1000
  • 1 \le C_i \le 2000
  • C_i は相異なる。すなわち、同じ選択肢が複数存在することはない。
  • A+B=C_i なる i が丁度 1 つ存在する。すなわち、正解となる選択肢が必ずただ 1 つ存在する。

入力

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

N A B
C_1 C_2 \dots C_N

出力

答えを整数として出力せよ。


入力例 1

3 125 175
200 300 400

出力例 1

2

125+175 = 300 です。
1 番の選択肢は 2002 番の選択肢は 3003 番の選択肢は 400 です。
よって正解となる選択肢の番号は 2 番であり、これを出力します。


入力例 2

1 1 1
2

出力例 2

1

1 択問題である場合もあります。


入力例 3

5 123 456
135 246 357 468 579

出力例 3

5

Score : 100 points

Problem Statement

Given integers A and B, find A+B.
This is a N-choice problem; the i-th choice is C_i.
Print the index of the correct choice.

Constraints

  • All values in the input are integers.
  • 1 \le N \le 300
  • 1 \le A,B \le 1000
  • 1 \le C_i \le 2000
  • C_i are pairwise distinct. In other words, no two choices have the same value.
  • There is exactly one i such that A+B=C_i. In other words, there is always a unique correct choice.

Input

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

N A B
C_1 C_2 \dots C_N

Output

Print the answer as an integer.


Sample Input 1

3 125 175
200 300 400

Sample Output 1

2

We have 125+175 = 300.
The first, second, and third choices are 200, 300, and 400, respectively.
Thus, the 2-nd choice is correct, so 2 should be printed.


Sample Input 2

1 1 1
2

Sample Output 2

1

The problem may be a one-choice problem.


Sample Input 3

5 123 456
135 246 357 468 579

Sample Output 3

5
C - Pizza

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

ここに円形のピザが 1 枚あります。
高橋くんは長さ N の数列 A を使ってこのピザを以下の手順で切り分けます。

  • 最初に、円の中心から 12 時の方向に切れ込みをひとつ入れます。
  • 次に、以下の操作を N 回繰り返します。 i 回目の操作では以下を行います。
    • まず、ピザを時計回りに A_i 度回転させる。
    • 次に、円の中心から 12 時の方向に切れ込みをひとつ入れる。

例えば、A=(90,180,45,195) として手順を行うと、下図のようになります。

このとき、最も大きなピザの中心角が何度であるか求めてください。

制約

  • 入力は全て整数
  • 1 \le N \le 359
  • 1 \le A_i \le 359
  • 同じ場所に複数回切れ込みが入ることはない。

入力

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

N
A_1 A_2 \dots A_N

出力

答えを整数として出力せよ。


入力例 1

4
90 180 45 195

出力例 1

120

この入力は問題文中の例と一致します。
最も大きなピザの中心角は 120 度です。


入力例 2

1
1

出力例 2

359

入力例 3

10
215 137 320 339 341 41 44 18 241 149

出力例 3

170

Score : 200 points

Problem Statement

We have a circular pizza.
Takahashi will cut this pizza using a sequence A of length N, according to the following procedure.

  • First, make a cut from the center in the 12 o'clock direction.
  • Next, do N operations. The i-th operation is as follows.
    • Rotate the pizza A_i degrees clockwise.
    • Then, make a cut from the center in the 12 o'clock direction.

For example, if A=(90,180,45,195), the procedure cuts the pizza as follows.

Find the center angle of the largest pizza after the procedure.

Constraints

  • All values in input are integers.
  • 1 \le N \le 359
  • 1 \le A_i \le 359
  • There will be no multiple cuts at the same position.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the answer as an integer.


Sample Input 1

4
90 180 45 195

Sample Output 1

120

This input coincides with the example in the Problem Statement.
The center angle of the largest pizza is 120 degrees.


Sample Input 2

1
1

Sample Output 2

359

Sample Input 3

10
215 137 320 339 341 41 44 18 241 149

Sample Output 3

170
D - Perfect String

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

英大文字と英小文字からなる文字列のうち、以下の条件を全て満たすものを素晴らしい文字列ということとします。

  • 英大文字が文字列の中に現れる。
  • 英小文字が文字列の中に現れる。
  • 全ての文字が相異なる。

例えば、AtCoderAa は素晴らしい文字列ですが、atcoderPerfect は素晴らしい文字列ではありません。

文字列 S が与えられるので、S が素晴らしい文字列か判定してください。

制約

  • 1 \le |S| \le 100
  • S は英大文字と英小文字からなる文字列である。

入力

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

S

出力

S が素晴らしい文字列ならば Yes を、そうでないならば No を出力せよ。


入力例 1

AtCoder

出力例 1

Yes

AtCoder は、英大文字が含まれ、英小文字も含まれ、かつ全ての文字が相異なるため素晴らしい文字列です。


入力例 2

Aa

出力例 2

Yes

Aa は違う文字であることに注意してください。この文字列は素晴らしい文字列です。


入力例 3

atcoder

出力例 3

No

英大文字が含まれていないため、素晴らしい文字列ではありません。


入力例 4

Perfect

出力例 4

No

2 文字目と 5 文字目が等しいため、素晴らしい文字列ではありません。

Score : 200 points

Problem Statement

Let us call a string consisting of uppercase and lowercase English alphabets a wonderful string if all of the following conditions are satisfied:

  • The string contains an uppercase English alphabet.
  • The string contains a lowercase English alphabet.
  • All characters in the string are pairwise distinct.

For example, AtCoder and Aa are wonderful strings, while atcoder and Perfect are not.

Given a string S, determine if S is a wonderful string.

Constraints

  • 1 \le |S| \le 100
  • S is a string consisting of uppercase and lowercase English alphabets.

Input

Input is given from Standard Input in the following format:

S

Output

If S is a wonderful string, print Yes; otherwise, print No.


Sample Input 1

AtCoder

Sample Output 1

Yes

AtCoder is a wonderful string because it contains an uppercase English alphabet, a lowercase English alphabet, and all characters in the string are pairwise distinct.


Sample Input 2

Aa

Sample Output 2

Yes

Note that A and a are different characters. This string is a wonderful string.


Sample Input 3

atcoder

Sample Output 3

No

It is not a wonderful string because it does not contain an uppercase English alphabet.


Sample Input 4

Perfect

Sample Output 4

No

It is not a wonderful string because the 2-nd and the 5-th characters are the same.

E - abc285_brutmhyhiizp

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

別世界の AtCoder で開催されている AtCoder Big Contest では、 10^{16} 問の問題が一度に出題されます。
問題の ID は 1 問目から順に A, B, ..., Z, AA, AB, ..., ZZ, AAA, ... と付けられています。

つまり、 ID は以下の順番で付けられています。

  • 長さ 1 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 2 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 3 の英大文字からなる文字列を辞書順に並べたもの
  • ...

このコンテストに含まれる問題の ID である文字列 S が与えられるので、それが何問目か答えてください。

制約

  • S は AtCoder Big Contest に含まれる問題の ID として正しい

入力

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

S

出力

答えを整数として出力せよ。


入力例 1

AB

出力例 1

28

ID が AB である問題は、 AtCoder Big Contest の 28 問目です。


入力例 2

C

出力例 2

3

ID が C である問題は、 AtCoder Big Contest の 3 問目です。


入力例 3

BRUTMHYHIIZP

出力例 3

10000000000000000

ID が BRUTMHYHIIZP である問題は、 AtCoder Big Contest の 10^{16} 問目、すなわち最終問題です。

Score : 300 points

Problem Statement

In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once.
The IDs of the problems are as follows, from the 1-st problem in order: A, B, ..., Z, AA, AB, ..., ZZ, AAA, ...

In other words, the IDs are given in the following order:

  • the strings of length 1 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 2 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 3 consisting of uppercase English letters, in lexicographical order;
  • ...

Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)

Constraints

  • S is a valid ID of a problem given in AtCoder Big Contest.

Input

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

S

Output

Print the answer as an integer.


Sample Input 1

AB

Sample Output 1

28

The problem whose ID is AB is the 28-th problem of AtCoder Big Contest, so 28 should be printed.


Sample Input 2

C

Sample Output 2

3

The problem whose ID is C is the 3-rd problem of AtCoder Big Contest, so 3 should be printed.


Sample Input 3

BRUTMHYHIIZP

Sample Output 3

10000000000000000

The problem whose ID is BRUTMHYHIIZP is the 10^{16}-th (last) problem of AtCoder Big Contest, so 10^{16} should be printed as an integer.

F - Takahashi Gets Lost

Time Limit: 3 sec / Memory Limit: 1024 MiB

配点 : 250

問題文

HW 列のグリッドがあります。

グリッドの各マスはのどちらかであり、 その情報は H 個の長さ W の文字列 S_1, S_2, \ldots, S_H で与えられます。 上から i 行目、左から j 列目のマスを (i, j) で表すと、 S_ij 文字目が . のときマス (i, j) は陸であり、# のときマス (i, j) は海です。

ここで、グリッドの外周のマス(すなわち、i = 1i = Hj = 1j = W のうち少なくとも 1 個以上を満たすマス (i, j) )については、すべて海であることが制約として保証されます。

高橋君が乗った宇宙船が、グリッド上のあるマスに不時着してしまいました。 その後、高橋君は LRUD のみからなる長さ N の文字列 T で表される手順に沿って、グリッド上を N 回移動しました。 i = 1, 2, \ldots, N について、Ti 文字目は i 回目の移動の内容を下記の通り表します。

  • L のとき、左に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i, j-1) である。
  • R のとき、右に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i, j+1) である。
  • U のとき、上に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i-1, j) である。
  • D のとき、下に 1 マス移動したことを表す。すなわち、移動前のマスを (i, j) とするとき、移動後のマスは (i+1, j) である。

高橋君の移動経路上のマス(不時着したマスおよび現在いるマスを含む)はいずれも海でないことがわかっています。 高橋君が現在いるマスとしてあり得るものの個数を出力してください。

制約

  • H, W, N は整数
  • 3 \leq H, W \leq 500
  • 1 \leq N \leq 500
  • TLRUD のみからなる長さ N の文字列
  • S_i.# のみからなる長さ W の文字列
  • 高橋君が現在いるマスとしてあり得るものが少なくとも 1 個存在する。
  • グリッドの外周のマスはすべて海である。

入力

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

H W N
T
S_1
S_2
\vdots
S_H

出力

答えを出力せよ。


入力例 1

6 7 5
LULDR
#######
#...#.#
##...##
#.#...#
#...#.#
#######

出力例 1

2

下記の 2 つの場合がありえるため、高橋君が現在いるマスとしてあり得るものは (3, 4)(4, 5)2 個です。

  • マス (3, 5) に不時着し、(3, 5) \rightarrow (3, 4) \rightarrow (2, 4) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4) と移動した場合
  • マス (4, 6) に不時着し、(4, 6) \rightarrow (4, 5) \rightarrow (3, 5) \rightarrow (3, 4) \rightarrow (4, 4) \rightarrow (4, 5) と移動した場合

入力例 2

13 16 9
ULURDLURD
################
##..##.#..####.#
###.#..#.....#.#
#..##..#####.###
#...#..#......##
###.##.#..#....#
##.#####....##.#
###.###.#.#.#..#
######.....##..#
#...#.#.######.#
##..###..#..#.##
#...#.#.#...#..#
################

出力例 2

6

Score: 250 points

Problem Statement

There is a grid with H rows and W columns.

Each cell of the grid is land or sea, which is represented by H strings S_1, S_2, \ldots, S_H of length W. Let (i, j) denote the cell at the i-th row from the top and j-th column from the left, and (i, j) is land if the j-th character of S_i is ., and (i, j) is sea if the character is #.

The constraints guarantee that all cells on the perimeter of the grid (that is, the cells (i, j) that satisfy at least one of i = 1, i = H, j = 1, j = W) are sea.

Takahashi's spaceship has crash-landed on a cell in the grid. Afterward, he moved N times on the grid following the instructions represented by a string T of length N consisting of L, R, U, and D. For i = 1, 2, \ldots, N, the i-th character of T describes the i-th move as follows:

  • L indicates a move of one cell to the left. That is, if he is at (i, j) before the move, he will be at (i, j-1) after the move.
  • R indicates a move of one cell to the right. That is, if he is at (i, j) before the move, he will be at (i, j+1) after the move.
  • U indicates a move of one cell up. That is, if he is at (i, j) before the move, he will be at (i-1, j) after the move.
  • D indicates a move of one cell down. That is, if he is at (i, j) before the move, he will be at (i+1, j) after the move.

It is known that all cells along his path (including the cell where he crash-landed and the cell he is currently on) are not sea. Print the number of cells that could be his current position.

Constraints

  • H, W, and N are integers.
  • 3 \leq H, W \leq 500
  • 1 \leq N \leq 500
  • T is a string of length N consisting of L, R, U, and D.
  • S_i is a string of length W consisting of . and #.
  • There is at least one cell that could be Takahashi's current position.
  • All cells on the perimeter of the grid are sea.

Input

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

H W N
T
S_1
S_2
\vdots
S_H

Output

Print the answer.


Sample Input 1

6 7 5
LULDR
#######
#...#.#
##...##
#.#...#
#...#.#
#######

Sample Output 1

2

The following two cases are possible, so there are two cells that could be Takahashi's current position: (3, 4) and (4, 5).

  • He crash-landed on cell (3, 5) and moved (3, 5) \rightarrow (3, 4) \rightarrow (2, 4) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4).
  • He crash-landed on cell (4, 6) and moved (4, 6) \rightarrow (4, 5) \rightarrow (3, 5) \rightarrow (3, 4) \rightarrow (4, 4) \rightarrow (4, 5).

Sample Input 2

13 16 9
ULURDLURD
################
##..##.#..####.#
###.#..#.....#.#
#..##..#####.###
#...#..#......##
###.##.#..#....#
##.#####....##.#
###.###.#.#.#..#
######.....##..#
#...#.#.######.#
##..###..#..#.##
#...#.#.#...#..#
################

Sample Output 2

6
G - Takahashi's Solitaire

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

高橋君は N 枚のカードを手札として持っています。 i = 1, 2, \ldots, N について、i 番目のカードには非負整数 A_i が書かれています。

高橋君は、まず手札から好きなカードを 1 枚選んで、テーブルの上に置きます。 その後、高橋君は好きな回数( 0 回でも良い)だけ、下記の操作を繰り返します。

  • 最後にテーブルの上に置いたカードに書かれた整数を X とする。手札に整数 X または整数 (X+1)\bmod M が書かれたカードがあれば、そのうち好きなものを 1 枚選んで、テーブルの上に置く。ここで、(X+1)\bmod M(X+1)M で割ったあまりを表す。

最終的に手札に残ったカードに書かれている整数の総和としてあり得る最小値を出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 2 \leq M \leq 10^9
  • 0 \leq A_i \lt M
  • 入力はすべて整数

入力

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

N M
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

9 7
3 0 2 5 5 3 0 6 3

出力例 1

11

高橋君が、まず 4 番目のカード(書かれた整数は 5 )をテーブルの上に置き、その後、以下の手順で操作を行う場合を考えます。

  • 5 番目のカード(書かれた整数は 5 )をテーブルの上に置く。
  • 8 番目のカード(書かれた整数は 6 )をテーブルの上に置く。
  • 2 番目のカード(書かれた整数は 0 )をテーブルの上に置く。
  • 7 番目のカード(書かれた整数は 0 )をテーブルの上に置く。

このとき、最終的に手札に残ったカードは、1, 3, 6, 9 枚目のカードであり、それらに書かれた整数の総和は 3 + 2 + 3 +3 = 11 です。 これが、最終的に手札に残ったカードに書かれている整数の総和としてあり得る最小値です。


入力例 2

1 10
4

出力例 2

0

入力例 3

20 20
18 16 15 9 8 8 17 1 3 17 11 9 12 11 7 3 2 14 3 12

出力例 3

99

Score : 400 points

Problem Statement

Takahashi has N cards in his hand. For i = 1, 2, \ldots, N, the i-th card has an non-negative integer A_i written on it.

First, Takahashi will freely choose a card from his hand and put it on a table. Then, he will repeat the following operation as many times as he wants (possibly zero).

  • Let X be the integer written on the last card put on the table. If his hand contains cards with the integer X or the integer (X+1)\bmod M written on them, freely choose one of those cards and put it on the table. Here, (X+1)\bmod M denotes the remainder when (X+1) is divided by M.

Print the smallest possible sum of the integers written on the cards that end up remaining in his hand.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 2 \leq M \leq 10^9
  • 0 \leq A_i \lt M
  • All values in the input are integers.

Input

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

N M
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

9 7
3 0 2 5 5 3 0 6 3

Sample Output 1

11

Assume that he first puts the fourth card (5 is written) on the table and then performs the following.

  • Put the fifth card (5 is written) on the table.
  • Put the eighth card (6 is written) on the table.
  • Put the second card (0 is written) on the table.
  • Put the seventh card (0 is written) on the table.

Then, the first, third, sixth, and ninth cards will end up remaining in his hand, and the sum of the integers on those cards is 3 + 2 + 3 +3 = 11. This is the minimum possible sum of the integers written on the cards that end up remaining in his hand.


Sample Input 2

1 10
4

Sample Output 2

0

Sample Input 3

20 20
18 16 15 9 8 8 17 1 3 17 11 9 12 11 7 3 2 14 3 12

Sample Output 3

99
H - Reachable Set

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 450

問題文

N 頂点 M 辺からなる無向グラフがあります。 頂点には 1,2,\ldots,N の番号がついており、i 番目 (1\leq i\leq M) の辺は頂点 u _ i と頂点 v _ i を結んでいます。

k=1,2,\ldots,N について、次の問題を解いてください。

次の操作について考える。

  • 頂点を一つ選ぶ。選んだ頂点と、選んだ頂点に接続する全ての辺をグラフから削除する。

上の操作を繰り返すことで、次の条件を満たすことができるか判定せよ。

  • 頂点 1 から辺をたどって到達できる頂点の集合が、頂点 1, 頂点 2,\ldots, 頂点 k のちょうど k 個からなる。

可能な場合、条件を満たすために少なくとも何回操作を行う必要があるか求めよ。

制約

  • 1\leq N\leq2\times10 ^ 5
  • 0\leq M\leq3\times10 ^ 5
  • 1\leq u _ i\lt v _ i\leq N\ (1\leq i\leq M)
  • (u _ i,v _ i)\neq(u _ j,v _ j)\ (1\leq i\lt j\leq M)
  • 入力はすべて整数

入力

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

N M
u _ 1 v _ 1
u _ 2 v _ 2
\vdots
u _ M v _ M

出力

N 行にわたって出力せよ。 i 行目 (1\leq i\leq N) には、k=i としたときの条件を満たすことができないなら -1 を、満たすことができるなら条件を満たすために行う必要がある操作の回数を出力せよ。


入力例 1

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

出力例 1

2
3
3
2
1
0

たとえば、k=2 としたときの問題では、頂点 3, 頂点 4, 頂点 53 つの頂点を選んで削除することで、頂点 1 から到達できる頂点を頂点 1, 頂点 22 つだけにすることができます。 頂点を 2 つ以下だけ削除して条件を満たすことはできないため、2 行目には 3 を出力してください。

また、k=6 としたときの問題では、頂点をひとつも削除しないことで頂点 1 から到達できる頂点を頂点 1, 頂点 2,\ldots, 頂点 66 つにすることができます。 なので、6 行目には 0 を出力してください。


入力例 2

5 4
1 5
2 3
3 4
4 5

出力例 2

1
-1
-1
-1
0

入力例 3

2 0

出力例 3

0
-1

辺が 1 つもない場合もあります。


入力例 4

11 25
6 9
5 9
2 3
1 9
10 11
4 5
9 10
8 9
7 8
3 5
1 7
6 10
4 7
7 9
1 10
4 11
3 8
2 7
3 4
1 8
2 8
3 7
2 10
1 6
6 11

出力例 4

5
-1
-1
-1
-1
-1
4
3
2
1
0

Score : 450 points

Problem Statement

You are given an undirected graph with N vertices and M edges. The vertices are numbered 1,2,\ldots,N, and the i‑th edge (1 \le i \le M) connects vertices u_i and v_i.

For each k = 1,2,\ldots,N, solve the following problem:

Consider the following operation.

  • Choose one vertex, and delete that vertex together with all edges incident to it.

Determine whether one can repeat this operation to satisfy the following condition:

  • The set of vertices reachable from vertex 1 by traversing edges consists exactly of the k vertices 1,2,\ldots,k.

If it is possible, find the minimum number of operations required to do so.

Constraints

  • 1 \le N \le 2 \times 10^{5}
  • 0 \le M \le 3 \times 10^{5}
  • 1 \le u_i < v_i \le N\ (1 \le i \le M)
  • (u_i,v_i) \ne (u_j,v_j)\ (1 \le i < j \le M)
  • All input values are integers.

Input

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

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M

Output

Print N lines. On the i-th line (1 \le i \le N), if one cannot satisfy the condition for k=i, print -1; otherwise, print the minimum number of operations required to satisfy the condition.


Sample Input 1

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

Sample Output 1

2
3
3
2
1
0

For example, for k = 2, deleting the three vertices 3, 4, 5 makes the set of vertices reachable from vertex 1 equal to the two vertices 1, 2. It is impossible with two or fewer deletions, so print 3 on the 2nd line.

For k = 6, deleting zero vertices makes the set of vertices reachable from vertex 1 equal to the six vertices 1,2,\ldots,6, so print 0 on the 6th line.


Sample Input 2

5 4
1 5
2 3
3 4
4 5

Sample Output 2

1
-1
-1
-1
0

Sample Input 3

2 0

Sample Output 3

0
-1

There may be no edges.


Sample Input 4

11 25
6 9
5 9
2 3
1 9
10 11
4 5
9 10
8 9
7 8
3 5
1 7
6 10
4 7
7 9
1 10
4 11
3 8
2 7
3 4
1 8
2 8
3 7
2 10
1 6
6 11

Sample Output 4

5
-1
-1
-1
-1
-1
4
3
2
1
0
I - Adding Chords

Time Limit: 3 sec / Memory Limit: 1024 MiB

配点 : 525

問題文

円周上に等間隔に N 個の点があり、時計回りに 1,2,\dots,N と番号がついています。

以下の形式のクエリが Q 個与えられるので順に処理してください。

  • A_i と点 B_i を結ぶ線分を書く。ただし、この線分が既に書かれている線分と交わる場合は書かない。

ここで、2Q 個の整数 A_1,\ldots,A_Q,B_1,\ldots,B_Q は相異なることが保証されます。

各線分が書かれたかどうか答えてください。

制約

  • 2 \leq N \leq 10^6
  • 1 \leq Q \leq 3\times 10^5
  • 1 \leq A_i < B_i \leq N
  • 2Q 個の整数 A_1,\ldots,A_Q,B_1,\ldots,B_Q は相異なる
  • 入力は全て整数

入力

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

N Q
A_1 B_1
A_2 B_2
\vdots
A_Q B_Q

出力

Q 行出力せよ。
i 行目には、i 番目のクエリにおいて線分が書かれたとき Yes、書かれなかったとき No と出力せよ。


入力例 1

8 3
1 5
2 7
3 4

出力例 1

Yes
No
Yes

クエリにより図のように線分が書かれます。

  • 1 番目のクエリで、点 1 と点 5 を結ぶ線分が書かれる。
  • 2 番目のクエリで、点 2 と点 7 を結ぶ線分は、1 番目のクエリで書いた線分と交わるので書かない。
  • 3 番目のクエリで、点 3 と点 4 を結ぶ線分が書かれる。


入力例 2

999999 4
123456 987654
888888 999999
1 3
2 777777

出力例 2

Yes
No
Yes
No

Score : 525 points

Problem Statement

There are N points equally spaced on a circle, numbered 1,2,\dots,N clockwise.

You are given Q queries of the following form; process them in order.

  • Draw the line segment connecting points A_i and B_i. However, if this segment intersects a segment that has already been drawn, do not draw it.

Here, it is guaranteed that the 2Q integers A_1,\ldots,A_Q,B_1,\ldots,B_Q are all distinct.

For each query, answer whether the segment was drawn.

Constraints

  • 2 \leq N \leq 10^6
  • 1 \leq Q \leq 3\times 10^5
  • 1 \leq A_i < B_i \leq N
  • The 2Q integers A_1,\ldots,A_Q,B_1,\ldots,B_Q are pairwise distinct.
  • All input values are integers.

Input

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

N Q
A_1 B_1
A_2 B_2
\vdots
A_Q B_Q

Output

Output Q lines. On the i-th line, output Yes if, in the i-th query, the segment was drawn, and No if it was not drawn.


Sample Input 1

8 3
1 5
2 7
3 4

Sample Output 1

Yes
No
Yes

By the queries, the segments are drawn as in the figure.

  • In the 1-st query, the segment connecting points 1 and 5 is drawn.
  • In the 2-nd query, the segment connecting points 2 and 7 is not drawn because it intersects the segment drawn in the 1-st query.
  • In the 3-rd query, the segment connecting points 3 and 4 is drawn.


Sample Input 2

999999 4
123456 987654
888888 999999
1 3
2 777777

Sample Output 2

Yes
No
Yes
No