A - First Player

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

配点 : 100

問題文

1 、人 2\ldots 、人 N と番号付けられた N 人が、この順番で時計回りに円卓に座っています。 特に、時計回りで人 N の次の位置には人 1 が座っています。

i = 1, 2, \ldots, N について、人 i の名前は S_i 、年齢は A_i です。 ここで、異なる 2 人が同じ名前や同じ年齢であることはありません。

年齢が最も小さい人を起点として、座っている位置の時計回りの順番で、N 人全員の名前を出力してください。

制約

  • 2 \leq N \leq 100
  • N は整数
  • S_i は英小文字のみからなる長さ 1 以上 10 以下の文字列
  • i \neq j \implies S_i \neq S_j
  • 0 \leq A_i \leq 10^9
  • A_i は整数
  • i \neq j \implies A_i \neq A_j

入力

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

N
S_1 A_1
S_2 A_2
\vdots
S_N A_N

出力

N 行出力せよ。 i = 1, 2, \ldots, N について、i 行目には、年齢が最も小さい人を起点として時計回りで i 番目の位置に座っている人の名前を出力せよ。


入力例 1

5
alice 31
bob 41
carol 5
dave 92
ellen 65

出力例 1

carol
dave
ellen
alice
bob

年齢が最も小さい人は人 3 です。よって、人 3 を起点として座っている位置の時計回りの順番、すなわち、人 3 、人 4 、人 5 、人 1 、人 2 の順に名前を出力します。


入力例 2

2
takahashi 1000000000
aoki 999999999

出力例 2

aoki
takahashi

Score : 100 points

Problem Statement

There are N people numbered 1, 2, \ldots, N, sitting in this clockwise order around a round table. In particular, person 1 is sitting next to person N in the clockwise direction.

For each i = 1, 2, \ldots, N, person i has a name S_i and an age A_i. Here, no two people have the same name or the same age.

Starting from the youngest person, print the names of all N people in the order of their seating positions in clockwise order.

Constraints

  • 2 \leq N \leq 100
  • N is an integer.
  • S_i is a string of length between 1 and 10, consisting of lowercase English letters.
  • i \neq j \implies S_i \neq S_j
  • 0 \leq A_i \leq 10^9
  • A_i is an integer.
  • i \neq j \implies A_i \neq A_j

Input

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

N
S_1 A_1
S_2 A_2
\vdots
S_N A_N

Output

Print N lines. For each i = 1, 2, \ldots, N, the i-th line should contain the name of the person sitting in the i-th position clockwise from the youngest person.


Sample Input 1

5
alice 31
bob 41
carol 5
dave 92
ellen 65

Sample Output 1

carol
dave
ellen
alice
bob

The youngest person is person 3. Therefore, starting from person 3, print the names in the clockwise order of their seating positions: person 3, person 4, person 5, person 1, and person 2.


Sample Input 2

2
takahashi 1000000000
aoki 999999999

Sample Output 2

aoki
takahashi
B - Subscribers

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

配点 : 200

問題文

整数 N が与えられます。
以下の指示に従って N の近似値を出力してください。

  • N10^3-1 以下ならば、N をそのまま出力する。
  • N10^3 以上 10^4-1 以下ならば、N の一の位を切り捨てて出力する。
  • N10^4 以上 10^5-1 以下ならば、N の十の位以下を切り捨てて出力する。
  • N10^5 以上 10^6-1 以下ならば、N の百の位以下を切り捨てて出力する。
  • N10^6 以上 10^7-1 以下ならば、N の千の位以下を切り捨てて出力する。
  • N10^7 以上 10^8-1 以下ならば、N の一万の位以下を切り捨てて出力する。
  • N10^8 以上 10^9-1 以下ならば、N の十万の位以下を切り捨てて出力する。

制約

  • N0 以上 10^9-1 以下の整数

入力

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

N

出力

答えを出力せよ。


入力例 1

20230603

出力例 1

20200000

2023060310^7 以上 10^8-1 以下です。
したがって、一万以下の位を切り捨てて 20200000 を出力します。


