A - 202<s>3</s>

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

配点 : 100 点

問題文

英小文字と数字からなる文字列 S が入力されます。
S は 2023 で終わることが保証されます。
S の最後の文字を 4 に変更し、変更後の文字列を出力してください。

制約

  • S は英小文字と数字からなる長さ 4 以上 100 以下の文字列
  • S は 2023 で終わる。

入力

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

S

出力

答えを出力せよ。


入力例 1

hello2023

出力例 1

hello2024

hello2023 の最後の文字を 4 に変更すると、 hello2024 となります。


入力例 2

worldtourfinals2023

出力例 2

worldtourfinals2024

入力例 3

2023

出力例 3

2024

S が 2023 で終わることが保証されていますが、 S が 2023 そのものである場合もあります。


入力例 4

20232023

出力例 4

20232024

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase English letters and digits.
S is guaranteed to end with 2023.
Change the last character of S to 4 and print the modified string.

Constraints

  • S is a string of length between 4 and 100, inclusive, consisting of lowercase English letters and digits.
  • S ends with 2023.

Input

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

S

Output

Print the answer.


Sample Input 1

hello2023

Sample Output 1

hello2024

Changing the last character of hello2023 to 4 yields hello2024.


Sample Input 2

worldtourfinals2023

Sample Output 2

worldtourfinals2024

Sample Input 3

2023

Sample Output 3

2024

S is guaranteed to end with 2023, possibly being 2023 itself.


Sample Input 4

20232023

Sample Output 4

20232024
B - wwwvvvvvv

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

配点 : 100 点

問題文

v と w のみからなる文字列 S が与えられます。

S の中に、下に尖っている部分が何箇所あるかを出力してください(入出力例にある図もご参照ください)。

制約

  • S は v と w のみからなる文字列
  • S の長さは 1 以上 100 以下

入力

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

S

出力

答えを整数として出力せよ。


入力例 1

vvwvw

出力例 1

7

vvwvw

上の画像のように、vvwvw という文字列には下に尖った部分が 7 箇所あります。


入力例 2

v

出力例 2

1

入力例 3

wwwvvvvvv

出力例 3

12

Score : 100 points

Problem Statement

You are given a string S consisting of v and w.

Print the number of "bottoms" in the string S (see the figure at Sample Input/Output).

Constraints

  • S is a string consisting of v and w.
  • The length of S is between 1 and 100, inclusive.

Input

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

S

Output

Print the answer as an integer.


Sample Input 1

vvwvw

Sample Output 1

7

vvwvw

The image above shows the seven "bottoms" in the string vvwvw.


Sample Input 2

v

Sample Output 2

1

Sample Input 3

wwwvvvvvv

Sample Output 3

12
C - Locked Rooms

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

配点 : 200 点

問題文

N + 1 個の部屋が一列に並んでおり、順に 0, 1, \ldots, N の番号が付けられています。

部屋の間には N 個のドアがあり、1, 2, \ldots, N の番号が付けられています。ドア i は部屋 i - 1 と部屋 i の間にあります。

各ドアについて鍵の状態を表す値 L_i が与えられ、L_i = 0 のときドア i の鍵は開いており、L_i = 1 のときドア i の鍵は閉まっています。

2 人の人がおり、1 人は部屋 0 に、もう 1 人は部屋 N にいます。それぞれの人は、ドア i の鍵が開いているときに限り、部屋 i - 1 と部屋 i の間を移動することができます。

このとき、2 人のいずれも到達できない部屋の個数を求めてください。

制約

  • 2 \leq N \leq 100
  • L_i \in \lbrace 0, 1 \rbrace
  • 入力される値はすべて整数

入力

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

N
L_1 L_2 \ldots L_N

出力

答えを出力せよ。


入力例 1

5
0 1 0 0 1

出力例 1

3

2 人のいずれも到達できない部屋は部屋 2, 3, 4 の 3 つです。


入力例 2

3
1 0 1

出力例 2

2

入力例 3

8
0 0 1 1 0 1 0 0

出力例 3

3

Score : 200 points

Problem Statement

There are N + 1 rooms arranged in a line, numbered 0, 1, \ldots, N in order.

Between the rooms, there are N doors numbered 1, 2, \ldots, N. Door i is between rooms i - 1 and i.

