A - Sequence of Strings

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

N 個の文字列 S_1,S_2,\ldots,S_N がこの順番で与えられます。

S_N,S_{N-1},\ldots,S_1 の順番で出力してください。

制約

  • 1\leq N \leq 10
  • N は整数
  • S_i は英小文字、英大文字、数字からなる長さ 1 以上 10 以下の文字列

入力

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

N
S_1
S_2
\vdots
S_N

出力

N 行出力せよ。 i\ (1\leq i \leq N) 行目には、S_{N+1-i} を出力せよ。


入力例 1

3
Takahashi
Aoki
Snuke

出力例 1

Snuke
Aoki
Takahashi

N=3S_1= TakahashiS_2= AokiS_3= Snuke です。

よって、SnukeAokiTakahashi の順で出力します。


入力例 2

4
2023
Year
New
Happy

出力例 2

Happy
New
Year
2023

与えられる文字列が数字を含むこともあります。

Score : 100 points

Problem Statement

You are given N strings S_1,S_2,\ldots,S_N in this order.

Print S_N,S_{N-1},\ldots,S_1 in this order.

Constraints

  • 1\leq N \leq 10
  • N is an integer.
  • S_i is a string of length between 1 and 10, inclusive, consisting of lowercase English letters, uppercase English letters, and digits.

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print N lines. The i-th (1\leq i \leq N) line should contain S_{N+1-i}.


Sample Input 1

3
Takahashi
Aoki
Snuke

Sample Output 1

Snuke
Aoki
Takahashi

We have N=3, S_1= Takahashi, S_2= Aoki, and S_3= Snuke.

Thus, you should print Snuke, Aoki, and Takahashi in this order.


Sample Input 2

4
2023
Year
New
Happy

Sample Output 2

Happy
New
Year
2023

The given strings may contain digits.

B - Hell, World!

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

1 以上 10 以下の整数 X が与えられます。

HelloWorld という文字列から X 文字目だけを削除した文字列を出力してください。

制約

  • X1 以上 10 以下の整数

入力

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

X

出力

答えを出力せよ。


入力例 1

5

出力例 1

HellWorld

HelloWorld5 文字目を削除すると HellWorld になります。したがって、HellWorld を出力してください。


入力例 2

9

出力例 2

HelloWord

入力例 3

1

出力例 3

elloWorld

Score : 100 points

Problem Statement

You are given an integer X between 1 and 10, inclusive.

Output the string obtained by deleting only the X-th character from the string HelloWorld.

Constraints

  • X is an integer between 1 and 10, inclusive.

Input

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

X

Output

Output the answer.


Sample Input 1

5

Sample Output 1

HellWorld

Deleting the 5-th character of HelloWorld gives HellWorld. Thus, output HellWorld.


Sample Input 2

9

Sample Output 2

HelloWord

Sample Input 3

1

Sample Output 3

elloWorld
C - Who is missing?

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

整数 1, 2, \dots, N が書かれたカードが 4 枚ずつ、合計 4N 枚あります。

高橋君は、これらのカードをシャッフルしたのち 1 枚のカードを選んで抜き取り、残りの 4N - 1 枚を束にしてあなたに渡しました。渡された束の i \, (1 \leq i \leq 4N - 1) 枚目のカードには、整数 A_i が書かれています。

高橋君が抜き取ったカードに書かれていた整数を求めてください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq N \, (1 \leq i \leq 4N - 1)
  • k \, (1 \leq k \leq N) に対し、A_i = k となる i4 個以下である。
  • 入力は全て整数である。

入力

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

N
A_1 A_2 \ldots A_{4N - 1}

出力

答えを出力せよ。


入力例 1

3
1 3 2 3 3 2 2 1 1 1 2

出力例 1

3

高橋君が抜き取ったカードには 3 が書かれています。


入力例 2

1
1 1 1

出力例 2

1

入力例 3

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

出力例 3

2

Score : 200 points

Problem Statement

We have 4 cards with an integer 1 written on it, 4 cards with 2, \ldots, 4 cards with N, for a total of 4N cards.