入力例 2

0

出力例 2

0

入力例 3

304

出力例 3

304

入力例 4

500600

出力例 4

500000

Score : 200 points

Problem Statement

You are given an integer N.
Print an approximation of N according to the following instructions.

  • If N is less than or equal to 10^3-1, print N as it is.
  • If N is between 10^3 and 10^4-1, inclusive, truncate the ones digit of N and print the result.
  • If N is between 10^4 and 10^5-1, inclusive, truncate the tens digit and all digits below it of N and print the result.
  • If N is between 10^5 and 10^6-1, inclusive, truncate the hundreds digit and all digits below it of N and print the result.
  • If N is between 10^6 and 10^7-1, inclusive, truncate the thousands digit and all digits below it of N and print the result.
  • If N is between 10^7 and 10^8-1, inclusive, truncate the ten-thousands digit and all digits below it of N and print the result.
  • If N is between 10^8 and 10^9-1, inclusive, truncate the hundred-thousands digit and all digits below it of N and print the result.

Constraints

  • N is an integer between 0 and 10^9-1, inclusive.

Input

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

N

Output

Print the answer.


Sample Input 1

20230603

Sample Output 1

20200000

20230603 is between 10^7 and 10^8-1 (inclusive).
Therefore, truncate the ten-thousands digit and all digits below it, and print 20200000.


Sample Input 2

0

Sample Output 2

0

Sample Input 3

304

Sample Output 3

304

Sample Input 4

500600

Sample Output 4

500000
C - Virus

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

配点 : 300

問題文

1, 2, \ldots, N の番号がついた N 人の人が二次元平面上におり、人 i は座標 (X_i,Y_i) で表される地点にいます。

1 がウイルスに感染しました。ウイルスに感染した人から距離が D 以内にいる人にウイルスはうつります。

ただし、距離はユークリッド距離、すなわち 2(a_1, a_2)(b_1, b_2) に対し、この 2 点間の距離が \sqrt {(a_1-b_1)^2 + (a_2-b_2)^2} であるものとして定められています。

十分に時間が経過した、すなわち人 i がウイルスに感染しているならば 人 i との距離が D 以内にいるすべての人がウイルスに感染している状態になったときに、各 i について人 i がウイルスに感染しているか判定してください。

制約

  • 1 \leq N, D \leq 2000
  • -1000 \leq X_i, Y_i \leq 1000
  • i \neq j のとき (X_i, Y_i) \neq (X_j, Y_j)
  • 入力はすべて整数

入力

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

N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

N 行出力せよ。i 行目には、人 i がウイルスに感染しているならば Yes を、そうでないならば No を出力せよ。


入力例 1

4 5
2 -1
3 1
8 8
0 5

出力例 1

Yes
Yes
No
Yes

1 と人 2 の距離は \sqrt 5 であるため、人 2 はウイルスに感染します。
また、人 2 と人 4 の距離は 5 であるため、人 4 はウイルスに感染します。
3 は距離 5 以内に人がいないので、ウイルスに感染することはありません。


入力例 2

3 1
0 0
-1000 -1000
1000 1000

出力例 2

Yes
No
No

入力例 3

9 4
3 2
6 -1
1 6
6 5
-2 -3
5 3
2 -3
2 1
2 6

出力例 3

Yes
No
No
Yes
Yes
Yes
Yes
Yes
No

Score : 300 points

Problem Statement

There are N people numbered 1, 2, \ldots, N on a two-dimensional plane, and person i is at the point represented by the coordinates (X_i,Y_i).

Person 1 has been infected with a virus. The virus spreads to people within a distance of D from an infected person.

Here, the distance is defined as the Euclidean distance, that is, for two points (a_1, a_2) and (b_1, b_2), the distance between these two points is \sqrt {(a_1-b_1)^2 + (a_2-b_2)^2}.

After a sufficient amount of time has passed, that is, when all people within a distance of D from person i are infected with the virus if person i is infected, determine whether person i is infected with the virus for each i.