For each door, a value L_i representing the lock state is given. When L_i = 0, door i is unlocked, and when L_i = 1, door i is locked.

There are two people, one in room 0 and the other in room N. Each person can move between rooms i - 1 and i only when door i is unlocked.

Find the number of rooms that neither of the two people can reach.

Constraints

  • 2 \leq N \leq 100
  • L_i \in \lbrace 0, 1 \rbrace
  • All input values are integers.

Input

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

N
L_1 L_2 \ldots L_N

Output

Output the answer.


Sample Input 1

5
0 1 0 0 1

Sample Output 1

3

The rooms that neither of the two people can reach are rooms 2, 3, 4, which is 3 rooms.


Sample Input 2

3
1 0 1

Sample Output 2

2

Sample Input 3

8
0 0 1 1 0 1 0 0

Sample Output 3

3
D - Music Player

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

配点 : 200 点

問題文

高橋君は音楽プレイヤーを持っています。はじめ、音量は 0 であり、曲は停止中です。

これから、Q 回の操作を順に行います。i 回目の操作は整数 A_i によって表され、操作の内容は以下の通りです。

  • A_i = 1 のとき、音量を 1 上げる。
  • A_i = 2 のとき、現在の音量が 1 以上であれば音量を 1 下げ、0 であれば何もしない。
  • A_i = 3 のとき、曲が停止中であれば曲を再生し、曲が再生中であれば曲を停止する。

i = 1, 2, \ldots, Q に対して、以下の問題を解いてください。

  • i 回目の操作を終えた直後に音量 3 以上で音楽が再生されているか判定せよ。

制約

  • 1 \leq Q \leq 2 \times 10^5
  • A_i \in \lbrace 1, 2, 3 \rbrace
  • 入力される値はすべて整数

入力

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

Q
A_1
A_2
\vdots
A_Q

出力

Q 行出力せよ。i 行目には、i 回目の操作を終えた直後に音量 3 以上で音楽が再生されているならば Yes を、そうでないならば No を出力せよ。


入力例 1

10
2
1
3
1
3
1
1
3
2
2

出力例 1

No
No
No
No
No
No
No
Yes
Yes
No
  • 1 回目の操作を終えた後、音量は 0 で曲は停止中です。

  • 2 回目の操作を終えた後、音量は 1 で曲は停止中です。

  • 3 回目の操作を終えた後、音量は 1 で曲は再生中です。

  • 4 回目の操作を終えた後、音量は 2 で曲は再生中です。

  • 5 回目の操作を終えた後、音量は 2 で曲は停止中です。

  • 6 回目の操作を終えた後、音量は 3 で曲は停止中です。

  • 7 回目の操作を終えた後、音量は 4 で曲は停止中です。

  • 8 回目の操作を終えた後、音量は 4 で曲は再生中です。

  • 9 回目の操作を終えた後、音量は 3 で曲は再生中です。

  • 10 回目の操作を終えた後、音量は 2 で曲は再生中です。

Score : 200 points

Problem Statement

Takahashi has a music player. Initially, the volume is 0 and the music is stopped.

From now on, Q operations will be performed in order. The i-th operation is represented by an integer A_i, which means the following:

  • If A_i = 1, increase the volume by 1.
  • If A_i = 2, if the current volume is 1 or more, decrease it by 1; if it is 0, do nothing.
  • If A_i = 3, if the music is stopped, play it; if the music is playing, stop it.

For i = 1, 2, \ldots, Q, solve the following problem:

  • Determine whether the music is playing at volume 3 or more immediately after the i-th operation.

Constraints

  • 1 \leq Q \leq 2 \times 10^5
  • A_i \in \lbrace 1, 2, 3 \rbrace
  • All input values are integers.

Input

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

Q
A_1
A_2
\vdots
A_Q

Output

Output Q lines. The i-th line should contain Yes if the music is playing at volume 3 or more immediately after the i-th operation, and No otherwise.


Sample Input 1

10
2
1
3
1
3
1
1
3
2
2

Sample Output 1

