A - 1-2-4 Test

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

3 問の問題からなる試験があり、それぞれの問題の配点は 1 点、2 点、4 点でした。

高橋君、青木君、すぬけ君の 3 人がこの試験を受け、 高橋君は A 点、青木君は B 点を取りました。

すぬけ君は、高橋君と青木君のうち少なくとも一方が解けた問題は解け、 2 人とも解けなかった問題は解けませんでした。

すぬけ君の点数を求めてください。

ただし、この問題の制約下で、すぬけ君の点数は一意に定まる事が証明できます。

制約

  • 0\leq A,B \leq 7
  • A,B は整数

入力

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

A B

出力

すぬけ君の点数を整数で出力せよ。


入力例 1

1 2

出力例 1

3

高橋君は 1 点を取った事から、 1 点の問題のみを正解し、それ以外の 2 問は解けなかったことがわかります。
同様に、青木君は 2 点を取った事から、 2 点の問題のみを正解し、それ以外の 2 問は解けなかったことがわかります。

よって、すぬけ君は 1 点の問題と 2 点の問題を正解し、高橋君と青木君がともに解けなかった 4 点の問題はすぬけ君も解けなかったことになるので、3 点を取ったことがわかります。よって、3 を出力します。


入力例 2

5 3

出力例 2

7

高橋君は 5 点を取った事から、 1 点の問題と 4 点の問題を正解し、 2 点の問題は解けなかったことがわかります。
同様に、青木君は 3 点を取った事から、 1 点の問題と 2 点の問題を正解し、 4 点の問題は解けなかったことがわかります。

よって、3 問すべてについて、高橋君と青木君の少なくとも一方が正解しているため、すぬけ君はすベての問題に正解し、7 点を取ったことがわかります。 よって、7 を出力します。


入力例 3

0 0

出力例 3

0

高橋君と青木君は 2 人ともいずれの問題も解けていません。 よって、すぬけ君もいずれの問題も解けておらず、 0 を出力します。

Score : 100 points

Problem Statement

There was an exam consisting of three problems worth 1, 2, and 4 points.

Takahashi, Aoki, and Snuke took this exam. Takahashi scored A points, and Aoki scored B points.

Snuke solved all of the problems solved by at least one of Takahashi and Aoki, and failed to solve any of the problems solved by neither of them.

Find Snuke's score.

It can be proved that Snuke's score is uniquely determined under the Constraints of this problem.

Constraints

  • 0\leq A,B \leq 7
  • A and B are integers.

Input

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

A B

Output

Print Snuke's score as an integer.


Sample Input 1

1 2

Sample Output 1

3

Since Takahashi scored 1 point, we see that he solved only the 1-point problem and failed to solve the other two.
Similarly, since Aoki scored 2 points, we see that he solved only the 2-point problem and failed to solve the other two.

Therefore, Snuke must have solved the 1- and 2-point problems, but not the 4-point one, which Takahashi and Aoki both failed to solve, for a score of 3 points. Thus, 3 should be printed.


Sample Input 2

5 3

Sample Output 2

7

Since Takahashi scored 5 points, we see that he solved the 1- and 4-point problems but not the 2-point one.
Similarly, since Aoki scored 3 points, we see that he solved the 1- and 2-point problems but not the 4-point one.

Therefore, each of the three problems is solved by at least one of Takahashi and Aoki, so we see that Snuke solved all of the problems, for a score of 7 points. Thus, 7 should be printed.


Sample Input 3

0 0

Sample Output 3

0

Both Takahashi and Aoki solved none of the problems. Therefore, so did Snuke. Thus, 0 should be printed.

B - When?

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

AtCoder Beginner Contest は通常、日本標準時で 21 時ちょうどに始まり 100 分間にわたって行われます。

0 以上 100 以下の整数 K が与えられます。21 時ちょうどから K 分後の時刻を HH:MM の形式で出力してください。ただし、HH24 時間制での時間を、MM は分を表します。時間または分が 1 桁のときは、先頭に 0 を追加して 2 桁の整数として表してください。

制約

  • K0 以上 100 以下の整数

入力

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

K

出力

21 時ちょうどから K 分後の時刻を問題文中の形式に従って出力せよ。


