C - MissingNo.

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

ナオヒロ君は N+1 個の連続する整数を 1 個ずつ持っていましたが、そのうち 1 個をなくしてしまいました。

残っている N 個の整数が順不同で A_1,\ldots,A_N として与えられるので、なくした整数を求めてください。

なお、なくした整数が一意に定まるような入力のみが与えられます。

制約

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 1000
  • 入力は全て整数である
  • なくした整数は一意に定まる

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

3
2 3 5

出力例 1

4

ナオヒロ君は初め 2,3,4,54 個の整数を持っており、4 をなくし、2,3,5 が残っていました。

なくした整数である 4 を出力します。


入力例 2

8
3 1 4 5 9 2 6 8

出力例 2

7

入力例 3

16
152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150

出力例 3

151

Score : 200 points

Problem Statement

Naohiro had N+1 consecutive integers, one of each, but he lost one of them.

The remaining N integers are given in arbitrary order as A_1,\ldots,A_N. Find the lost integer.

The given input guarantees that the lost integer is uniquely determined.

Constraints

  • 2 \leq N \leq 100
  • 1 \leq A_i \leq 1000
  • All input values are integers.
  • The lost integer is uniquely determined.

Input

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

N
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

3
2 3 5

Sample Output 1

4

Naohiro originally had four integers, 2,3,4,5, then lost 4, and now has 2,3,5.

Print the lost integer, 4.


Sample Input 2

8
3 1 4 5 9 2 6 8

Sample Output 2

7

Sample Input 3

16
152 153 154 147 148 149 158 159 160 155 156 157 144 145 146 150

Sample Output 3

151
D - Batters

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

高橋君は野球をモチーフにしたゲームを作ろうとしましたが、うまくコードが書けなくて困っています。
高橋君の代わりに次の問題を解くプログラムを作ってください。

マス 0, マス 1, マス 2, マス 34 つのマス目があります。はじめマスの上には何もありません。
また、整数 P があり、はじめ P = 0 です。
正の整数からなる数列 A = (A_1, A_2, \dots, A_N) が与えられるので、i = 1, 2, \dots, N について順番に次の操作を行います。

  1. マス 0 に駒を 1 個置く。
  2. マス上のすべての駒を番号が A_i 大きいマスに進める。言い換えると、駒がマス x にあればその駒をマス x + A_i に移動する。
    ただし移動先のマスが存在しない (すなわち x + A_i4 以上になる) 駒たちに関しては、それらを取り除いて P に取り除いた個数を加算する。

すべての操作を行った後の P の値を出力してください。

制約

  • 1 \leq N \leq 100
  • 1 \leq A_i \leq 4
  • 入力される値はすべて整数

入力

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

N
A_1 A_2 \dots A_N

出力

操作終了時点での P の値を出力せよ。


入力例 1

4
1 1 3 2

出力例 1

3

操作を説明すると次のようになり、操作終了時点での P の値は 3 になります。

  • i=1 での操作
    1. マス 0 に駒を置く。この時点でマス 0 にコマが乗っている。
    2. すべての駒を 1 大きいマスに進める。移動を終えた時点でマス 1 に駒が乗っている。
  • i=2 での操作
    1. マス 0 に駒を置く。この時点でマス 0, 1 にコマが乗っている。
    2. すべての駒を 1 大きいマスに進める。移動を終えた時点でマス 1, 2 に駒が乗っている。
  • i=3 での操作
    1. マス 0 に駒を置く。この時点でマス 0, 1, 2 にコマが乗っている。
    2. すべての駒を 3 大きいマスに進める。
      この時、マス 1,2 にある駒は移動先のマスが存在しないため (それぞれ 1+3=4,2+3=5 なので) 、盤上から取り除いて P2 を加算する。P の値は 2 になる。
      移動を終えた時点でマス 3 に駒が乗っている。
  • i=4 での操作
    1. マス 0 に駒を置く。この時点でマス 0, 3 にコマが乗っている。
    2. すべての駒を 2 大きいマスに進める。
      この時、マス 3 にある駒は移動先のマスが存在しないため (3+2=5 なので) 、盤上から取り除いて P1 を加算する。P の値は 3 になる。
      移動を終えた時点でマス 2 に駒が乗っている。