Takahashi shuffled these cards, removed one of them, and gave you a pile of the remaining 4N-1 cards. The i-th card (1 \leq i \leq 4N - 1) of the pile has an integer A_i written on it.

Find the integer written on the card removed by Takahashi.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq A_i \leq N \, (1 \leq i \leq 4N - 1)
  • For each k \, (1 \leq k \leq N), there are at most 4 indices i such that A_i = k.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_{4N - 1}

Output

Print the answer.


Sample Input 1

3
1 3 2 3 3 2 2 1 1 1 2

Sample Output 1

3

Takahashi removed a card with 3 written on it.


Sample Input 2

1
1 1 1

Sample Output 2

1

Sample Input 3

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

Sample Output 3

2
D - Sensor Data Logging

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

ある測定では、時刻 0,1,\dots,T におけるセンサーの測定値を以下の規則で記録します。

  • 時刻 0 では、測定値を保存する。
  • 時刻 1,2,\dots,T では、「現時刻の測定値」と「直前に保存された測定値」との差の絶対値が X 以上であるとき、またその時に限り値を保存する。

時刻 i=0,1,\dots,T におけるセンサーの測定値は A_i でした。

測定値が保存された時刻と保存された値とを、時刻の昇順に出力してください。

制約

  • 1 \le T \le 100
  • 1 \le X \le 100
  • 0 \le A_i \le 100
  • 入力はすべて整数

入力

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

T X
A_0 A_1 \dots A_T

出力

測定値が k 回保存され、そのうち時刻の昇順に並べた時に i 回目の時刻が t_i 、測定値が a_i であったとき、以下の形式で出力せよ。

t_1 a_1
t_2 a_2
\vdots
t_k a_k

入力例 1

6 10
30 35 40 21 30 12 31

出力例 1

0 30
2 40
3 21
6 31

測定は以下の流れで進行します。

  • 時刻 0 の測定値は 30 であった。これを保存する。
  • 時刻 1 の測定値は 35 であった。最後に保存された測定値は 30 であり、この値との差の絶対値が 10 未満であるため、保存しない。
  • 時刻 2 の測定値は 40 であった。最後に保存された測定値は 30 であり、この値との差の絶対値が 10 以上であるため、保存する。
  • 時刻 3 の測定値は 21 であった。最後に保存された測定値は 40 であり、この値との差の絶対値が 10 以上であるため、保存する。
  • 時刻 4 の測定値は 30 であった。最後に保存された測定値は 21 であり、この値との差の絶対値が 10 未満であるため、保存しない。
  • 時刻 5 の測定値は 12 であった。最後に保存された測定値は 21 であり、この値との差の絶対値が 10 未満であるため、保存しない。
  • 時刻 6 の測定値は 31 であった。最後に保存された測定値は 21 であり、この値との差の絶対値が 10 以上であるため、保存する。

Score : 200 points

Problem Statement

In a certain measurement, the sensor readings at times 0,1,\dots,T are recorded according to the following rules.

  • At time 0, the reading is saved.
  • At times 1,2,\dots,T, the reading is saved if and only if the absolute difference between the current reading and the most recently saved reading is at least X.

The sensor reading at time i=0,1,\dots,T was A_i.

Output the times at which readings were saved and the saved values, in ascending order of time.

Constraints

  • 1 \le T \le 100
  • 1 \le X \le 100
  • 0 \le A_i \le 100
  • All input values are integers.

Input

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

T X
A_0 A_1 \dots A_T

Output

If k readings were saved, and the i-th saved reading in ascending order of time was at time t_i with value a_i, output in the following format:

t_1 a_1
t_2 a_2
\vdots
t_k a_k

Sample Input 1

6 10
30 35 40 21 30 12 31

Sample Output 1

0 30
2 40
3 21
6 31

