A - Not Found

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

配点 : 100

問題文

英小文字からなる長さ 1 以上 25 以下の文字列 S が与えられます。
S に含まれない英小文字をひとつ出力してください。
但し、そのようなものが複数ある場合はどれを出力しても構いません。

制約

  • S は英小文字からなる長さ 1 以上 25 以下の文字列

入力

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

S

出力

S に含まれない英小文字をひとつ出力せよ。そのようなものが複数ある場合はどれを出力しても構わない。


入力例 1

a

出力例 1

d

S= a です。
a 以外の英小文字、 b, c, ..., z が正解となります。


入力例 2

abcdfhijklmnopqrstuvwxyz

出力例 2

e

S 中に含まれない英小文字は eg です。


入力例 3

qazplwsxokmedcijnrfvuhbgt

出力例 3

y

Score : 100 points

Problem Statement

You are given a string S of length between 1 and 25 consisting of lowercase English letters.
Output one lowercase English letter that does not appear in S.
If there are multiple such letters, you may output any one of them.

Constraints

  • S is a string of length between 1 and 25 (inclusive) consisting of lowercase English letters.

Input

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

S

Output

Output one lowercase English letter that does not appear in S. If there are multiple such letters, you may output any one of them.


Sample Input 1

a

Sample Output 1

d

S= a.
Any lowercase English letter other than a (that is, b, c, …, or z) is a correct answer.


Sample Input 2

abcdfhijklmnopqrstuvwxyz

Sample Output 2

e

The lowercase English letters not included in S are e and g.


Sample Input 3

qazplwsxokmedcijnrfvuhbgt

Sample Output 3

y
B - Grandma's Footsteps

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

配点 : 150

問題文

高橋君は学校でゲームを楽しんでいます。チャイムが鳴ると同時にゲームが開始します。

高橋君はチャイムが鳴った直後から、以下の動作を繰り返し行います。

  • 毎秒 S メートルの速さで A 秒間走る。その後の B 秒間は静止する。

チャイムが鳴ってから X 秒が経過するまでに、高橋君は合計何メートル走りますか?

制約

  • 1 \leq S \leq 15
  • 1 \leq A \leq 1000
  • 1 \leq B \leq 1000
  • 1 \leq X \leq 1000
  • 入力される値はすべて整数

入力

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

S A B X

出力

答えを 1 行に出力せよ。単位 (メートル) は省いて出力すること。


入力例 1

7 3 2 11

出力例 1

49

チャイムが鳴ってからの 11 秒間、高橋君は以下のように動きます。

  • 0 秒後から 3 秒後までのあいだ、高橋君は毎秒 7 メートルの速さで走る。このあいだの移動距離は 21 メートル。
  • 3 秒後から 5 秒後までのあいだ、高橋君は静止する。
  • 5 秒後から 8 秒後までのあいだ、高橋君は毎秒 7 メートルの速さで走る。このあいだの移動距離は 21 メートル。
  • 8 秒後から 10 秒後までのあいだ、高橋君は静止する。
  • 10 秒後から 11 秒後までのあいだ、高橋君は毎秒 7 メートルの速さで走る。このあいだの移動距離は 7 メートル。

総移動距離は 49 メートルなので、49 を出力します。


入力例 2

6 3 2 9

出力例 2

36

チャイムが鳴ってからの 9 秒間、高橋君は以下のように動きます。

  • 0 秒後から 3 秒後までのあいだ、高橋君は毎秒 6 メートルの速さで走る。このあいだの移動距離は 18 メートル。
  • 3 秒後から 5 秒後までのあいだ、高橋君は静止する。
  • 5 秒後から 8 秒後までのあいだ、高橋君は毎秒 6 メートルの速さで走る。このあいだの移動距離は 18 メートル。
  • 8 秒後から 9 秒後までのあいだ、高橋君は静止する。

総移動距離は 36 メートルなので、36 を出力します。


入力例 3

1 1 666 428

出力例 3

1