入力例 2

3
1 1 1

出力例 2

0

P の値が操作中に変化しない場合もあります。


入力例 3

10
2 2 4 1 1 1 4 2 2 1

出力例 3

8

Score : 200 points

Problem Statement

Takahashi is trying to create a game inspired by baseball, but he is having difficulty writing the code.
Write a program for Takahashi that solves the following problem.

There are 4 squares called Square 0, Square 1, Square 2, and Square 3. Initially, all squares are empty.
There is also an integer P; initially, P = 0.
Given a sequence of positive integers A = (A_1, A_2, \dots, A_N), perform the following operations for i = 1, 2, \dots, N in this order:

  1. Put a piece on Square 0.
  2. Advance every piece on the squares A_i squares ahead. In other words, if Square x has a piece, move the piece to Square (x + A_i).
    If, however, the destination square does not exist (i.e. x + A_i is greater than or equal to 4) for a piece, remove it. Add to P the number of pieces that have been removed.

Print the value of P after all the operations have been performed.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq A_i \leq 4
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the value of P after all the operations have been performed.


Sample Input 1

4
1 1 3 2

Sample Output 1

3

The operations are described below. After all the operations have been performed, P equals 3.

  • The operations for i=1:
    1. Put a piece on Square 0. Now, Square 0 has a piece.
    2. Advance every piece on the squares 1 square ahead. After these moves, Square 1 has a piece.
  • The operations for i=2:
    1. Put a piece on Square 0. Now, Squares 0 and 1 have a piece.
    2. Advance every piece on the squares 1 square ahead. After these moves, Squares 1 and 2 have a piece.
  • The operations for i=3:
    1. Put a piece on Square 0. Now, Squares 0, 1, and 2 have a piece.
    2. Advance every piece on the squares 3 squares ahead.
      Here, for the pieces on Squares 1 and 2, the destination squares do not exist (since 1+3=4 and 2+3=5), so remove these pieces and add 2 to P. P now equals 2. After these moves, Square 3 has a piece.
  • The operations for i=4:
    1. Put a piece on Square 0. Now, Squares 0 and 3 have a piece.
    2. Advance every piece on the squares 2 squares ahead.
      Here, for the piece on Square 3, the destination square does not exist (since 3+2=5), so remove this piece and add 1 to P. P now equals 3.
      After these moves, Square 2 has a piece.

Sample Input 2

3
1 1 1

Sample Output 2

0

The value of P may not be updated by the operations.


Sample Input 3

10
2 2 4 1 1 1 4 2 2 1

Sample Output 3

8
E - Final Day

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

N 人の生徒が 4 日間にわたる試験を受けています。

それぞれの日に行われる試験は 300 点満点です。すなわち、4 日間を通した試験の満点は 1200 点です。

現在 3 日目までの試験が終わり、これから 4 日目の試験が行われようとしています。i \, (1 \leq i \leq N) 番目の生徒は j \, (1 \leq j \leq 3) 日目の試験で P_{i, j} 点獲得しました。

それぞれの生徒について、4 日目の試験後に上位 K 位以内に入っていることがあり得るかどうか判定してください。
ただし、4 日目の試験後の生徒の順位は、その生徒よりも 4 日間の合計点が高い生徒の人数に 1 を加えた値として定めます。

制約

  • 1 \leq K \leq N \leq 10^5
  • 0 \leq P_{i, j} \leq 300 \, (1 \leq i \leq N, 1 \leq j \leq 3)
  • 入力は全て整数である。

入力

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

N K
P_{1,1} P_{1,2} P_{1,3}
\vdots
P_{N,1} P_{N,2} P_{N,3}

出力

N 行出力せよ。i \, (1 \leq i \leq N) 行目には、i 番目の生徒が 4 日目の試験後に上位 K 位以内に入っていることがあり得るならば Yes と、そうでないならば No と出力せよ。


入力例 1

3 1
178 205 132
112 220 96
36 64 20

出力例 1

Yes
Yes
No

