A - Secret Numbers

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

配点 : 100 点

問題文

英小文字と数字のみからなる文字列 S が与えられます。

S から数字である文字だけを取り出し、元の順序のまま並べた文字列を求めてください。

制約

  • S は英小文字と数字のみからなる長さ 1 以上 50 以下の文字列

入力

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

S

出力

答えを出力せよ。


入力例 1

abc462

出力例 1

462

abc462 に含まれる数字は 4, 6, 2 です。これらを元の順序のまま連結すると 462 となります。したがって、462 を出力してください。


入力例 2

codequeen

出力例 2


codequeen に数字は含まれないので空文字列を出力してください。


入力例 3

31415

出力例 3

31415

入力例 4

10plus2is12

出力例 4

10212

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English letters and digits.

Extract only the digit characters from S and output the string formed by arranging them in their original order.

Constraints

  • S is a string of length between 1 and 50, inclusive, consisting of lowercase English letters and digits.

Input

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

S

Output

Output the answer.


Sample Input 1

abc462

Sample Output 1

462

The digits contained in abc462 are 4, 6, 2. Concatenating them in their original order gives 462. Thus, output 462.


Sample Input 2

codequeen

Sample Output 2


codequeen contains no digits, so output the empty string.


Sample Input 3

31415

Sample Output 3

31415

Sample Input 4

10plus2is12

Sample Output 4

10212
B - Same

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

配点 : 100 点

問題文

N 個の整数 A _ 1,A _ 2,\ldots,A _ N が与えられます。

これらの値がすべて等しいならば Yes 、そうでなければ No と出力してください。

制約

  • 2\leq N\leq100
  • 1\leq A _ i\leq100\ (1\leq i\leq N)
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \ldots A _ N

出力

与えられた A _ 1,A _ 2,\ldots,A _ N の値がすべて等しいなら Yes を、そうでなければ No を 1 行で出力せよ。


入力例 1

3
3 2 4

出力例 1

No

A _ 1\neq A _ 2 なので、No と出力してください。


入力例 2

4
3 3 3 3

出力例 2

Yes

A _ 1=A _ 2=A _ 3=A _ 4 なので、Yes と出力してください。


入力例 3

10
73 8 55 26 97 48 37 47 35 55

出力例 3

No

Score : 100 points

Problem Statement

You are given N integers A _ 1,A _ 2,\ldots,A _ N.

If their values are all equal, print Yes; otherwise, print No.

Constraints

  • 2\leq N\leq100
  • 1\leq A _ i\leq100\ (1\leq i\leq N)
  • All input values are integers.

Input

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

N
A _ 1 A _ 2 \ldots A _ N

Output

Print a single line containing Yes if the values of the given A _ 1,A _ 2,\ldots,A _ N are all equal, and No otherwise.


Sample Input 1

3
3 2 4

Sample Output 1

No

We have A _ 1\neq A _ 2, so you should print No.


Sample Input 2

4
3 3 3 3

Sample Output 2

Yes

We have A _ 1=A _ 2=A _ 3=A _ 4, so you should print Yes.


Sample Input 3

10
73 8 55 26 97 48 37 47 35 55

Sample Output 3

No
C - KEYENCE building

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

配点 : 200 点

問題文

1 から N の番号がついた N 人の人がいます。

人 i はキーエンス本社ビルの建築面積を S_i 平方メートルであると予想しました。

キーエンス本社ビルは下図のような形をしています。ただし、a,b はある 正の整数 です。
つまり、キーエンス本社ビルの建築面積は 4ab+3a+3b 平方メートルと表されます。

N 人のうち、この情報のみによって、予想した面積が確実に誤りであるとわかる人数を求めてください。

キーエンス本社ビル見取り図

制約

  • 1 \leq N \leq 20
  • 1 \leq S_i \leq 1000
  • 入力に含まれる値は全て整数である

入力

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

N
S_1 \ldots S_N

出力

答えを出力せよ。


入力例 1

3
10 20 39

出力例 1

1

a=1,b=1 のとき面積は 10 平方メートル、a=2,b=3 のとき面積は 39 平方メートルとなります。

しかし a,b がどのような正の整数であったとしても面積が 20 平方メートルになることはありません。

よって、人 2 の予想だけは確実に誤りであることがわかります。