入力例 1

63

出力例 1

22:03

21 時ちょうどから 63 分後の時刻は 223 分なので、22:03 と出力します。

以下のような出力は不正解となります。

  • 10:03
  • 22:3

入力例 2

45

出力例 2

21:45

入力例 3

100

出力例 3

22:40

Score : 100 points

Problem Statement

AtCoder Beginner Contest usually starts at 21:00 JST and lasts for 100 minutes.

You are given an integer K between 0 and 100 (inclusive). Print the time K minutes after 21:00 in the HH:MM format, where HH denotes the hour on the 24-hour clock and MM denotes the minute. If the hour or the minute has just one digit, append a 0 to the beginning to represent it as a 2-digit integer.

Constraints

  • K is an integer between 0 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

K

Output

Print the time K minutes after 21:00 in the format specified in the Problem Statement.


Sample Input 1

63

Sample Output 1

22:03

63 minutes after 21:00, it will be 22:03, so 22:03 should be printed.

The following outputs would be judged incorrect:

  • 10:03
  • 22:3

Sample Input 2

45

Sample Output 2

21:45

Sample Input 3

100

Sample Output 3

22:40
C - Modulo Number

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

-10^{18} 以上 10^{18} 以下の整数 N が与えられます。

以下の条件を満たす 0 以上 998244353 未満の整数 x を求めてください。なお、答えが一意に定まることが証明できます。

  • N-x998244353 の倍数

制約

  • N-10^{18} 以上 10^{18} 以下の整数

入力

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

N

出力

答えを出力せよ。


入力例 1

998244354

出力例 1

1

998244354-1 = 998244353998244353 の倍数なので条件を満たします。


入力例 2

-9982443534

出力例 2

998244349

-9982443534-998244349= -10980687883998244353 の倍数なので条件を満たします。

Score : 200 points

Problem Statement

You are given an integer N between -10^{18} and 10^{18} (inclusive).

Find an integer x between 0 and 998244353 - 1 (inclusive) that satisfies the following condition. It can be proved that such an integer is unique.

  • N-x is a multiple of 998244353.