Constraints

  • 1 \leq N, D \leq 2000
  • -1000 \leq X_i, Y_i \leq 1000
  • (X_i, Y_i) \neq (X_j, Y_j) if i \neq j.
  • All input values are integers.

Input

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

N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print N lines. The i-th line should contain Yes if person i is infected with the virus, and No otherwise.


Sample Input 1

4 5
2 -1
3 1
8 8
0 5

Sample Output 1

Yes
Yes
No
Yes

The distance between person 1 and person 2 is \sqrt 5, so person 2 gets infected with the virus.
Also, the distance between person 2 and person 4 is 5, so person 4 gets infected with the virus.
Person 3 has no one within a distance of 5, so they will not be infected with the virus.


Sample Input 2

3 1
0 0
-1000 -1000
1000 1000

Sample Output 2

Yes
No
No

Sample Input 3

9 4
3 2
6 -1
1 6
6 5
-2 -3
5 3
2 -3
2 1
2 6

Sample Output 3

Yes
No
No
Yes
Yes
Yes
Yes
Yes
No
D - A Piece of Cake

実行時間制限: 3 sec / メモリ制限: 1024 MB

配点 : 400

問題文

xy -平面上にいくつかのイチゴが載った長方形のケーキがあります。 ケーキは、長方形領域 \lbrace (x, y) : 0 \leq x \leq W, 0 \leq y \leq H \rbrace をちょうど占めます。

ケーキには N 個のイチゴが載っており、i = 1, 2, \ldots, N について、i 番目のイチゴの座標は (p_i, q_i) です。 2 個以上のイチゴが同一の座標にあることはありません。

高橋君は、このケーキを包丁で下記の通りにいくつかのピースに切り分けます。

  • まず、ケーキを通る y 軸に並行な A 本の異なる直線、直線 x = a_1 、直線 x = a_2\ldots 、直線 x = a_A のそれぞれにそってケーキを切る。
  • 次に、ケーキを通る x 軸に並行な B 本の異なる直線、直線 y = b_1 、直線 y = b_2\ldots 、直線 y = b_B のそれぞれにそってケーキを切る。

その結果、ケーキは (A+1)(B+1) 個の長方形のピースに分割されます。 高橋君はそれらのうちのいずれか 1 個だけを選んで食べます。 高橋君が選んだピースに載っているイチゴの個数としてあり得る最小値と最大値をそれぞれ出力してください。

ここで、最終的にピースの縁となる位置にはイチゴが存在しないことが保証されます。 より形式的な説明は下記の制約を参照してください。

制約

  • 3 \leq W, H \leq 10^9
  • 1 \leq N \leq 2 \times 10^5
  • 0 \lt p_i \lt W
  • 0 \lt q_i \lt H
  • i \neq j \implies (p_i, q_i) \neq (p_j, q_j)
  • 1 \leq A, B \leq 2 \times 10^5
  • 0 \lt a_1 \lt a_2 \lt \cdots \lt a_A \lt W
  • 0 \lt b_1 \lt b_2 \lt \cdots \lt b_B \lt H
  • p_i \not \in \lbrace a_1, a_2, \ldots, a_A \rbrace
  • q_i \not \in \lbrace b_1, b_2, \ldots, b_B \rbrace
  • 入力はすべて整数

入力

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

W H
N
p_1 q_1
p_2 q_2
\vdots
p_N q_N
A
a_1 a_2 \ldots a_A
B
b_1 b_2 \ldots b_B

出力

高橋君が選んだピースに載っているイチゴの個数としてあり得る最小値 m と最大値 M をそれぞれ、下記の形式の通り空白区切りで出力せよ。

m M

入力例 1

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

出力例 1

0 2

9 個のピースの内訳は、イチゴが 0 個載ったものが 6 個、イチゴが 1 個載ったものが 1 個、イチゴが 2 個載ったものが 2 個です。 よって、それらのうちのいずれか 1 個だけを選んで食べるとき、選んだピースに載っているイチゴの個数としてあり得る最小値は 0 、最大値は 2 です。