No
No
No
No
No
No
No
Yes
Yes
No
  • After the 1-st operation, the volume is 0 and the music is stopped.

  • After the 2-nd operation, the volume is 1 and the music is stopped.

  • After the 3-rd operation, the volume is 1 and the music is playing.

  • After the 4-th operation, the volume is 2 and the music is playing.

  • After the 5-th operation, the volume is 2 and the music is stopped.

  • After the 6-th operation, the volume is 3 and the music is stopped.

  • After the 7-th operation, the volume is 4 and the music is stopped.

  • After the 8-th operation, the volume is 4 and the music is playing.

  • After the 9-th operation, the volume is 3 and the music is playing.

  • After the 10-th operation, the volume is 2 and the music is playing.

E - Enumerate Sequences

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

配点 : 300 点

問題文

以下の条件を満たす長さ N の整数列を辞書順で小さい方から順に全て出力して下さい。

  • i 番目の要素は 1 以上 R_i 以下
  • 総和が K の倍数
数列の辞書順とは? 数列 A = (A_1, \ldots, A_{|A|}) が B = (B_1, \ldots, B_{|B|}) より辞書順で真に小さいとは、下記の 1. と 2. のどちらかが成り立つことを言います。
  1. |A|<|B| かつ (A_{1},\ldots,A_{|A|}) = (B_1,\ldots,B_{|A|}) である。
  2. ある整数 1\leq i\leq \min\{|A|,|B|\} が存在して、下記の 2 つがともに成り立つ。
    • (A_{1},\ldots,A_{i-1}) = (B_1,\ldots,B_{i-1})
    • A_i < B_i

制約

  • 入力は全て整数
  • 1 \le N \le 8
  • 2 \le K \le 10
  • 1 \le R_i \le 5

入力

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

N K
R_1 R_2 \dots R_N

出力

出力すべき数列が X 個あり、そのうち i 個目が A_i=(A_{i,1},A_{i,2},\dots,A_{i,N}) であったとき、答えを以下の形式で出力せよ。

A_{1,1} A_{1,2} \dots A_{1,N}
A_{2,1} A_{2,2} \dots A_{2,N}
\vdots
A_{X,1} A_{X,2} \dots A_{X,N}

入力例 1

3 2
2 1 3

出力例 1

1 1 2
2 1 1
2 1 3

出力すべき数列は 3 個で、辞書順で (1,1,2),(2,1,1),(2,1,3) です。


入力例 2

1 2
1

出力例 2


出力すべき数列が無い場合もあります。
この場合、出力は空で構いません。


入力例 3

5 5
2 3 2 3 2

出力例 3

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

Score : 300 points

Problem Statement

Print all integer sequences of length N that satisfy the following conditions, in ascending lexicographical order.

  • The i-th element is between 1 and R_i, inclusive.
  • The sum of all elements is a multiple of K.
What is lexicographical order for sequences? A sequence A = (A_1, \ldots, A_{|A|}) is lexicographically smaller than B = (B_1, \ldots, B_{|B|}) if either 1. or 2. below holds:
  1. |A|<|B| and (A_{1},\ldots,A_{|A|}) = (B_1,\ldots,B_{|A|}).
  2. There exists an integer 1\leq i\leq \min\{|A|,|B|\} such that both of the following are true:
    • (A_{1},\ldots,A_{i-1}) = (B_1,\ldots,B_{i-1})
    • A_i < B_i

Constraints

  • All input values are integers.
  • 1 \le N \le 8
  • 2 \le K \le 10
  • 1 \le R_i \le 5

Input

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

N K
R_1 R_2 \dots R_N

Output

Print the answer in the following format, where X is the number of sequences to print, the i-th of which is A_i=(A_{i,1},A_{i,2},\dots,A_{i,N}):

A_{1,1} A_{1,2} \dots A_{1,N}
A_{2,1} A_{2,2} \dots A_{2,N}
\vdots
A_{X,1} A_{X,2} \dots A_{X,N}

Sample Input 1

3 2
2 1 3

Sample Output 1

1 1 2
2 1 1
2 1 3

There are three sequences to be printed, which are (1,1,2),(2,1,1),(2,1,3) in lexicographical order.


Sample Input 2

1 2
1

Sample Output 2


There may be no sequences to print.
In this case, the output can be empty.


Sample Input 3

5 5
2 3 2 3 2

Sample Output 3

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