4 日目に全員が 100 点を取ると、1 番目の生徒が 1 位になります。 4 日目に 2 番目の生徒が 100 点を取り、それ以外の生徒が 0 点を取ると、2 番目の生徒が 1 位になります。 3 番目の生徒が 1 位になることはあり得ません。


入力例 2

2 1
300 300 300
200 200 200

出力例 2

Yes
Yes

入力例 3

4 2
127 235 78
192 134 298
28 56 42
96 120 250

出力例 3

Yes
Yes
No
Yes

Score : 300 points

Problem Statement

N students are taking a 4-day exam.

There is a 300-point test on each day, for a total of 1200 points.

The first three days of the exam are already over, and the fourth day is now about to begin. The i-th student (1 \leq i \leq N) got P_{i, j} points on the j-th day (1 \leq j \leq 3).

For each student, determine whether it is possible that he/she is ranked in the top K after the fourth day.
Here, the rank of a student after the fourth day is defined as the number of students whose total scores over the four days are higher than that of the student, plus 1.

Constraints

  • 1 \leq K \leq N \leq 10^5
  • 0 \leq P_{i, j} \leq 300 \, (1 \leq i \leq N, 1 \leq j \leq 3)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
P_{1,1} P_{1,2} P_{1,3}
\vdots
P_{N,1} P_{N,2} P_{N,3}

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain Yes if it is possible that the i-th student is ranked in the top K after the fourth day, and No otherwise.


Sample Input 1

3 1
178 205 132
112 220 96
36 64 20

Sample Output 1

Yes
Yes
No

If every student scores 100 on the fourth day, the 1-st student will rank 1-st.
If the 2-nd student scores 100 and the other students score 0 on the fourth day, the 2-nd student will rank 1-st.
The 3-rd student will never rank 1-st.


Sample Input 2

2 1
300 300 300
200 200 200

Sample Output 2

Yes
Yes

Sample Input 3

4 2
127 235 78
192 134 298
28 56 42
96 120 250

Sample Output 3

Yes
Yes
No
Yes
F - Poem Online Judge

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

ポエムオンラインジャッジ (Poem Online Judge, 以下 POJ と表記) は提出された文字列に得点をつけるオンラインジャッジです。
POJ に N 回の提出がありました。早い方から i 番目の提出では文字列 S_i が提出されて、得点は T_i でした。(同じ文字列が複数回提出される場合もあります)
ただし、POJ では 同じ文字列を提出しても得点が等しいとは限らない のに注意してください。

N 回の提出のうち、その提出よりも早い提出であって文字列が一致するものが存在しないような提出を オリジナル であると呼びます。
また、オリジナルな提出の中で最も得点が高いものを 最優秀賞 と呼びます。ただし、そのような提出が複数ある場合は、最も提出が早いものを最優秀賞とします。

最優秀賞は早い方から何番目の提出ですか?

制約

  • 1 \leq N \leq 10^5
  • S_i は英小文字からなる文字列
  • S_i の長さは 1 以上 10 以下
  • 0 \leq T_i \leq 10^9
  • N, T_i は整数

入力

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

N
S_1 T_1
S_2 T_2
\vdots
S_N T_N

出力

答えを出力せよ。


入力例 1

3
aaa 10
bbb 20
aaa 30

出力例 1

2

以下では早い方から i 番目の提出を提出 i と呼びます。
オリジナルな提出は提出 1 と 提出 2 です。提出 3 は提出 1 と文字列が一致しているためオリジナルではありません。
オリジナルな提出のうち最も得点が高い提出は提出 2 です。よってこれが最優秀賞になります。


入力例 2

5
aaa 9
bbb 10
ccc 10
ddd 10
bbb 11

出力例 2

2

オリジナルな提出は提出 1・提出 2・提出 3・提出 4 です。
その中で最も得点が高い提出は提出 2・提出 3・提出 4 です。この場合はこの中でもっとも提出の早い提出 2 を最優秀賞とします。
このように、オリジナルな提出の中で最も得点が高い提出が複数ある場合は、さらにその中で最も提出が早いものを最優秀賞とするのに注意してください。


入力例 3

10
bb 3
ba 1
aa 4
bb 1
ba 5
aa 9
aa 2
ab 6
bb 5
ab 3