入力例 2

4 4
4
1 1
3 1
3 3
1 3
1
2
1
2

出力例 2

1 1

どのピースにもイチゴが 1 個載っています。

Score : 400 points

Problem Statement

There is a rectangular cake with some strawberries on the xy-plane. The cake occupies the rectangular area \lbrace (x, y) : 0 \leq x \leq W, 0 \leq y \leq H \rbrace.

There are N strawberries on the cake, and the coordinates of the i-th strawberry are (p_i, q_i) for i = 1, 2, \ldots, N. No two strawberries have the same coordinates.

Takahashi will cut the cake into several pieces with a knife, as follows.

  • First, cut the cake along A different lines parallel to the y-axis: lines x = a_1, x = a_2, \ldots, x = a_A.
  • Next, cut the cake along B different lines parallel to the x-axis: lines y = b_1, y = b_2, \ldots, y = b_B.

As a result, the cake will be divided into (A+1)(B+1) rectangular pieces. Takahashi will choose just one of these pieces to eat. Print the minimum and maximum possible numbers of strawberries on the chosen piece.

Here, it is guaranteed that there are no strawberries along the edges of the final pieces. For a more formal description, refer to the constraints below.

Constraints

  • 3 \leq W, H \leq 10^9
  • 1 \leq N \leq 2 \times 10^5
  • 0 \lt p_i \lt W
  • 0 \lt q_i \lt H
  • i \neq j \implies (p_i, q_i) \neq (p_j, q_j)
  • 1 \leq A, B \leq 2 \times 10^5
  • 0 \lt a_1 \lt a_2 \lt \cdots \lt a_A \lt W
  • 0 \lt b_1 \lt b_2 \lt \cdots \lt b_B \lt H
  • p_i \not \in \lbrace a_1, a_2, \ldots, a_A \rbrace
  • q_i \not \in \lbrace b_1, b_2, \ldots, b_B \rbrace
  • All input values are integers.

Input

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

W H
N
p_1 q_1
p_2 q_2
\vdots
p_N q_N
A
a_1 a_2 \ldots a_A
B
b_1 b_2 \ldots b_B

Output

Print the minimum possible number of strawberries m and the maximum possible number M on the chosen piece in the following format, separated by a space.

m M

Sample Input 1

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

Sample Output 1

0 2

There are nine pieces in total: six with zero strawberries, one with one strawberry, and two with two strawberries. Therefore, when choosing just one of these pieces to eat, the minimum possible number of strawberries on the chosen piece is 0, and the maximum possible number is 2.


Sample Input 2

4 4
4
1 1
3 1
3 3
1 3
1
2
1
2

Sample Output 2

1 1

Each piece has one strawberry on it.

E - Good Graph

実行時間制限: 3 sec / メモリ制限: 1024 MB

配点 : 475

問題文

N 頂点 M 辺の無向グラフ G が与えられます。 i = 1, 2, \ldots, M について、i 番目の辺は頂点 u_i と頂点 v_i を結ぶ無向辺です。

N 頂点のグラフは、すべての i = 1, 2, \ldots, K について下記の条件が成り立つとき、良いグラフと呼ばれます。

  • G 上で頂点 x_i と頂点 y_i を結ぶパスが存在しない。

与えられるグラフ G は良いグラフです。

Q 個の独立な質問が与えられるので、それらすべてに答えてください。 i = 1, 2, \ldots, Q について、i 番目の質問は

  • 入力で与えられたグラフ G に頂点 p_i と頂点 q_i を結ぶ無向辺を 1 本追加して得られるグラフ G^{(i)} は良いグラフですか?

という質問です。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 1 \leq u_i, v_i \leq N
  • 1 \leq K \leq 2 \times 10^5
  • 1 \leq x_i, y_i \leq N
  • x_i \neq y_i
  • i \neq j \implies \lbrace x_i, y_i \rbrace \neq \lbrace x_j, y_j \rbrace
  • すべての i = 1, 2, \ldots, K について次が成り立つ:頂点 x_i と頂点 y_i を結ぶパスは存在しない。
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq p_i, q_i \leq N
  • p_i \neq q_i
  • 入力はすべて整数