入力例 2

5
666 777 888 777 666

出力例 2

3

Score : 200 points

Problem Statement

There are N people numbered 1 to N.

Person i guessed the building area of KEYENCE headquarters building to be S_i square meters.

The shape of KEYENCE headquarters building is shown below, where a and b are some positive integers.
That is, the building area of the building can be represented as 4ab+3a+3b.

Based on just this information, how many of the N people are guaranteed to be wrong in their guesses?

Sketch of KEYENCE headquarters building

Constraints

  • 1 \leq N \leq 20
  • 1 \leq S_i \leq 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
S_1 \ldots S_N

Output

Print the answer.


Sample Input 1

3
10 20 39

Sample Output 1

1

The area would be 10 square meters if a=1,b=1, and 39 square meters if a=2,b=3.

However, no pair of positive integers a and b would make the area 20 square meters.

Thus, we can only be sure that Person 2 guessed wrong.


Sample Input 2

5
666 777 888 777 666

Sample Output 2

3
D - Chessboard

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

配点 : 200 点

問題文

チェス盤のどこにコマが置かれているか答えてください。

縦 8 マス、横 8 マスのグリッドがあります。グリッドの各マスには、次のルールで定められる長さ 2 の文字列の名前がついています。

  • 左から 1 列目にあるマスの名前の 1 文字目は a である。同様に、左から 2,3,\ldots,8 列目にあるマスの名前の 1 文字目は b, c, d, e, f, g, h である。
  • 下から 1 行目にあるマスの名前の 2 文字目は 1 である。同様に、下から 2,3,\ldots,8 行目にあるマスの名前の 2 文字目は 2, 3, 4, 5, 6, 7, 8 である。

例えば、グリッドの左下のマスの名前は a1、右下のマスの名前は h1、右上のマスの名前は h8 です。

グリッドの状態を表す長さ 8 の 8 つの文字列 S_1,\ldots,S_8 が与えられます。
S_i の j 文字目は、グリッドの上から i 行目 左から j 列目のマスにコマが置かれているとき *、置かれていないとき . であり、S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在します。
コマが置かれているマスの名前を求めてください。

制約

  • S_i は . および * のみからなる長さ 8 の文字列である
  • S_1,\ldots,S_8 の中に文字 * はちょうど 1 つ存在する。

入力

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

S_1
S_2
S_3
S_4
S_5
S_6
S_7
S_8

出力

答えを出力せよ。


入力例 1

........
........
........
........
........
........
........
*.......

出力例 1

a1

問題文中で説明したとおり、グリッドの左下のマスの名前は a1 です。


入力例 2

........
........
........
........
........
.*......
........
........

出力例 2

b3

Score : 200 points

Problem Statement

Locate a piece on a chessboard.

We have a grid with 8 rows and 8 columns of squares. Each of the squares has a 2-character name determined as follows.

  • The first character of the name of a square in the 1-st column from the left is a. Similarly, the first character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th column from the left is b, c, d, e, f, g, h, respectively.
  • The second character of the name of a square in the 1-st row from the bottom is 1. Similarly, the second character of the name of a square in the 2-nd, 3-rd, \ldots, 8-th row from the bottom is 2, 3, 4, 5, 6, 7, 8, respectively.

For instance, the bottom-left square is named a1, the bottom-right square is named h1, and the top-right square is named h8.

You are given 8 strings S_1,\ldots,S_8, each of length 8, representing the state of the grid.
The j-th character of S_i is * if the square at the i-th row from the top and j-th column from the left has a piece on it, and . otherwise. The character * occurs exactly once among S_1,\ldots,S_8. Find the name of the square that has a piece on it.

Constraints

  • S_i is a string of length 8 consisting of . and*.
  • The character * occurs exactly once among S_1,\ldots,S_8.

Input

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

S_1
S_2
S_3
S_4
S_5
S_6
S_7
S_8

Output

Print the answer.


Sample Input 1

........
........
........
........
........
........
........
*.......

Sample Output 1

a1

As explained in the problem statement, the bottom-left square is named a1.


Sample Input 2

........
........
........
........
........
.*......
........
........

Sample Output 2

b3
E - Brackets Stack Query

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

配点 : 300 点

問題文