チャイムが鳴ってからの 428 秒間、高橋君は以下のように動きます。

  • 0 秒後から 1 秒後までのあいだ、高橋君は毎秒 1 メートルの速さで走る。このあいだの移動距離は 1 メートル。
  • 1 秒後から 428 秒後までのあいだ、高橋君は静止する。

総移動距離は 1 メートルなので、1 を出力します。

Score : 150 points

Problem Statement

Takahashi is enjoying a game at school. The game starts at the moment the bell rings.

Immediately after the bell rings, he repeats the following actions:

  • Run at a speed of S meters per second for A seconds. Then, remain stationary for B seconds.

How many meters in total does he run by the time X seconds have elapsed since the bell rang?

Constraints

  • 1 \leq S \leq 15
  • 1 \leq A \leq 1000
  • 1 \leq B \leq 1000
  • 1 \leq X \leq 1000
  • All input values are integers.

Input

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

S A B X

Output

Output the answer in one line. Omit the unit (meters) in the output.


Sample Input 1

7 3 2 11

Sample Output 1

49

During the 11 seconds after the bell rings, Takahashi moves as follows:

  • From 0 seconds to 3 seconds, he runs at a speed of 7 meters per second. The distance traveled during this time is 21 meters.
  • From 3 seconds to 5 seconds, he remains stationary.
  • From 5 seconds to 8 seconds, he runs at a speed of 7 meters per second. The distance traveled during this time is 21 meters.
  • From 8 seconds to 10 seconds, he remains stationary.
  • From 10 seconds to 11 seconds, he runs at a speed of 7 meters per second. The distance traveled during this time is 7 meters.

The total distance traveled is 49 meters, so output 49.


Sample Input 2

6 3 2 9

Sample Output 2

36

During the 9 seconds after the bell rings, Takahashi moves as follows:

  • From 0 seconds to 3 seconds, he runs at a speed of 6 meters per second. The distance traveled during this time is 18 meters.
  • From 3 seconds to 5 seconds, he remains stationary.
  • From 5 seconds to 8 seconds, he runs at a speed of 6 meters per second. The distance traveled during this time is 18 meters.
  • From 8 seconds to 9 seconds, he remains stationary.

The total distance traveled is 36 meters, so output 36.


Sample Input 3

1 1 666 428

Sample Output 3

1

During the 428 seconds after the bell rings, Takahashi moves as follows:

  • From 0 seconds to 1 second, he runs at a speed of 1 meter per second. The distance traveled during this time is 1 meter.
  • From 1 second to 428 seconds, he remains stationary.

The total distance traveled is 1 meter, so output 1.

C - MissingNo.

実行時間制限: 2 sec / メモリ制限: 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 - A..B..C

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

配点 : 200

問題文

文字列 S が与えられます。

S の中に A, B, C がこの順に等間隔に並んでいる場所が何箇所あるか求めてください。

厳密には、3 つの整数の組 (i,j,k) であって、以下の条件をすべて満たすものの個数を求めてください。 ここで、|S|S の長さを、S_xSx 文字目を表すものとします。

  • 1\leq i<j<k\leq |S|
  • j-i = k-j
  • S_i= A
  • S_j= B
  • S_k= C

制約

  • S は英大文字からなる長さ 3 以上 100 以下の文字列

入力

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

S

出力

答えを出力せよ。


入力例 1

AABCC

出力例 1

2

(i,j,k)=(1,3,5),(2,3,4)2 つの組が条件を満たします。


入力例 2

ARC

出力例 2

0

入力例 3

AABAAABBAEDCCCD

出力例 3

4

Score : 200 points

Problem Statement

A string S is given.

Find how many places in S have A, B, and C in this order at even intervals.

Specifically, find the number of triples of integers (i,j,k) that satisfy all of the following conditions. Here, |S| denotes the length of S, and S_x denotes the x-th character of S.

  • 1 \leq i < j < k \leq |S|
  • j - i = k - j
  • S_i = A
  • S_j = B
  • S_k = C

Constraints

  • S is an uppercase English string with length between 3 and 100, inclusive.

Input

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

S

Output

Print the answer.


Sample Input 1

AABCC

Sample Output 1

2