入力

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

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M
K
x_1 y_1
x_2 y_2
\vdots
x_K y_K
Q
p_1 q_1
p_2 q_2
\vdots
p_Q q_Q

出力

Q 行出力せよ。 i = 1, 2, \ldots, Q について、i 行目には i 番目の質問に対する答えを出力せよ。 具体的には、グラフ G^{(i)} が良いグラフである場合は Yes を、良いグラフでない場合は No を出力せよ。


入力例 1

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

出力例 1

No
No
Yes
Yes
  • 1 番目の質問に関して、グラフ G^{(1)} は良いグラフではありません。なぜなら、頂点 x_1 = 1 と頂点 y_1 = 5 を結ぶパス 1 \rightarrow 2 \rightarrow 5 を持つからです。よって、No と出力します。
  • 2 番目の質問に関して、グラフ G^{(2)} は良いグラフではありません。なぜなら、頂点 x_2 = 2 と頂点 y_2 = 6 を結ぶパス 2 \rightarrow 6 を持つからです。よって、No と出力します。
  • 3 番目の質問に関して、グラフ G^{(3)} は良いグラフです。よって、Yes と出力します。
  • 4 番目の質問に関して、グラフ G^{(4)} は良いグラフです。よって、Yes と出力します。

この入力例のように、与えられるグラフ G が自己ループや多重辺を持つ場合があることに注意してください。

Score : 475 points

Problem Statement

You are given an undirected graph G with N vertices and M edges. For i = 1, 2, \ldots, M, the i-th edge is an undirected edge connecting vertices u_i and v_i.

A graph with N vertices is called good if the following condition holds for all i = 1, 2, \ldots, K:

  • there is no path connecting vertices x_i and y_i in G.

The given graph G is good.

You are given Q independent questions. Answer all of them. For i = 1, 2, \ldots, Q, the i-th question is as follows.

  • Is the graph G^{(i)} obtained by adding an undirected edge connecting vertices p_i and q_i to the given graph G good?

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq 2 \times10^5
  • 1 \leq u_i, v_i \leq N
  • 1 \leq K \leq 2 \times 10^5
  • 1 \leq x_i, y_i \leq N
  • x_i \neq y_i
  • i \neq j \implies \lbrace x_i, y_i \rbrace \neq \lbrace x_j, y_j \rbrace
  • For all i = 1, 2, \ldots, K, there is no path connecting vertices x_i and y_i.
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq p_i, q_i \leq N
  • p_i \neq q_i
  • 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
K
x_1 y_1
x_2 y_2
\vdots
x_K y_K
Q
p_1 q_1
p_2 q_2
\vdots
p_Q q_Q

Output

Print Q lines. For i = 1, 2, \ldots, Q, the i-th line should contain the answer to the i-th question: Yes if the graph G^{(i)} is good, and No otherwise.


Sample Input 1

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

Sample Output 1

No
No
Yes
Yes
  • For the first question, the graph G^{(1)} is not good because it has a path 1 \rightarrow 2 \rightarrow 5 connecting vertices x_1 = 1 and y_1 = 5. Therefore, print No.
  • For the second question, the graph G^{(2)} is not good because it has a path 2 \rightarrow 6 connecting vertices x_2 = 2 and y_2 = 6. Therefore, print No.
  • For the third question, the graph G^{(3)} is good. Therefore, print Yes.
  • For the fourth question, the graph G^{(4)} is good. Therefore, print Yes.

As seen in this sample input, note that the given graph G may have self-loops or multi-edges.

F - Shift Table

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

配点 : 525

問題文