The measurement proceeds as follows.

  • The reading at time 0 is 30. Save it.
  • The reading at time 1 is 35. The most recently saved reading is 30, and the absolute difference is less than 10, so it is not saved.
  • The reading at time 2 is 40. The most recently saved reading is 30, and the absolute difference is at least 10, so it is saved.
  • The reading at time 3 is 21. The most recently saved reading is 40, and the absolute difference is at least 10, so it is saved.
  • The reading at time 4 is 30. The most recently saved reading is 21, and the absolute difference is less than 10, so it is not saved.
  • The reading at time 5 is 12. The most recently saved reading is 21, and the absolute difference is less than 10, so it is not saved.
  • The reading at time 6 is 31. The most recently saved reading is 21, and the absolute difference is at least 10, so it is saved.
E - Variety

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

N 個の宝石があります。i 番目の宝石の色(整数で表されます)は C_i で価値は V_i です。

この N 個の宝石の中から K 個を選びます。ただし、選んだ宝石の色が M 種類以上なければなりません。

このとき、選んだ宝石の価値の総和としてありうる最大値を求めてください。(与えられる入力では、このような選択が必ず可能です。)

制約

  • 1 \leq M \leq K \leq N \leq 2 \times 10^5
  • 1 \leq C_i \leq N
  • 1 \leq V_i \leq 10^9
  • M 種類以上の色の宝石が存在する
  • 入力される値はすべて整数

入力

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

N K M
C_1 V_1
C_2 V_2
\vdots
C_N V_N

出力

選んだ宝石の価値の総和としてありうる最大値を整数として出力せよ。


入力例 1

5 3 2
1 30
1 40
1 50
2 10
3 20

出力例 1

110

この例では 5 個の宝石から 3 個を選びます。選んだ宝石の色が 2 種類以上なければなりません。

宝石 2, 3, 5 を選ぶと、それらの色は 1, 1, 32 種類あります。それらの価値の総和は 40 + 50 + 20 = 110 で、これがありうる最大値です。


入力例 2

5 3 3
1 30
1 40
1 50
2 10
3 20

出力例 2

80

宝石や選ぶ個数は入力例 1 と同じですが、選んだ宝石の色が 3 種類以上なければなりません。

宝石 3, 4, 5 を選ぶと、それらの色は 1, 2, 33 種類あります。それらの価値の総和は 50 + 10 + 20 = 80 で、これがありうる最大値です。


入力例 3

5 5 1
4 1000000000
5 1000000000
4 1000000000
5 1000000000
4 1000000000

出力例 3

5000000000

オーバーフローに注意してください。

Score : 300 points

Problem Statement

There are N gems. The color (represented as an integer) of the i-th gem is C_i and its value is V_i.

Choose K gems from these N gems. Here, the chosen gems must have at least M distinct colors.

Find the maximum possible total value of the chosen gems. (Such a choice is always possible in the given input.)

Constraints

  • 1 \leq M \leq K \leq N \leq 2 \times 10^5
  • 1 \leq C_i \leq N
  • 1 \leq V_i \leq 10^9
  • There exist gems of at least M distinct colors.
  • All input values are integers.

Input

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

N K M
C_1 V_1
C_2 V_2
\vdots
C_N V_N

Output

Output the maximum possible total value of the chosen gems as an integer.


Sample Input 1

5 3 2
1 30
1 40
1 50
2 10
3 20

Sample Output 1

110

In this sample, choose three gems from five gems. The chosen gems must have at least two distinct colors.

Choosing gems 2, 3, 5 gives colors 1, 1, 3, which are two distinct colors. Their total value is 40 + 50 + 20 = 110, and this is the maximum possible value.


Sample Input 2

5 3 3
1 30
1 40
1 50
2 10
3 20

Sample Output 2

80

The gems and the number to choose are the same as in Sample Input 1, but the chosen gems must have at least three distinct colors.

Choosing gems 3, 4, 5 gives colors 1, 2, 3, which are three distinct colors. Their total value is 50 + 10 + 20 = 80, and this is the maximum possible value.


Sample Input 3

5 5 1
4 1000000000
5 1000000000
4 1000000000
5 1000000000
4 1000000000

Sample Output 3

5000000000

Beware of overflow.