C - Better Students Are Needed!

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

入学試験の受験者が N 人います。
試験の結果、 i 番の受験生は数学で A_i 点、英語で B_i 点を取りました。

試験の合格者は次のように決められます。

  1. 数学の点が高い方から X 人を合格とする。
  2. 次に、この時点でまだ合格となっていない受験者のうち、英語の点が高い方から Y 人を合格とする。
  3. 次に、この時点でまだ合格となっていない受験者のうち、数学と英語の合計点が高い方から Z 人を合格とする。
  4. ここまでで合格となっていない受験者は、不合格とする。

ただし、 1. から 3. までのどの段階についても、同点であった場合は受験生の番号の小さい方を優先します。入出力例も参照してください。

以上の手順で合格者を決める時、合格となった受験生の番号を小さい方から順に改行区切りで出力してください。

制約

  • 入力は全て整数
  • 1 \le N \le 1000
  • 0 \le X,Y,Z \le N
  • 1 \le X+Y+Z \le N
  • 0 \le A_i,B_i \le 100

入力

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

N X Y Z
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N

出力

合格となった受験生の番号を小さい方から順に改行区切りで出力せよ。


入力例 1

6 1 0 2
80 60 80 60 70 70
40 20 50 90 90 80

出力例 1

1
4
5
  • まず、数学の点が高い方から 1 人が合格となります。
    • 数学の最高点は 80 点で 1 番の受験生と 3 番の受験生が並んでいますが、受験生の番号が小さい方が優先され 1 番の受験生が合格となります。
  • 次に、まだ合格となっていない受験者のうち、英語の点が高い方から 0 人が合格となります。
    • 明らかに、ここで合格者が増えることはありません。
  • 次に、まだ合格となっていない受験者のうち、数学と英語の合計点が高い方から 2 人が合格となります。
    • まず、まだ合格となっていない受験者の中で、合計点が 160 点と最も高い 5 番の受験生が合格となります。
    • 次に、まだ合格となっていない受験者の中で、合計点が 150 点の 4 番の受験生と 6 番の受験生が並んでいます。受験生の番号の小さい方が優先され、 4 番の受験生が合格となります。

以上より、合格となる受験生の番号は 1,4,5 なので、小さい方から出力してください。


入力例 2

5 2 1 2
0 100 0 100 0
0 0 100 100 0

出力例 2

1
2
3
4
5

全員が合格となることもあります。


入力例 3

15 4 3 2
30 65 20 95 100 45 70 85 20 35 95 50 40 15 85
0 25 45 35 65 70 80 90 40 55 20 20 45 75 100

出力例 3

2
4
5
6
7
8
11
14
15

Score : 200 points

Problem Statement

N examinees took an entrance exam.
The examinee numbered i scored A_i points in math and B_i points in English.

The admissions are determined as follows.

  1. X examinees with the highest math scores are admitted.
  2. Then, among the examinees who are not admitted yet, Y examinees with the highest English scores are admitted.
  3. Then, among the examinees who are not admitted yet, Z examinees with the highest total scores in math and English are admitted.
  4. Those examinees who are not admitted yet are rejected.

Here, in each of the steps 1. to 3., ties are broken by examinees' numbers: an examinee with the smaller examinee's number is prioritized. See also Sample Input and Output.

Print the examinees' numbers of the admitted examinees determined by the steps above in ascending order, separated by newlines.

Constraints

  • All values in input are integers.
  • 1 \le N \le 1000
  • 0 \le X,Y,Z \le N
  • 1 \le X+Y+Z \le N
  • 0 \le A_i,B_i \le 100

Input

Input is given from Standard Input in the following format:

N X Y Z
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N

Output

Print the examinees' number of the admitted examinees in ascending order, separated by newlines.


Sample Input 1

6 1 0 2
80 60 80 60 70 70
40 20 50 90 90 80

Sample Output 1

1
4
5
  • First, 1 examinee with the highest math score is admitted.
    • Examinee 1 is tied with Examinee 3, scoring the highest 80 points in math, and the tie is broken by the examinees' numbers, so Examinee 1 is admitted.
  • Then, among the examinees who are not admitted yet, 0 examinees with the highest English scores are admitted.
    • Obviously, it does not affect the admissions.
  • Then, among the examinees who are not admitted yet, 2 examinees with the highest total scores in math and English are admitted.
    • First, among the examinees who are not admitted yet, Examinee 5 is admitted, scoring the highest total score of 160 points.
    • Next, among the examinees who are not admitted yet, Examinee 4 is tied with Examinee 6, scoring a total score of 150 points. The tie is broken by the examinees' numbers, and Examinee 4 is admitted.