高橋君と青木君は、これから N 日間アルバイトをします。
高橋君のシフト表は文字列 S により与えられ、Si 文字目が # のとき i 日目に出勤、. のとき i 日目に欠勤します。
これをもとに、青木君は以下のようにシフト表を作りました。

  • まず、N でない N の正の約数 M をとる。
  • 次に、1 日目から M 日目までの勤怠を決める。
  • 最後に、i = 1, 2, \ldots, N - M の順に M + i 日目の勤怠が i 日目の勤怠と一致するように M + i 日目の勤怠を決める。

ここで、M の値が異なる場合でも最終的にできたシフトが同じものとなることがあることに注意してください。

N 日すべてについて高橋君と青木君の少なくとも一方が出勤することになったとき、青木君のシフト表として考えられるものの個数を 998244353 で割った余りを求めてください。

制約

  • N2 以上 10^5 以下の整数
  • S は 長さ N#. からなる文字列

入力

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

N
S

出力

答えを出力せよ。


入力例 1

6
##.#.#

出力例 1

3

高橋君は 1 \cdot 2 \cdot 4 \cdot 6 日目に出勤します。
青木君のシフト表を表す文字列を T とし、青木君は Ti 文字目が # のとき i 日目に出勤、. のとき i 日目に欠勤するとします。
T としてあり得るものは ###### \cdot #.#.#. \cdot .##.##3 つです。

1 つめのシフト表は M1 または 2 または 32 つめのシフト表は M = 23 つめのシフト表は M = 3 とすることにより実現できます。


入力例 2

7
...####

出力例 2

1

入力例 3

12
####.####.##

出力例 3

19

Score : 525 points

Problem Statement

Takahashi and Aoki will work part-time for the next N days.
Takahashi's shift schedule is given by the string S, where the i-th character of S is # if he works on the i-th day, and . if he is absent on the i-th day.
Based on this, Aoki created his shift schedule as follows.

  • First, take a positive divisor M of N that is not equal to N.
  • Next, decide the attendance for the first M days.
  • Finally, for i = 1, 2, \ldots, N - M in this order, decide the attendance for the (M + i)-th day so that it matches the attendance for the i-th day.

Note that different values of M may lead to the same final shift schedule.

Find the number of possible shift schedules for Aoki such that at least one of Takahashi and Aoki works on each of the N days, modulo 998244353.

Constraints

  • N is an integer between 2 and 10^5, inclusive.
  • S is a string of length N consisting of # and ..

Input

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

N
S

Output

Print the answer.


Sample Input 1

6
##.#.#

Sample Output 1

3

Takahashi works on days 1, 2, 4, and 6.
Let T be the string representing Aoki's shift schedule, where the i-th character of T is # if he works on the i-th day, and . if he is absent on the i-th day.
There are three possible strings for T: ######, #.#.#., and .##.##.

The first shift schedule can be realized by choosing M = 1 or 2 or 3, the second by choosing M = 2, and the third by choosing M = 3.


Sample Input 2

7
...####

Sample Output 2

1

Sample Input 3

12
####.####.##

Sample Output 3

19
G - Max of Medians

実行時間制限: 5 sec / メモリ制限: 1024 MB

配点 : 625

問題文

長さ 2N の数列 A = (A_1, A_2, \ldots, A_{2N}) が与えられます。

数列 A の要素を並べ替えることによって長さ N の数列 (A_1 \oplus A_2, A_3 \oplus A_4, \ldots, A_{2N-1} \oplus A_{2N}) の中央値として得ることのできる最大の値を求めてください。

ここで、\oplus はビットごとの排他的論理和を表します。

ビットごとの排他的論理和とは? 非負整数 A, B のビットごとの排他的論理和 A \oplus B は、以下のように定義されます。
  • A \oplus B を二進表記した際の 2^k (k \geq 0) の位の数は、A, B を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1、そうでなければ 0 である。
例えば、3 \oplus 5 = 6 となります (二進表記すると: 011 \oplus 101 = 110)。

また、長さ L の数列 B に対して B の中央値とは、B を昇順にソートして得られる数列を B' として B'\lfloor \frac{L}{2} \rfloor + 1 番目の値のことを指します。