Constraints

  • N is an integer between -10^{18} and 10^{18} (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

998244354

Sample Output 1

1

998244354-1 = 998244353 is a multiple of 998244353, so the condition is satisfied.


Sample Input 2

-9982443534

Sample Output 2

998244349

-9982443534-998244349= -10980687883 is a multiple of 998244353, so the condition is satisfied.

D - Piano

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

無限に長いピアノの鍵盤があります。 この鍵盤内の連続する区間であって、白鍵 W 個と黒鍵 B 個からなるものは存在しますか?

文字列 wbwbwwbwbwbw を無限に繰り返してできる文字列を S とおきます。

S の部分文字列であって、W 個の wB 個の b からなるものは存在しますか?

S の部分文字列とは S の部分文字列とは、ある 2 つの正整数 l,r\ (l\leq r) に対して、Sl 文字目、l+1 文字目、\dotsr 文字目をこの順に繋げてできる文字列のことをいいます。

制約

  • W,B は整数
  • 0\leq W,B \leq 100
  • W+B \geq 1

入力

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

W B

出力

S の部分文字列であって、W 個の wB 個の b からなるものが存在するならば Yes を、存在しないならば No を出力せよ。


入力例 1

3 2

出力例 1

Yes

S の最初の 15 文字は wbwbwwbwbwbwwbw であり、S11 文字目から 15 文字目までを取り出してできる文字列 bwwbw3 個の w2 個の b からなる部分文字列の一例です。


入力例 2

3 0

出力例 2

No

3 個の w0 個の b からなる文字列は www のみですが、これは S の部分文字列ではありません。


入力例 3

92 66

出力例 3

Yes

Score: 200 points

Problem Statement

There is an infinitely long piano keyboard. Is there a continuous segment within this keyboard that consists of W white keys and B black keys?

Let S be the string formed by infinitely repeating the string wbwbwwbwbwbw.

Is there a substring of S that consists of W occurrences of w and B occurrences of b?

What is a substring of S? A substring of S is a string that can be formed by concatenating the l-th, (l+1)-th, \dots, r-th characters of S in this order for some two positive integers l and r (l\leq r).

Constraints

  • W and B are integers.
  • 0\leq W,B \leq 100
  • W+B \geq 1

Input

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

W B

Output

If there is a substring of S that consists of W occurrences of w and B occurrences of b, print Yes; otherwise, print No.


Sample Input 1

3 2

Sample Output 1

Yes

The first 15 characters of S are wbwbwwbwbwbwwbw. You can take the 11-th through 15-th characters to form the string bwwbw, which is a substring consisting of three occurrences of w and two occurrences of b.


Sample Input 2

3 0

Sample Output 2

No

The only string consisting of three occurrences of w and zero occurrences of b is www, which is not a substring of S.


Sample Input 3

92 66

Sample Output 3

Yes
E - Approximate Equalization 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

整数列 A=(A_1,A_2,\dots,A_N) があります。 あなたは次の操作を好きな回数(0 回でもよい)行うことができます。

  • 1\leq i,j \leq N を満たす整数 i,j を選ぶ。A_i1 減らし、A_j1 増やす。

A の最小値と最大値の差を 1 以下にするために必要な最小の操作回数を求めてください。

制約

  • 1\leq N \leq 2\times 10^5
  • 1\leq A_i \leq 10^9
  • 入力は全て整数

入力

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

N
A_1 A_2 \dots A_N

出力

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


入力例 1

4
4 7 3 7

出力例 1

3

以下のように 3 回の操作を行うことで、A の最小値と最大値の差を 1 以下にすることができます。

  • i=2,j=3 として操作を行う。A=(4,6,4,7) になる。
  • i=4,j=1 として操作を行う。A=(5,6,4,6) になる。
  • i=4,j=3 として操作を行う。A=(5,6,5,5) になる。

3 回未満の操作で A の最小値と最大値の差を 1 以下にすることはできません。よって答えは 3 です。


入力例 2

1
313

出力例 2

0

入力例 3

10
999999997 999999999 4 3 2 4 999999990 8 999999991 999999993

出力例 3

2499999974

Score : 400 points

Problem Statement

You are given an integer sequence A=(A_1,A_2,\dots,A_N). You can perform the following operation any number of times (possibly zero).

  • Choose integers i and j with 1\leq i,j \leq N. Decrease A_i by one and increase A_j by one.

Find the minimum number of operations required to make the difference between the minimum and maximum values of A at most one.

Constraints

  • 1\leq N \leq 2\times 10^5
  • 1\leq A_i \leq 10^9
  • All input values are integers.

Input

The 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
4 7 3 7

Sample Output 1

3

By the following three operations, the difference between the minimum and maximum values of A becomes at most one.

  • Choose i=2 and j=3 to make A=(4,6,4,7).
  • Choose i=4 and j=1 to make A=(5,6,4,6).
  • Choose i=4 and j=3 to make A=(5,6,5,5).

You cannot make the difference between maximum and minimum values of A at most one by less than three operations, so the answer is 3.


Sample Input 2

1
313

Sample Output 2

0

Sample Input 3

10
999999997 999999999 4 3 2 4 999999990 8 999999991 999999993

Sample Output 3

2499999974
F - Neo-lexicographic Ordering

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

AtCoder 王国を治める高橋君は、英小文字のアルファベット順を変更することにしました。

新たなアルファベット順はa , b , \ldots, z を並べ替えて得られる文字列 X を用いて表されます。Xi \, (1 \leq i \leq 26) 文字目は、新たな順番において i 番目に小さい英小文字を表します。

AtCoder 王国には N 人の国民がおり、それぞれの国民の名前は S_1, S_2, \dots, S_N です。ここで、S_i \, (1 \leq i \leq N) は英小文字からなります。
これらの名前を、高橋君の定めたアルファベット順に基づく辞書順に従って並べ替えてください。

辞書順とは?

辞書順とは簡単に説明すると「単語が辞書に載っている順番」を意味します。より厳密な説明として、英小文字からなる相異なる文字列 S, T の大小を判定するアルゴリズムを以下に説明します。

以下では「 Si 文字目の文字」を S_i のように表します。また、 ST より辞書順で小さい場合は S \lt T 、大きい場合は S \gt T と表します。

  1. S, T のうち長さが大きくない方の文字列の長さを L とします。i=1,2,\dots,L に対して S_iT_i が一致するか調べます。
  2. S_i \neq T_i である i が存在する場合、そのような i のうち最小のものを j とします。そして、S_jT_j を比較して、S_jT_j よりアルファベット順で小さい場合は S \lt T 、そうでない場合は S \gt T と決定して、アルゴリズムを終了します。
  3. S_i \neq T_i である i が存在しない場合、ST の長さを比較して、ST より短い場合は S \lt T 、長い場合は S \gt T と決定して、アルゴリズムを終了します。

制約

  • Xa , b , \ldots, z を並べ替えて得られる
  • 2 \leq N \leq 50000
  • N は整数
  • 1 \leq |S_i| \leq 10 \, (1 \leq i \leq N)
  • S_i は英小文字からなる (1 \leq i \leq N)
  • S_i \neq S_j (1 \leq i \lt j \leq N)

入力

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

X
N
S_1
S_2
\vdots
S_N

出力

N 行出力せよ。i \, (1 \leq i \leq N) 行目には、高橋君の定めたアルファベット順に基づく辞書順に従って国民の名前を並べ替えたとき、i 番目に小さいものを出力すること。


入力例 1

bacdefghijklmnopqrstuvwxzy
4
abx
bzz
bzy
caa

出力例 1

bzz
bzy
abx
caa

高橋君が新たに設定したアルファベット順において、ba より小さく、zy より小さいです。そのため、国民の名前を辞書順に並べ替えると、小さい順に bzz , bzy , abx , caa となります。


入力例 2

zyxwvutsrqponmlkjihgfedcba
5
a
ab
abc
ac
b

出力例 2

b
a
ac
ab
abc

Score : 300 points

Problem Statement

Takahashi, who governs the Kingdom of AtCoder, has decided to change the alphabetical order of English lowercase letters.

The new alphabetical order is represented by a string X, which is a permutation of a, b, \ldots, z. The i-th character of X (1 \leq i \leq 26) would be the i-th smallest English lowercase letter in the new order.

The kingdom has N citizens, whose names are S_1, S_2, \dots, S_N, where each S_i (1 \leq i \leq N) consists of lowercase English letters.
Sort these names lexicographically according to the alphabetical order decided by Takahashi.

What is the lexicographical order?

Simply speaking, the lexicographical order is the order in which words are listed in a dictionary. As a more formal definition, here is the algorithm to determine the lexicographical order between different strings S and T.

Below, let S_i denote the i-th character of S. Also, if S is lexicographically smaller than T, we will denote that fact as S \lt T; if S is lexicographically larger than T, we will denote that fact as S \gt T.

  1. Let L be the smaller of the lengths of S and T. For each i=1,2,\dots,L, we check whether S_i and T_i are the same.
  2. If there is an i such that S_i \neq T_i, let j be the smallest such i. Then, we compare S_j and T_j. If S_j comes earlier than T_j in alphabetical order, we determine that S \lt T and quit; if S_j comes later than T_j, we determine that S \gt T and quit.
  3. If there is no i such that S_i \neq T_i, we compare the lengths of S and T. If S is shorter than T, we determine that S \lt T and quit; if S is longer than T, we determine that S \gt T and quit.

Constraints

  • X is a permutation of a, b, \ldots, z.
  • 2 \leq N \leq 50000
  • N is an integer.
  • 1 \leq |S_i| \leq 10 \, (1 \leq i \leq N)
  • S_i consists of lowercase English letters. (1 \leq i \leq N)
  • S_i \neq S_j (1 \leq i \lt j \leq N)

Input

Input is given from Standard Input in the following format:

X
N
S_1
S_2
\vdots
S_N

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain the i-th smallest name when the citizens' names are sorted according to the alphabetical order decided by Takahashi.


Sample Input 1

bacdefghijklmnopqrstuvwxzy
4
abx
bzz
bzy
caa

Sample Output 1

bzz
bzy
abx
caa

In the new alphabetical order set by Takahashi, b is smaller than a and z is smaller than y. Thus, sorting the citizens' names lexicographically would result in bzz, bzy, abx, caa in ascending order.


Sample Input 2

zyxwvutsrqponmlkjihgfedcba
5
a
ab
abc
ac
b

Sample Output 2

b
a
ac
ab
abc
G - Impartial Gift

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

高橋君は青木君とすぬけ君に 1 つずつ贈り物を送ることにしました。
青木君への贈り物の候補は N 個あり、 それぞれの価値は A_1, A_2, \ldots,A_N です。
すぬけ君への贈り物の候補は M 個あり、 それぞれの価値は B_1, B_2, \ldots,B_M です。

高橋君は 2 人への贈り物の価値の差が D 以下になるようにしたいと考えています。

条件をみたすように贈り物を選ぶことが可能か判定し、可能な場合はそのような選び方における贈り物の価値の和の最大値を求めてください。

制約

  • 1\leq N,M\leq 2\times 10^5
  • 1\leq A_i,B_i\leq 10^{18}
  • 0\leq D \leq 10^{18}
  • 入力はすべて整数

入力

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

N M D
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

出力

高橋君が条件をみたすように贈り物を選ぶことができる場合、 条件をみたし、かつ価値の和が最大になるように贈り物を選んだ時の価値の和を出力せよ。 高橋君が条件をみたすように選ぶことができない場合、-1 を出力せよ。


入力例 1

2 3 2
3 10
2 5 15

出力例 1

8

高橋君は贈り物の価値の差を 2 以下にする必要があります。
青木君に価値 3, すぬけ君に価値 5 の贈り物を渡すと条件をみたし、価値の和としてはこのときが最大となります。
よって、3+5=8 を出力します。


入力例 2

3 3 0
1 3 3
6 2 7

出力例 2

-1

条件をみたすように贈り物を選ぶことは不可能です。 また、同一人物に対して、同じ価値の贈り物が複数存在することもあります。


入力例 3

1 1 1000000000000000000
1000000000000000000
1000000000000000000

出力例 3

2000000000000000000

答えが 32 bit整数型の範囲に収まらないことがあることに注意してください。


入力例 4

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

出力例 4

14

Score : 400 points

Problem Statement

Takahashi has decided to give one gift to Aoki and one gift to Snuke.
There are N candidates of gifts for Aoki, and their values are A_1, A_2, \ldots,A_N.
There are M candidates of gifts for Snuke, and their values are B_1, B_2, \ldots,B_M.

Takahashi wants to choose gifts so that the difference in values of the two gifts is at most D.

Determine if he can choose such a pair of gifts. If he can, print the maximum sum of values of the chosen gifts.

Constraints

  • 1\leq N,M\leq 2\times 10^5
  • 1\leq A_i,B_i\leq 10^{18}
  • 0\leq D \leq 10^{18}
  • All values in the input are integers.

Input

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

N M D
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

If he can choose gifts to satisfy the condition, print the maximum sum of values of the chosen gifts. If he cannot satisfy the condition, print -1.


Sample Input 1

2 3 2
3 10
2 5 15

Sample Output 1

8

The difference of values of the two gifts should be at most 2.
If he gives a gift with value 3 to Aoki and another with value 5 to Snuke, the condition is satisfied, achieving the maximum possible sum of values.
Thus, 3+5=8 should be printed.


Sample Input 2

3 3 0
1 3 3
6 2 7

Sample Output 2

-1

He cannot choose gifts to satisfy the condition. Note that the candidates of gifts for a person may contain multiple gifts with the same value.


Sample Input 3

1 1 1000000000000000000
1000000000000000000
1000000000000000000

Sample Output 3

2000000000000000000

Note that the answer may not fit into a 32-bit integer type.


Sample Input 4

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

Sample Output 4

14
H - Blackout 2

Time Limit: 3 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

ある国には N 個の都市と M 個の発電所があります。これらを総称して地点と呼びます。
地点には 1,2,\dots,N+M の番号がつけられており、そのうち都市は地点 1,2,\dots,N で発電所は地点 N+1,N+2,\dots,N+M です。

この国には電線が E 本あり、電線 i ( 1 \le i \le E ) は地点 U_i と地点 V_i を双方向に結びます。
また、ある都市に 電気が通っている とは、ある都市から電線をいくつか辿って少なくともひとつの発電所に辿り着くことができる状態を言います。

今、 Q 個のイベントが起こります。そのうち i ( 1 \le i \le Q ) 番目のイベントでは電線 X_i が切れ、その電線を辿ることができなくなります。一度切れた電線は、その後のイベントにおいても切れたままです。

全てのイベントについて、そのイベントが終わった直後に電気が通っている都市の数を求めてください。

制約

  • 入力は全て整数
  • 1 \le N,M
  • N+M \le 2 \times 10^5
  • 1 \le Q \le E \le 5 \times 10^5
  • 1 \le U_i < V_i \le N+M
  • i \neq j ならば、 U_i \neq U_j または V_i \neq V_j
  • 1 \le X_i \le E
  • X_i は相異なる

入力

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

N M E
U_1 V_1
U_2 V_2
\vdots
U_E V_E
Q
X_1
X_2
\vdots
X_Q

出力

Q 行出力せよ。
そのうち i ( 1 \le i \le Q ) 行目には i 番目のイベントが終わった直後に電気が通っている都市の数を出力せよ。


入力例 1

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

出力例 1

4
4
2
2
2
1

はじめ、全ての都市に電気が通っています。

  • 1 番目のイベントによって地点 5 と地点 10 を結ぶ電線 3 が切れます。
    • これにより、都市 5 に電気が通らなくなり、電気が通っている都市の数は 4 となります。
  • 2 番目のイベントによって地点 2 と地点 9 を結ぶ電線 5 が切れます。
  • 3 番目のイベントによって地点 3 と地点 6 を結ぶ電線 8 が切れます。
    • これにより、都市 2,3 に電気が通らなくなり、電気が通っている都市の数は 2 となります。
  • 4 番目のイベントによって地点 1 と地点 8 を結ぶ電線 10 が切れます。
  • 5 番目のイベントによって地点 4 と地点 10 を結ぶ電線 2 が切れます。
  • 6 番目のイベントによって地点 1 と地点 7 を結ぶ電線 7 が切れます。
    • これにより、都市 1 に電気が通らなくなり、電気が通っている都市の数は 1 となります。

Score : 500 points

Problem Statement

A country has N cities and M power plants, which we collectively call places.
The places are numbered 1,2,\dots,N+M, among which Places 1,2,\dots,N are the cities and Places N+1,N+2,\dots,N+M are the power plants.

This country has E power lines. Power Line i (1 \le i \le E) connects Place U_i and Place V_i bidirectionally.
A city is said to be electrified if one can reach at least one of the power plants from the city using some power lines.

Now, Q events will happen. In the i-th (1 \le i \le Q) event, Power Line X_i breaks, making it unusable. Once a power line breaks, it remains broken in the succeeding events.

Find the number of electrified cities right after each events.

Constraints

  • All values in input are integers.
  • 1 \le N,M
  • N+M \le 2 \times 10^5
  • 1 \le Q \le E \le 5 \times 10^5
  • 1 \le U_i < V_i \le N+M
  • If i \neq j, then U_i \neq U_j or V_i \neq V_j.
  • 1 \le X_i \le E
  • X_i are distinct.

Input

Input is given from Standard Input in the following format:

N M E
U_1 V_1
U_2 V_2
\vdots
U_E V_E
Q
X_1
X_2
\vdots
X_Q

Output

Print Q lines.
The i-th line should contain the number of electrified cities right after the i-th event.


Sample Input 1

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

Sample Output 1

4
4
2
2
2
1

Initially, all cities are electrified.

  • The 1-st event breaks Power Line 3 that connects Point 5 and Point 10.
    • Now City 5 is no longer electrified, while 4 cities remain electrified.
  • The 2-nd event breaks Power Line 5 that connects Point 2 and Point 9.
  • The 3-rd event breaks Power Line 8 that connects Point 3 and Point 6.
    • Now Cities 2 and 3 are no longer electrified, while 2 cities remain electrified.
  • The 4-th event breaks Power Line 10 that connects Point 1 and Point 8.
  • The 5-th event breaks Power Line 2 that connects Point 4 and Point 10.
  • The 6-th event breaks Power Line 7 that connects Point 1 and Point 7.
    • Now City 1 is no longer electrified, while 1 city remains electrified.
I - Apples

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 550

問題文

数直線上にりんごの木が並んでおり、 N 個のりんごが木から落ちてきます。
具体的には 1\leq i\leq N について、時刻 T_i に座標 X_i にりんごが落ちてきます。

高橋君は耐久性が D , 長さ W のカゴを持っており、一度だけ 次の行動を取ることができます。

正整数 S, L を選ぶ。高橋君は時刻 S-0.5L-0.5\leq x\leq L+W-0.5 の範囲を覆うようにカゴを設置し、時刻 S+D-0.5 に回収する。 高橋君はカゴを設置してから回収するまでの間に、カゴが設置されていた範囲に落ちてきたりんごをすべて得ることができる。

高橋君は一度設置したカゴを動かしたり、回収したカゴを再度設置することはできません。
高橋君が得られるりんごの数の最大値を求めてください。

制約

  • 1 \leq N\leq 2\times 10^5
  • 1 \leq D\leq 2\times 10^5
  • 1 \leq W\leq 2\times 10^5
  • 1 \leq T_i\leq 2\times 10^5
  • 1 \leq X_i\leq 2\times 10^5
  • (T_i,X_i) はすべて異なる。
  • 入力はすべて整数

入力

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

N D W
T_1 X_1
T_2 X_2
\vdots
T_N X_N

出力

高橋君が得られるりんごの数の最大値を出力せよ。


入力例 1

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

出力例 1

5

高橋君は S=3, L=2 を選ぶと、時刻 2.5 から 6.5 までカゴを 1.5\leq x\leq 4.5 の範囲に設置します。このとき、

  • 時刻 T_2=3 に 座標 X_2=4 に落ちてくるりんご
  • 時刻 T_3=6 に 座標 X_3=4 に落ちてくるりんご
  • 時刻 T_4=5 に 座標 X_4=2 に落ちてくるりんご
  • 時刻 T_5=4 に 座標 X_5=2 に落ちてくるりんご
  • 時刻 T_6=4 に 座標 X_6=3 に落ちてくるりんご

5 個のりんごを得ることができます。
どのように行動しても 6 個以上のりんごを得ることはできないため、5 を出力します。

Score : 550 points

Problem Statement

There are apple trees lined up on a number line, and N apples fall from the trees.
Specifically, for each 1\leq i\leq N, an apple falls at coordinate X_i at time T_i.

Takahashi has a basket with durability D and length W, and he can take the following action exactly once.

Choose positive integers S and L. He sets up the basket to cover the range L-0.5\leq x\leq L+W-0.5 at time S-0.5, and retrieves it at time S+D-0.5. He gets all the apples that fell into the range covered by the basket between the time it was set up and the time it was retrieved.

He cannot move the basket once it has been set up, nor can he set it up again once it has been retrieved.
Find the maximum number of apples that he can get.

Constraints

  • 1 \leq N\leq 2\times 10^5
  • 1 \leq D\leq 2\times 10^5
  • 1 \leq W\leq 2\times 10^5
  • 1 \leq T_i\leq 2\times 10^5
  • 1 \leq X_i\leq 2\times 10^5
  • All pairs (T_i,X_i) are different.
  • All input values are integers.

Input

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

N D W
T_1 X_1
T_2 X_2
\vdots
T_N X_N

Output

Print the maximum number of apples that Takahashi can get.


Sample Input 1

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

Sample Output 1

5

If Takahashi chooses S=3 and L=2, he will set up the basket to cover the range 1.5\leq x\leq 4.5 from time 2.5 to 6.5. Then, he gets the following five apples:

  • The apple that falls at coordinate X_2=4 at time T_2=3
  • The apple that falls at coordinate X_3=4 at time T_3=6
  • The apple that falls at coordinate X_4=2 at time T_4=5
  • The apple that falls at coordinate X_5=2 at time T_5=4
  • The apple that falls at coordinate X_6=3 at time T_6=4

There is no way to get six or more apples, so print 5.