Therefore, the examinees' numbers of the admitted examinees are 1, 4, and 5. Print them in ascending order.


Sample Input 2

5 2 1 2
0 100 0 100 0
0 0 100 100 0

Sample Output 2

1
2
3
4
5

All examinees may be admitted.


Sample Input 3

15 4 3 2
30 65 20 95 100 45 70 85 20 35 95 50 40 15 85
0 25 45 35 65 70 80 90 40 55 20 20 45 75 100

Sample Output 3

2
4
5
6
7
8
11
14
15
D - AtCoder Quiz

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

AtCoder では現在、 ABC , ARC , AGC , AHC4 つのコンテストが定期的に開催されています。

AtCoder で現在定期的に開催されているコンテストは S_1 , S_2 , S_3 とあと 1 つは何ですか?

制約

  • S_1 , S_2 , S_3 はそれぞれ、 ABC , ARC , AGC , AHC のいずれかである。
  • S_1 , S_2 , S_3 は相異なる。

入力

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

S_1
S_2
S_3

出力

答えを出力せよ。


入力例 1

ARC
AGC
AHC

出力例 1

ABC

ARC , AGC , AHC3つが入力として与えられているので、 残りの 1 つはABC です。


入力例 2

AGC
ABC
ARC

出力例 2

AHC

Score : 200 points

Problem Statement

AtCoder currently holds four series of regular contests: ABC, ARC, AGC, and AHC.

What is the series of regular contests currently held by AtCoder in addition to S_1, S_2, and S_3?

Constraints

  • Each of S_1, S_2, and S_3 is ABC, ARC, AGC, or AHC.
  • S_1, S_2, and S_3 are pairwise different.

Input

Input is given from Standard Input in the following format:

S_1
S_2
S_3

Output

Print the answer.


Sample Input 1

ARC
AGC
AHC

Sample Output 1

ABC

Given in input are ARC, AGC, and AHC. The rest is ABC.


Sample Input 2

AGC
ABC
ARC

Sample Output 2

AHC
E - Even Digits

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

非負整数 n が次の条件を満たすとき、n良い整数 と呼びます。

  • n10 進法で表したときに、偶数の数字 (0, 2, 4, 6, 8) のみが登場する。

例えば 068 および 2024 は良い整数です。

整数 N が与えられます。良い整数のうち小さい方から N 番目の整数を求めてください。

制約

  • 1 \leq N \leq 10^{12}
  • N は整数

入力

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

N

出力

小さい方から N 番目の良い整数を出力せよ。


入力例 1

8

出力例 1

24

良い整数を小さい方から順に並べると 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots となります。
小さい方から 8 番目の良い整数は 24 なので、これを出力します。


入力例 2

133

出力例 2

2024

入力例 3

31415926535

出力例 3

2006628868244228

Score: 300 points

Problem Statement

A non-negative integer n is called a good integer when it satisfies the following condition:

  • All digits in the decimal notation of n are even numbers (0, 2, 4, 6, and 8).

For example, 0, 68, and 2024 are good integers.

You are given an integer N. Find the N-th smallest good integer.

Constraints

  • 1 \leq N \leq 10^{12}
  • N is an integer.

Input

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

N

Output

Print the N-th smallest good integer.


Sample Input 1

8

Sample Output 1

24

The good integers in ascending order are 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots.
The eighth smallest is 24, which should be printed.


Sample Input 2

133

Sample Output 2

2024

Sample Input 3

31415926535

Sample Output 3

2006628868244228
F - Four Variables

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

正整数 N が与えられます。
正整数の組 (A,B,C,D) であって、AB + CD = N を満たすものの個数を求めてください。

なお、本問の制約の下、答えが 9 \times 10^{18} 以下であることが証明できます。

制約

  • 2 \leq N \leq 2 \times 10^5
  • N は整数

入力

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

N

出力

答えを出力せよ。


入力例 1

4

出力例 1

8

(A,B,C,D) として以下の 8 個が考えられます。

  • (A,B,C,D)=(1,1,1,3)
  • (A,B,C,D)=(1,1,3,1)
  • (A,B,C,D)=(1,2,1,2)
  • (A,B,C,D)=(1,2,2,1)
  • (A,B,C,D)=(1,3,1,1)
  • (A,B,C,D)=(2,1,1,2)
  • (A,B,C,D)=(2,1,2,1)
  • (A,B,C,D)=(3,1,1,1)