制約

  • 1 \leq N \leq 10^5
  • 0 \leq A_i < 2^{30}
  • 入力はすべて整数

入力

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

N
A_1 A_2 \ldots A_{2N}

出力

答えを出力せよ。


入力例 1

4
4 0 0 11 2 7 9 5

出力例 1

14

A(5, 0, 9, 7, 11, 4, 0, 2) と並べ替えると、(A_1 \oplus A_2, A_3 \oplus A_4, A_5 \oplus A_6, A_7 \oplus A_8) = (5, 14, 15, 2) となり、この数列の中央値は 14 です。
(A_1 \oplus A_2, A_3 \oplus A_4, A_5 \oplus A_6, A_7 \oplus A_8) の中央値が 15 以上となるように A を並べ替えることは不可能であるため、14 を出力します。


入力例 2

1
998244353 1000000007

出力例 2

1755654

入力例 3

5
1 2 4 8 16 32 64 128 256 512

出力例 3

192

Score : 625 points

Problem Statement

You are given a sequence of length 2N: A = (A_1, A_2, \ldots, A_{2N}).

Find the maximum value that can be obtained as the median of the length-N sequence (A_1 \oplus A_2, A_3 \oplus A_4, \ldots, A_{2N-1} \oplus A_{2N}) by rearranging the elements of the sequence A.

Here, \oplus represents bitwise exclusive OR.

What is bitwise exclusive OR? The bitwise exclusive OR of non-negative integers A and B, denoted as A \oplus B, is defined as follows:
  • The number at the 2^k position (k \geq 0) in the binary representation of A \oplus B is 1 if and only if exactly one of the numbers at the 2^k position in the binary representation of A and B is 1, and it is 0 otherwise.
For example, 3 \oplus 5 = 6 (in binary notation: 011 \oplus 101 = 110).

Also, for a sequence B of length L, the median of B is the value at the \lfloor \frac{L}{2} \rfloor + 1-th position of the sequence B' obtained by sorting B in ascending order.

Constraints

  • 1 \leq N \leq 10^5
  • 0 \leq A_i < 2^{30}
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_{2N}

Output

Print the answer.


Sample Input 1

4
4 0 0 11 2 7 9 5

Sample Output 1

14

By rearranging A as (5, 0, 9, 7, 11, 4, 0, 2), we get (A_1 \oplus A_2, A_3 \oplus A_4, A_5 \oplus A_6, A_7 \oplus A_8) = (5, 14, 15, 2), and the median of this sequence is 14.
It is impossible to rearrange A so that the median of (A_1 \oplus A_2, A_3 \oplus A_4, A_5 \oplus A_6, A_7 \oplus A_8) is 15 or greater, so we print 14.


Sample Input 2

1
998244353 1000000007

Sample Output 2

1755654

Sample Input 3

5
1 2 4 8 16 32 64 128 256 512

Sample Output 3

192
Ex - Constrained Topological Sort

実行時間制限: 3 sec / メモリ制限: 1024 MB

配点 : 625

問題文

N 頂点 M 辺の有向グラフが与えられます。 i = 1, 2, \ldots, M について、i 番目の辺は頂点 s_i から頂点 t_i への有向辺です。

(1, 2, \ldots, N) の順列 P = (P_1, P_2, \ldots, P_N) であって下記の 2 つの条件をともに満たすものが存在するかを判定し、存在する場合はその一例を示してください。

  • すべての i = 1, 2, \ldots, M について、P_{s_i} \lt P_{t_i}
  • すべての i = 1, 2, \ldots, N について、L_i \leq P_i \leq R_i

制約

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq \min\lbrace 4 \times 10^5, N(N-1) \rbrace
  • 1 \leq s_i, t_i \leq N
  • s_i \neq t_i
  • i \neq j \implies (s_i, t_i) \neq (s_j, t_j)
  • 1 \leq L_i \leq R_i \leq N
  • 入力はすべて整数

入力

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

N M
s_1 t_1
s_2 t_2
\vdots
s_M t_M
L_1 R_1
L_2 R_2
\vdots
L_N R_N