文字列 T が次の条件を満たすとき、T を良い括弧列と呼びます。

  • 次の操作を 0 回以上繰り返すことで T を空文字列にすることができる。

    • T に(連続な)部分文字列として含まれる () を選び、これを取り除く。

例えば () や (()()), および空文字列は良い括弧列ですが、)()( や ))) は良い括弧列ではありません。

文字列 S があります。S ははじめ空文字列です。
以下で説明されるクエリを与えられる順に Q 個処理してください。そして、各クエリの直後に S が良い括弧列であるかを判定してください。
クエリは次の 2 種類です。

  • 1 c: 文字 c が与えられる。c は ( または ) である。c を S の末尾に追加する。
  • 2: S の末尾の文字を削除する。この時、S は空文字列でないことが保証される。

制約

  • 1 \leq Q \leq 8 \times 10^5
  • 1 種類目のクエリの c は ( または )
  • 2 種類目のクエリを与えられた時点で S は空でないことが保証される
  • Q は整数

入力

入力は以下の形式で標準入力から与えられる。ここで \mathrm{query}_i は i 番目のクエリを意味する。

Q
\mathrm{query}_1 
\mathrm{query}_2
\vdots
\mathrm{query}_Q

各クエリは以下の 2 種類のいずれかの形式で与えられる。

1 c
2

出力

Q 行出力せよ。i 行目には、i 番目のクエリを処理した直後の文字列 S が良い括弧列である場合は Yes を、そうでない場合は No を出力せよ。


入力例 1

8
1 (
2
1 (
1 )
2
1 (
1 )
1 )

出力例 1

No
Yes
No
Yes
No
No
No
Yes

1 番目のクエリを処理した直後の S は ( で、これは良い括弧列ではありません。
2 番目のクエリを処理した直後の S は空文字列で、これは良い括弧列です。
3 番目のクエリを処理した直後の S は ( で、これは良い括弧列ではありません。
4 番目のクエリを処理した直後の S は () で、これは良い括弧列です。
5 番目のクエリを処理した直後の S は ( で、これは良い括弧列ではありません。
6 番目のクエリを処理した直後の S は (( で、これは良い括弧列ではありません。
7 番目のクエリを処理した直後の S は (() で、これは良い括弧列ではありません。
8 番目のクエリを処理した直後の S は (()) で、これは良い括弧列です。

Score : 300 points

Problem Statement

A string T is called a good bracket sequence if and only if it satisfies the following condition:

  • T can be made into an empty string by repeating the following operation zero or more times:

    • Choose () contained in T as a (contiguous) substring and remove it.

For example, (), (()()), and the empty string are good bracket sequences, but )()( and ))) are not good bracket sequences.

There is a string S. Initially, S is an empty string.
Process Q queries in the order they are given. After each query, determine whether S is a good bracket sequence.
There are two types of queries:

  • 1 c: A character c is given. c is either ( or ). Append c to the end of S.
  • 2: Remove the last character of S. It is guaranteed that S is not an empty string at this time.

Constraints

  • 1 \leq Q \leq 8 \times 10^5
  • c in queries of the first type is ( or ).
  • It is guaranteed that S is not empty when a query of the second type is given.
  • Q is an integer.

Input

The input is given from Standard Input in the following format, where \mathrm{query}_i denotes the i-th query.

Q
\mathrm{query}_1 
\mathrm{query}_2
\vdots
\mathrm{query}_Q

Each query is given in one of the following two formats:

1 c
2

Output

Output Q lines. The i-th line should contain Yes if the string S immediately after processing the i-th query is a good bracket sequence, and No otherwise.


Sample Input 1

8
1 (
2
1 (
1 )
2
1 (
1 )
1 )

Sample Output 1

No
Yes
No
Yes
No
No
No
Yes

S immediately after processing the 1st query is (, which is not a good bracket sequence.
S immediately after processing the 2nd query is an empty string, which is a good bracket sequence.
S immediately after processing the 3rd query is (, which is not a good bracket sequence.
S immediately after processing the 4th query is (), which is a good bracket sequence.
S immediately after processing the 5th query is (, which is not a good bracket sequence.
S immediately after processing the 6th query is ((, which is not a good bracket sequence.
S immediately after processing the 7th query is ((), which is not a good bracket sequence.
S immediately after processing the 8th query is (()), which is a good bracket sequence.