入力例 2

292

出力例 2

10886

入力例 3

19876

出力例 3

2219958

Score : 300 points

Problem Statement

You are given a positive integer N.
Find the number of quadruples of positive integers (A,B,C,D) such that AB + CD = N.

Under the constraints of this problem, it can be proved that the answer is at most 9 \times 10^{18}.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • N is an integer.

Input

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

N

Output

Print the answer.


Sample Input 1

4

Sample Output 1

8

Here are the eight desired quadruples.

  • (A,B,C,D)=(1,1,1,3)
  • (A,B,C,D)=(1,1,3,1)
  • (A,B,C,D)=(1,2,1,2)
  • (A,B,C,D)=(1,2,2,1)
  • (A,B,C,D)=(1,3,1,1)
  • (A,B,C,D)=(2,1,1,2)
  • (A,B,C,D)=(2,1,2,1)
  • (A,B,C,D)=(3,1,1,1)

Sample Input 2

292

Sample Output 2

10886

Sample Input 3

19876

Sample Output 3

2219958
G - 1D Country

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 350

問題文

数直線上に N 個の村があります。i 番目の村は座標 X_i にあり、P_i 人の村人がいます。

Q 個のクエリに答えてください。i 番目のクエリは以下の形式です。

  • 整数 L_i,R_i が与えられる。座標が L_i 以上 R_i 以下の村に住んでいる村人の人数の総数を求めよ。

制約

  • 1\leq N,Q\leq 2\times 10^5
  • -10^9\leq X_1 < X_2 < \ldots < X_N \leq 10^9
  • 1\leq P_i\leq 10^9
  • -10^9\leq L_i \leq R_i \leq 10^9
  • 入力される数値は全て整数

入力

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

N
X_1 \ldots X_N
P_1 \ldots P_N
Q
L_1 R_1
\vdots
L_Q R_Q 

出力

Q 行出力せよ。

i\ (1\leq i \leq Q) 行目には、i 番目のクエリに対する答えを出力せよ。


入力例 1

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

出力例 1

1
5
10
0

1 番目のクエリについて考えます。座標が 1 以上 1 以下の村は、座標 1 にある村で、村人は 1 人います。よって答えは 1 です。

2 番目のクエリについて考えます。座標が 2 以上 6 以下の村は、座標 3 にある村と座標 5 にある村で、村人はそれぞれ 2 人と 3 人います。よって答えは 2+3=5 です。


入力例 2

7
-10 -5 -3 -1 0 1 4
2 5 6 5 2 1 7
8
-7 7
-1 5
-10 -4
-8 10
-5 0
-10 5
-8 7
-8 -3

出力例 2

26
15
7
26
18
28
26
11

Score : 350 points

Problem Statement

There are N villages on a number line. The i-th village is located at coordinate X_i, and has P_i villagers.

Answer Q queries. The i-th query is in the following format:

  • Given integers L_i and R_i, find the total number of villagers living in villages located between coordinates L_i and R_i, inclusive.

Constraints

  • 1\leq N,Q\leq 2\times 10^5
  • -10^9\leq X_1 < X_2 < \ldots < X_N \leq 10^9
  • 1\leq P_i\leq 10^9
  • -10^9\leq L_i \leq R_i \leq 10^9
  • All input values are integers.

Input

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

N
X_1 \ldots X_N
P_1 \ldots P_N
Q
L_1 R_1
\vdots
L_Q R_Q

Output

Print Q lines.

The i-th line(1\leq i \leq Q) should contain the answer to the i-th query.


Sample Input 1

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

Sample Output 1

1
5
10
0

Consider the first query. The villages between coordinates 1 and 1 are the village at coordinate 1, with 1 villager. Hence, the answer is 1.

Consider the second query. The villages between coordinates 2 and 6 are the villages at coordinates 3 and 5, with 2 and 3 villagers, respectively. Hence, the answer is 2+3=5.


Sample Input 2

7
-10 -5 -3 -1 0 1 4
2 5 6 5 2 1 7
8
-7 7
-1 5
-10 -4
-8 10
-5 0
-10 5
-8 7
-8 -3

Sample Output 2

26
15
7
26
18
28
26
11