出力

条件を満たす P が存在しない場合は、No と出力せよ。存在する場合は、下記の形式の通り、1 行目に Yes と出力し、 2 行目に P の各要素を空白区切りで出力せよ。 条件を満たす P が複数存在する場合は、そのうちのどれを出力しても正解となる。

Yes
P_1 P_2 \ldots P_N

入力例 1

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

出力例 1

Yes
3 1 4 2 5

P = (3, 1, 4, 2, 5) が条件を満たします。実際、

  • 1 番目の辺 (s_1, t_1) = (1, 5) について、P_1 = 3 \lt 5 = P_5
  • 2 番目の辺 (s_2, t_2) = (2, 1) について、P_2 = 1 \lt 3 = P_1
  • 3 番目の辺 (s_3, t_3) = (2, 5) について、P_2 = 1 \lt 5 = P_5
  • 4 番目の辺 (s_4, t_4) = (4, 3) について、P_4 = 2 \lt 4 = P_3

が成り立ちます。また、

  • L_1 = 1 \leq P_1 = 3 \leq R_1 = 5
  • L_2 = 1 \leq P_2 = 1 \leq R_2 = 3
  • L_3 = 3 \leq P_3 = 4 \leq R_3 = 4
  • L_4 = 1 \leq P_4 = 2 \leq R_4 = 3
  • L_5 = 4 \leq P_5 = 5 \leq R_5 = 5

も成り立ちます。


入力例 2

2 2
1 2
2 1
1 2
1 2

出力例 2

No

条件を満たす P が存在しないので、No を出力します。

Score : 625 points

Problem Statement

You are given a directed graph with N vertices and M edges. For i = 1, 2, \ldots, M, the i-th edge is directed from vertex s_i to vertex t_i.

Determine whether there is a permutation P = (P_1, P_2, \ldots, P_N) of (1, 2, \ldots, N) that satisfies both of the following conditions, and if there is, provide an example.

  • P_{s_i} \lt P_{t_i} for all i = 1, 2, \ldots, M.
  • L_i \leq P_i \leq R_i for all i = 1, 2, \ldots, N.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq M \leq \min\lbrace 4 \times 10^5, N(N-1) \rbrace
  • 1 \leq s_i, t_i \leq N
  • s_i \neq t_i
  • i \neq j \implies (s_i, t_i) \neq (s_j, t_j)
  • 1 \leq L_i \leq R_i \leq N
  • All input values are integers.

Input

The 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
L_1 R_1
L_2 R_2
\vdots
L_N R_N

Output

If there is no P that satisfies the conditions, print No. If there is a P that satisfies the conditions, print Yes in the first line, and the elements of P separated by spaces in the second line, in the following format. If multiple P's satisfy the conditions, any of them will be accepted.

Yes
P_1 P_2 \ldots P_N

Sample Input 1

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

Sample Output 1

Yes
3 1 4 2 5

P = (3, 1, 4, 2, 5) satisfies the conditions. In fact,

  • for the first edge (s_1, t_1) = (1, 5), we have P_1 = 3 \lt 5 = P_5;
  • for the second edge (s_2, t_2) = (2, 1), we have P_2 = 1 \lt 3 = P_1;
  • for the third edge (s_3, t_3) = (2, 5), we have P_2 = 1 \lt 5 = P_5;
  • for the fourth edge (s_4, t_4) = (4, 3), we have P_4 = 2 \lt 4 = P_3.

Also,

  • L_1 = 1 \leq P_1 = 3 \leq R_1 = 5,
  • L_2 = 1 \leq P_2 = 1 \leq R_2 = 3,
  • L_3 = 3 \leq P_3 = 4 \leq R_3 = 4,
  • L_4 = 1 \leq P_4 = 2 \leq R_4 = 3,
  • L_5 = 4 \leq P_5 = 5 \leq R_5 = 5.

Sample Input 2

2 2
1 2
2 1
1 2
1 2

Sample Output 2

No

No P satisfies the conditions, so print No.