出力例 3

8

Score : 300 points

Problem Statement

Poem Online Judge (POJ) is an online judge that gives scores to submitted strings.
There were N submissions to POJ. In the i-th earliest submission, string S_i was submitted, and a score of T_i was given. (The same string may have been submitted multiple times.)
Note that POJ may not necessarily give the same score to submissions with the same string.

A submission is said to be an original submission if the string in the submission is never submitted in any earlier submission.
A submission is said to be the best submission if it is an original submission with the highest score. If there are multiple such submissions, only the earliest one is considered the best submission.

Find the index of the best submission.

Constraints

  • 1 \leq N \leq 10^5
  • S_i is a string consisting of lowercase English characters.
  • S_i has a length between 1 and 10, inclusive.
  • 0 \leq T_i \leq 10^9
  • N and T_i are integers.

Input

Input is given from Standard Input in the following format:

N
S_1 T_1
S_2 T_2
\vdots
S_N T_N

Output

Print the answer.


Sample Input 1

3
aaa 10
bbb 20
aaa 30

Sample Output 1

2

We will refer to the i-th earliest submission as Submission i.
Original submissions are Submissions 1 and 2. Submission 3 is not original because it has the same string as that in Submission 1.
Among the original submissions, Submission 2 has the highest score. Therefore, this is the best submission.


Sample Input 2

5
aaa 9
bbb 10
ccc 10
ddd 10
bbb 11

Sample Output 2

2

Original submissions are Submissions 1, 2, 3, and 4.
Among them, Submissions 2, 3, and 4 have the highest scores. In this case, the earliest submission among them, Submission 2, is the best.
As in this sample, beware that if multiple original submissions have the highest scores, only the one with the earliest among them is considered the best submission.


Sample Input 3

10
bb 3
ba 1
aa 4
bb 1
ba 5
aa 9
aa 2
ab 6
bb 5
ab 3

Sample Output 3

8
G - Mismatched Parentheses

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

英小文字および (, ) からなる長さ N の文字列 S が与えられます。
以下の操作を可能な限り繰り返したあとの S を出力してください。

  • S の連続部分文字列であって、最初の文字が ( かつ 最後の文字が ) かつ 最初と最後以外に () も含まないものを自由に 1 つ選び削除する

なお、操作を可能な限り繰り返したあとの S は操作の手順によらず一意に定まることが証明できます。

制約

  • 1 \leq N \leq 2 \times 10^5
  • N は整数である
  • S は英小文字および (, ) からなる長さ N の文字列である

入力

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

N
S

出力

答えを出力せよ。


入力例 1

8
a(b(d))c

出力例 1

ac

例えば、以下の手順により操作後の Sac となります。

  • S4 文字目から 6 文字目までからなる部分文字列 (d) を削除する。Sa(b)c となる。
  • S2 文字目から 4 文字目までからなる部分文字列 (b) を削除する。Sac となる。
  • これ以上操作を行うことはできない。

入力例 2

5
a(b)(

出力例 2

a(

入力例 3

2
()

出力例 3


操作後の S は空文字列になる可能性があります。


入力例 4

6
)))(((

出力例 4

)))(((

Score : 400 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters and the characters ( and ).
Print the string S after performing the following operation as many times as possible.

  • Choose and delete a contiguous substring of S that starts with (, ends with ), and does not contain ( or ) other than the first and last characters.

It can be proved that the string S after performing the operation as many times as possible is uniquely determined without depending on how it is performed.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • N is an integer.
  • S is a string of length N consisting of lowercase English letters and the characters ( and ).

Input

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

N
S

Output

Print the answer.


Sample Input 1

8
a(b(d))c

Sample Output 1

ac

Here is one possible procedure, after which S will be ac.

  • Delete the substring (d) formed by the fourth to sixth characters of S, making it a(b)c.
  • Delete the substring (b) formed by the second to fourth characters of S, making it ac.
  • The operation can no longer be performed.

Sample Input 2

5
a(b)(

Sample Output 2

a(

Sample Input 3

2
()

Sample Output 3


The string S after the procedure may be empty.


Sample Input 4

6
)))(((

Sample Output 4

)))(((