There are two triples (i,j,k) = (1,3,5) and (2,3,4) that satisfy the conditions.


Sample Input 2

ARC

Sample Output 2

0

Sample Input 3

AABAAABBAEDCCCD

Sample Output 3

4
E - Martial artist

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

配点 : 300

問題文

高橋君は武術家です。 武術家の覚えられる技は N 個あり、技 1, 2, \ldots, N と名前がついています。 1 \leq i \leq N について、技 i を習得するには時間 T_i の修練が必要で、 さらに、修練の開始時点で技 A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} をすでに習得している必要があります。 ここで、1 \leq j \leq K_i について、A_{i,j} < i であることが保証されます。

高橋君は時刻 0 の時点で技を 1 つも覚えていません。 高橋君は同時に 1 つの技に対する修練しかできず、また、一度始めた修練を途中でやめることもできません。 高橋君が技 N を習得するのに必要な時間の最小値を求めてください。

制約

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq T_i \leq 10^9
  • 0 \leq K_i < i
  • 1 \leq A_{i,j} < i
  • \sum_{i=1}^N K_i \leq 2\times 10^5
  • A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} はすべて異なる。
  • 入力は全て整数である。

入力

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

N
T_1 K_1 A_{1,1} A_{1,2} \ldots A_{1,K_1}
T_2 K_2 A_{2,1} A_{2,2} \ldots A_{2,K_2}
\vdots
T_N K_N A_{N,1} A_{N,2} \ldots A_{N,K_N}

出力

N を習得するのに必要な時間の最小値を出力せよ。


入力例 1

3
3 0
5 1 1
7 1 1

出力例 1

10

例えば高橋君は次のように行動することができます。

  • 高橋君は時刻 0 に技 1 の修練を開始し、時刻 3 に技 1 を習得します。
  • その後、時刻 3 に技 3 の修練を開始し、時刻 10 に技 3 を習得します。

このときが最短で、高橋君が技 3 を習得するのに必要な時間は 3+7=10 となります。 技 3 の習得のためには、技 2 を習得する必要はありません。


入力例 2

5
1000000000 0
1000000000 0
1000000000 0
1000000000 0
1000000000 4 1 2 3 4

出力例 2

5000000000

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

Score : 300 points

Problem Statement

Takahashi is a martial artist. There are N moves that a martial artist can learn, called Move 1, 2, \ldots, N. For each 1 \leq i \leq N, it takes T_i minutes of practice to learn Move i. Additionally, at the beginning of that practice, all of the Moves A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} must be already learned. Here, it is guaranteed that A_{i,j} < i for each 1 \leq j \leq K_i.

Takahashi has not learned any move at time 0. He cannot practice for more than one move simultaneously, nor can he stop a practice he has already started. Find the minimum number of minutes needed for Takahashi to learn Move N.

Constraints

  • 1 \leq N \leq 2\times 10^5
  • 1 \leq T_i \leq 10^9
  • 0 \leq K_i < i
  • 1 \leq A_{i,j} < i
  • \sum_{i=1}^N K_i \leq 2\times 10^5
  • A_{i,1}, A_{i,2}, \ldots, A_{i,K_i} are all distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
T_1 K_1 A_{1,1} A_{1,2} \ldots A_{1,K_1}
T_2 K_2 A_{2,1} A_{2,2} \ldots A_{2,K_2}
\vdots
T_N K_N A_{N,1} A_{N,2} \ldots A_{N,K_N}

Output

Print the minimum number of minutes needed for Takahashi to learn Move N.


Sample Input 1

3
3 0
5 1 1
7 1 1

Sample Output 1

10

Here is one possible plan for Takahashi.

  • At time 0, start practicing for Move 1 to learn Move 1 at time 3.
  • Then, at time 3, start practicing for Move 3 to learn Move 3 at time 10.

Here, Takahashi spends 3+7=10 minutes to learn Move 3, which is the fastest possible. Note that he does not need to learn Move 2 to learn Move 3.


Sample Input 2

5
1000000000 0
1000000000 0
1000000000 0
1000000000 0
1000000000 4 1 2 3 4

Sample Output 2

5000000000

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