A - Shift

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

長さ N の数列 A = (A_1, A_2, \dots, A_N) が与えられます。
あなたは次の操作をちょうど K 回行います。

  • A の先頭の要素を取り除き、A の末尾に 0 を挿入する。

操作を行った後の A の要素をすべて出力してください。

制約

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

入力

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

N K
A_1 A_2 \dots A_N

出力

操作を行った後の A の要素を空白区切りで 1 行に出力せよ。


入力例 1

3 2
2 7 8

出力例 1

8 0 0

操作を行う前は A = (2, 7, 8) です。
操作を 1 回行った時点では A = (7, 8, 0) です。
操作を 2 回行った時点では A = (8, 0, 0) です。
よって (8, 0, 0) が答えです。


入力例 2

3 4
9 9 9

出力例 2

0 0 0

入力例 3

9 5
1 2 3 4 5 6 7 8 9

出力例 3

6 7 8 9 0 0 0 0 0

Score : 100 points

Problem Statement

You are given a sequence A = (A_1, A_2, \dots, A_N) of length N.
You perform the following operation exactly K times:

  • remove the initial element of A and append a 0 to the tail of A.

Print all the elements of A after the operations.

Constraints

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

Input

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

N K
A_1 A_2 \dots A_N

Output

Print the elements of A after the operations in one line, separated by spaces.


Sample Input 1

3 2
2 7 8

Sample Output 1

8 0 0

Before the operations, A = (2, 7, 8).
After performing the operation once, A = (7, 8, 0).
After performing the operation twice, A = (8, 0, 0).
Thus, (8, 0, 0) is the answer.


Sample Input 2

3 4
9 9 9

Sample Output 2

0 0 0

Sample Input 3

9 5
1 2 3 4 5 6 7 8 9

Sample Output 3

6 7 8 9 0 0 0 0 0
B - Misjudge the Time

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

高橋君は置き時計を買いました。
この時計は、現在の時刻が 24 時制で \mathrm{AB}\mathrm{CD} 分であるときに図 1 のように時刻を表します。
例えば図 2 では、時計は 758 分を示しています。

時刻の表示方法をより形式的に説明すると次のようになります。
現在の時刻が 24 時制で hm 分であるとします。ここで 24 時制とは、時間を 0 以上 23 以下の整数で、分を 0 以上 59 以下の整数で表す時刻の表現方法を言います。
h10 の位を A, 1 の位を B, m10 の位を C, 1 の位を D とします。(ただし h, m1 桁である場合は先行ゼロを追加して考えます。)
このとき時計は左上に A を、左下に B を、右上に C を、右下に D を表示します。

image

高橋君は、次の条件を満たす時刻を 見間違えやすい時刻 と呼ぶことにしました。

  • 時計の表示の右上と左下を入れ替えても、それに対応する 24 時制の時刻が存在する。

例えば 図 32013 分を示していますが、時計の表示の右上と左下を入れ替えると 213 分を意味する表示になります。よって 2013 分は見間違えやすい時刻です。

今、時計は HM 分を示しています。
(現時点も含めて)以降はじめて訪れる見間違えやすい時刻を 24 時制で答えてください。

制約

  • 0 \leq H \leq 23
  • 0 \leq M \leq 59
  • H, M は整数

入力

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

H M

出力

答えを hm 分とする。ここで h, m0 \leq h \leq 23, 0 \leq m \leq 59 である必要がある。
このとき h, m を以下の形式で出力せよ。

h m

なお、h, m2 桁に揃えるために先行ゼロをつけた形式で出力しても正答と見なされる。


入力例 1

1 23

出力例 1

1 23

123 分は見間違えやすい時刻です。なぜならば、時計の表示の右上と左下を入れ替えると 213 分を意味する表示になるからです。
よって答えは 123 分です。
なお、01 23 のように先行ゼロをつけた形式で出力しても正答として扱われます。


入力例 2

19 57

出力例 2

20 0

1957 分以降ではじめて訪れる見間違えやすい時刻は 200 分です。


入力例 3

20 40

出力例 3

21 0

24 時制では 240 分という表記は合法でないのに注意してください。

Score : 200 points

Problem Statement

Takahashi bought a table clock.
The clock shows the time as shown in Figure 1 at \mathrm{AB}:\mathrm{CD} in the 24-hour system.
For example, the clock in Figure 2 shows 7:58.

The format of the time is formally described as follows.
Suppose that the current time is m minutes past h in the 24-hour system. Here, the 24-hour system represents the hour by an integer between 0 and 23 (inclusive), and the minute by an integer between 0 and 59 (inclusive).
Let A be the tens digit of h, B be the ones digit of h, C be the tens digit of m, and D be the ones digit of m. (Here, if h has only one digit, we consider that it has a leading zero; the same applies to m.)
Then, the clock shows A in its top-left, B in its bottom-left, C in its top-right, and D in its bottom-right.

image

Takahashi has decided to call a time a confusing time if it satisfies the following condition:

  • after swapping the top-right and bottom-left digits on the clock, it still reads a valid time in the 24-hour system.

For example, the clock in Figure 3 shows 20:13. After swapping its top-right and bottom-left digits, it reads 21:03. Thus, 20:13 is a confusing time.

The clock now shows H:M.
Find the next confusing time (including now) in the 24-hour system.

Constraints

  • 0 \leq H \leq 23
  • 0 \leq M \leq 59
  • H and M are integers.

Input

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

H M

Output

Let h:m be the answer, where h and m must satisfy 0 \leq h \leq 23 and 0 \leq m \leq 59.
Print h and m in the following format:

h m

Your answer is considered correct even if h contains a leading zero to represent it as a 2-digit integer; the same applies to m.


Sample Input 1

1 23

Sample Output 1

1 23

1:23 is a confusing time because, after swapping its top-right and bottom-left digits on the clock, it reads 2:13.
Thus, the answer is 1:23.
Your answer is considered correct even if you print 01 23 with a leading zero.


Sample Input 2

19 57

Sample Output 2

20 0

The next confusing time after 19:57 is 20:00.


Sample Input 3

20 40

Sample Output 3

21 0

Note that 24:00 is an invalid notation in the 24-hour system.

C - FF

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

高橋君が運営する SNS「Twidai」にはユーザー 1 からユーザー N までの N 人のユーザーがいます。 Twidai では、ユーザーは別のユーザーをフォローすることや、フォローを解除することができます。

Twidai がサービスを開始してから、Q 回の操作が行われました。 i 回目 (1\leq i\leq Q) の操作は 3 つの整数 T _ i, A _ i, B _ i で表され、それぞれ次のような操作を表します。

  • T _ i=1 のとき:ユーザー A _ i がユーザー B _ i をフォローしたことを表す。この操作の時点でユーザー A _ i がユーザー B _ i をフォローしている場合、ユーザーのフォロー状況に変化はない。
  • T _ i=2 のとき:ユーザー A _ i がユーザー B _ i のフォローを解除したことを表す。この操作の時点でユーザー A _ i がユーザー B _ i をフォローしていない場合、ユーザーのフォロー状況に変化はない。
  • T _ i=3 のとき:ユーザー A _ i とユーザー B _ i が互いにフォローしているかをチェックすることを表す。この操作の時点でユーザー A _ i がユーザー B _ i をフォローしており、かつユーザー B _ i がユーザー A _ i をフォローしているとき、このチェックに対して Yes と答え、そうでないときこのチェックに対して No と答える必要がある。

サービス開始時には、どのユーザーも他のユーザーをフォローしていません。

すべての T _ i=3 であるような操作に対して、i が小さいほうから順番に正しい答えを出力してください。

制約

  • 2 \leq N \leq 10 ^ 9
  • 1 \leq Q \leq 2\times10 ^ 5
  • T _ i=1,2,3\ (1\leq i\leq Q)
  • 1 \leq A _ i \leq N\ (1\leq i\leq Q)
  • 1 \leq B _ i \leq N\ (1\leq i\leq Q)
  • A _ i\neq B _ i\ (1\leq i\leq Q)
  • T _ i=3 となる i\ (1\leq i\leq Q) が存在する
  • 入力される値はすべて整数

入力

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

N Q
T _ 1 A _ 1 B _ 1
T _ 2 A _ 2 B _ 2
\vdots
T _ Q A _ Q B _ Q

出力

T _ i=3 であるような i\ (1\leq i\leq Q) の個数を X として、X 行出力せよ。 j\ (1\leq j\leq X) 行目には j 番目の T _ i=3 であるような操作に対する答えを出力せよ。


入力例 1

3 9
1 1 2
3 1 2
1 2 1
3 1 2
1 2 3
1 3 2
3 1 3
2 1 2
3 1 2

出力例 1

No
Yes
No
No

Twidai には 3 人のユーザーがいます。 9 回の操作はそれぞれ次のようになっています。

  • ユーザー 1 がユーザー 2 をフォローします。そのほかにフォローしている/されているユーザーはいません。
  • ユーザー 1 とユーザー 2 が互いにフォローしているかチェックします。ユーザー 1 はユーザー 2 をフォローしていますが、ユーザー 2 はユーザー 1 をフォローしていません。この操作への正しい答えは No です。
  • ユーザー 2 がユーザー 1 をフォローします。
  • ユーザー 1 とユーザー 2 が互いにフォローしているかチェックします。ユーザー 1 はユーザー 2 をフォローしており、ユーザー 2 はユーザー 1 をフォローしています。この操作への正しい答えは Yes です。
  • ユーザー 2 がユーザー 3 をフォローします。
  • ユーザー 3 がユーザー 2 をフォローします。
  • ユーザー 1 とユーザー 3 が互いにフォローしているかチェックします。ユーザー 1 はユーザー 3 をフォローしておらず、ユーザー 3 もユーザー 1 をフォローしていません。この操作への正しい答えは No です。
  • ユーザー 1 がユーザー 2 のフォローを解除します。
  • ユーザー 1 とユーザー 2 が互いにフォローしているかチェックします。ユーザー 2 はユーザー 1 をフォローしていますが、ユーザー 1 はユーザー 2 をフォローしていません。この操作への正しい答えは No です。

入力例 2

2 8
1 1 2
1 2 1
3 1 2
1 1 2
1 1 2
1 1 2
2 1 2
3 1 2

出力例 2

Yes
No

同じユーザーに対して何度もフォロー操作をする場合があります。


入力例 3

10 30
3 1 6
3 5 4
1 6 1
3 1 7
3 8 4
1 1 6
2 4 3
1 6 5
1 5 6
1 1 8
1 8 1
2 3 10
1 7 6
3 5 6
1 6 7
3 6 7
1 9 5
3 8 6
3 3 8
2 6 9
1 7 1
3 10 8
2 9 2
1 10 9
2 6 10
2 6 8
3 1 6
3 1 8
2 8 5
1 9 10

出力例 3

No
No
No
No
Yes
Yes
No
No
No
Yes
Yes

Score : 300 points

Problem Statement

Takahashi runs an SNS "Twidai," which has N users from user 1 through user N. In Twidai, users can follow or unfollow other users.

Q operations have been performed since Twidai was launched. The i-th (1\leq i\leq Q) operation is represented by three integers T_i, A_i, and B_i, whose meanings are as follows:

  • If T_i = 1: it means that user A_i follows user B_i. If user A_i is already following user B_i at the time of this operation, it does not make any change.
  • If T_i = 2: it means that user A_i unfollows user B_i. If user A_i is not following user B_i at the time of this operation, it does not make any change.
  • If T_i = 3: it means that you are asked to determine if users A_i and B_i are following each other. You need to print Yes if user A_i is following user B_i and user B_i is following user A_i, and No otherwise.

When the service was launched, no users were following any users.

Print the correct answers for all operations such that T_i = 3 in ascending order of i.

Constraints

  • 2 \leq N \leq 10 ^ 9
  • 1 \leq Q \leq 2\times10 ^ 5
  • T _ i=1,2,3\ (1\leq i\leq Q)
  • 1 \leq A _ i \leq N\ (1\leq i\leq Q)
  • 1 \leq B _ i \leq N\ (1\leq i\leq Q)
  • A _ i\neq B _ i\ (1\leq i\leq Q)
  • There exists i\ (1\leq i\leq Q) such that T _ i=3.
  • All values in the input are integers.

Input

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

N Q
T _ 1 A _ 1 B _ 1
T _ 2 A _ 2 B _ 2
\vdots
T _ Q A _ Q B _ Q

Output

Print X lines, where X is the number of i's (1\leq i\leq Q) such that T _ i=3. The j-th (1\leq j\leq X) line should contain the answer to the j-th operation such that T _ i=3.


Sample Input 1

3 9
1 1 2
3 1 2
1 2 1
3 1 2
1 2 3
1 3 2
3 1 3
2 1 2
3 1 2

Sample Output 1

No
Yes
No
No

Twidai has three users. The nine operations are as follows.

  • User 1 follows user 2. No other users are following or followed by any users.
  • Determine if users 1 and 2 are following each other. User 1 is following user 2, but user 2 is not following user 1, so No is the correct answer to this operation.
  • User 2 follows user 1.
  • Determine if users 1 and 2 are following each other. User 1 is following user 2, and user 2 is following user 1, so Yes is the correct answer to this operation.
  • User 2 follows user 3.
  • User 3 follows user 2.
  • Determine if users 1 and 3 are following each other. User 1 is not following user 3, and user 3 is not following user 1, so No is the correct answer to this operation.
  • User 1 unfollows user 2.
  • Determine if users 1 and 2 are following each other. User 2 is following user 1, but user 1 is not following user 2, so No is the correct answer to this operation.

Sample Input 2

2 8
1 1 2
1 2 1
3 1 2
1 1 2
1 1 2
1 1 2
2 1 2
3 1 2

Sample Output 2

Yes
No

A user may follow the same user multiple times.


Sample Input 3

10 30
3 1 6
3 5 4
1 6 1
3 1 7
3 8 4
1 1 6
2 4 3
1 6 5
1 5 6
1 1 8
1 8 1
2 3 10
1 7 6
3 5 6
1 6 7
3 6 7
1 9 5
3 8 6
3 3 8
2 6 9
1 7 1
3 10 8
2 9 2
1 10 9
2 6 10
2 6 8
3 1 6
3 1 8
2 8 5
1 9 10

Sample Output 3

No
No
No
No
Yes
Yes
No
No
No
Yes
Yes
D - All Assign Point Add

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

長さ N の数列 A = (A_1, A_2, \dots, A_N) が与えられます。

Q 個のクエリが与えられるので、順番にすべて処理してください。 q 番目 (1\leq q\leq Q) のクエリは以下の 3 つのいずれかの形式で、それぞれ次のようなクエリを表します。

  • 1\ x _ qA のすべての要素に x _ q を代入する。
  • 2\ i _ q\ x _ qA _ {i _ q}x _ q を加える。
  • 3\ i _ qA _ {i _ q} の値を出力する。

制約

  • 1 \leq N \leq 2\times10^5
  • 1 \leq Q \leq 2\times10^5
  • 0 \leq A _ i \leq 10^9\ (1\leq i\leq N)
  • q 番目 (1\leq q\leq Q) のクエリが 2 番目もしくは 3 番目の形式のとき、1 \leq i _ q \leq N
  • q 番目 (1\leq q\leq Q) のクエリが 1 番目もしくは 2 番目の形式のとき、0 \leq x _ q \leq 10^9
  • 3 番目の形式のクエリが存在する
  • 入力される値はすべて整数

入力

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

N
A_1 A_2 \dots A_N
Q
\operatorname{query}_1
\operatorname{query}_2
\vdots
\operatorname{query}_Q

ただし、\operatorname{query}_qq 番目のクエリであり、1 x, 2 i x, 3 i の形式のいずれかで与えられる。

出力

\operatorname{query}_q3 番目の形式であるような q\ (1\leq q\leq Q) の個数を X として、X 行出力せよ。 j\ (1\leq j\leq X) 行目にはそのようなクエリのうち j 番目のクエリに対する答えを出力せよ。


入力例 1

5
3 1 4 1 5
6
3 2
2 3 4
3 3
1 1
2 3 4
3 3

出力例 1

1
8
5

はじめ、A=(3,1,4,1,5) です。 それぞれのクエリでは、以下のような処理が行われます。

  • A_2=1 なので、1 を出力します。
  • A_34 を加えます。A=(3,1,8,1,5) となります。
  • A_3=8 なので、8 を出力します。
  • A の要素すべてに 1 を代入します。A=(1,1,1,1,1) となります。
  • A_34 を加えます。A=(1,1,5,1,1) となります。
  • A_3=5 なので、5 を出力します。

入力例 2

1
1000000000
8
2 1 1000000000
2 1 1000000000
2 1 1000000000
2 1 1000000000
2 1 1000000000
2 1 1000000000
2 1 1000000000
3 1

出力例 2

8000000000

A の要素の値が 32\operatorname{bit} 整数に収まらない可能性があることに注意してください。


入力例 3

10
1 8 4 15 7 5 7 5 8 0
20
2 7 0
3 7
3 8
1 7
3 3
2 4 4
2 4 9
2 10 5
1 10
2 4 2
1 10
2 3 1
2 8 11
2 3 14
2 1 9
3 8
3 8
3 1
2 6 5
3 7

出力例 3

7
5
7
21
21
19
10

Score : 400 points

Problem Statement

You are given a sequence A = (A_1, A_2, \dots, A_N) of length N.

Given Q queries, process all of them in order. The q-th (1\leq q\leq Q) query is in one of the following three formats, which represents the following queries:

  • 1\ x _ q: assign x_q to every element of A.
  • 2\ i _ q\ x _ q: add x_q to A _ {i _ q}.
  • 3\ i _ q: print the value of A _ {i _ q}.

Constraints

  • 1 \leq N \leq 2\times10^5
  • 1 \leq Q \leq 2\times10^5
  • 0 \leq A _ i \leq 10^9\ (1\leq i\leq N)
  • If the q-th (1\leq q\leq Q) query is in the second or third format, 1 \leq i _ q \leq N.
  • If the q-th (1\leq q\leq Q) query is in the first or second format, 0 \leq x _ q \leq 10^9.
  • There exists a query in the third format.
  • All values in the input are integers.

Input

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

N
A_1 A_2 \dots A_N
Q
\operatorname{query}_1
\operatorname{query}_2
\vdots
\operatorname{query}_Q

Here, \operatorname{query}_q denotes the q-th query, which is in one of following formats: 1 x, 2 i x, and 3 i.

Output

Print X lines, where X is the number of q's (1\leq q\leq Q) such that \operatorname{query}_q is in the third format. The j-th (1\leq j\leq X) line should contain the answer to the j-th such query.


Sample Input 1

5
3 1 4 1 5
6
3 2
2 3 4
3 3
1 1
2 3 4
3 3

Sample Output 1

1
8
5

Initially, A=(3,1,4,1,5). The queries are processed as follows:

  • A_2=1, so print 1.
  • Add 4 to A_3, making A=(3,1,8,1,5).
  • A_3=8, so print 8.
  • Assign 1 to every element of A, making A=(1,1,1,1,1).
  • Add 4 to A_3, making A=(1,1,5,1,1).
  • A_3=5, so print 5.

Sample Input 2

1
1000000000
8
2 1 1000000000
2 1 1000000000
2 1 1000000000
2 1 1000000000
2 1 1000000000
2 1 1000000000
2 1 1000000000
3 1

Sample Output 2

8000000000

Note that the elements of A may not fit into a 32-bit integer type.


Sample Input 3

10
1 8 4 15 7 5 7 5 8 0
20
2 7 0
3 7
3 8
1 7
3 3
2 4 4
2 4 9
2 10 5
1 10
2 4 2
1 10
2 3 1
2 8 11
2 3 14
2 1 9
3 8
3 8
3 1
2 6 5
3 7

Sample Output 3

7
5
7
21
21
19
10
E - Grid Filling

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

H 行、横 W 列のグリッドがあります。 上から i 行目、左から j 列目のマスを (i,j) で表します。 (i,j)\ (1\leq i\leq H,1\leq j\leq W) には 1 以上 N 以下の整数 A _ {i,j} が書かれています。

整数 h,w が与えられます。0\leq k\leq H-h,0\leq l\leq W-w を満たすすべての (k,l) の組について、次の問題を解いてください。

  • k\lt i\leq k+h,l\lt j\leq l+w を満たす (i,j) を塗りつぶしたとき、塗りつぶされていないマスに書かれている数が何種類あるか求めよ。

ただし、問題を解く際に実際にマスを塗りつぶすことはない(各問題が独立である)ことに注意してください。

制約

  • 1 \leq H,W,N \leq 300
  • 1 \leq h \leq H
  • 1 \leq w \leq W
  • (h,w)\neq(H,W)
  • 1 \leq A _ {i,j} \leq N\ (1\leq i\leq H,1\leq j\leq W)
  • 入力される値はすべて整数

入力

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

H W N h w
A _ {1,1} A _ {1,2} \dots A _ {1,W}
A _ {2,1} A _ {2,2} \dots A _ {2,W}
\vdots
A _ {H,1} A _ {H,2} \dots A _ {H,W}

出力

(k,l) に対する答えを \operatorname{ans}_{k,l} として、以下の形式で出力せよ。

\operatorname{ans} _ {0,0} \operatorname{ans} _ {0,1} \dots \operatorname{ans} _ {0,W-w}
\operatorname{ans} _ {1,0} \operatorname{ans} _ {1,1} \dots \operatorname{ans} _ {1,W-w}
\vdots
\operatorname{ans} _ {H-h,0} \operatorname{ans} _ {H-h,1} \dots \operatorname{ans} _ {H-h,W-w}

入力例 1

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

出力例 1

4 4 3
5 3 4

与えられた盤面は下の図のようになります。

例えば、(k,l)=(0,0) のときは塗りつぶされていないマスに書かれている数は 1,3,4,54 種類なので、4 が答えになります。


入力例 2

5 6 9 3 4
7 1 5 3 9 5
4 5 4 5 1 2
6 1 6 2 9 7
4 7 1 5 8 8
3 4 3 3 5 3

出力例 2

8 8 7
8 9 7
8 9 8

入力例 3

9 12 30 4 7
2 2 2 2 2 2 2 2 2 2 2 2
2 2 20 20 2 2 5 9 10 9 9 23
2 29 29 29 29 29 28 28 26 26 26 15
2 29 29 29 29 29 25 25 26 26 26 15
2 29 29 29 29 29 25 25 8 25 15 15
2 18 18 18 18 1 27 27 25 25 16 16
2 19 22 1 1 1 7 3 7 7 7 7
2 19 22 22 6 6 21 21 21 7 7 7
2 19 22 22 22 22 21 21 21 24 24 24

出力例 3

21 20 19 20 18 17
20 19 18 19 17 15
21 19 20 19 18 16
21 19 19 18 19 18
20 18 18 18 19 18
18 16 17 18 19 17

Score : 500 points

Problem Statement

You have a grid with H rows from top to bottom and W columns from left to right. We denote by (i, j) the square at the i-th row from the top and j-th column from the left. (i,j)\ (1\leq i\leq H,1\leq j\leq W) has an integer A _ {i,j} between 1 and N written on it.

You are given integers h and w. For all pairs (k,l) such that 0\leq k\leq H-h and 0\leq l\leq W-w, solve the following problem:

  • If you black out the squares (i,j) such that k\lt i\leq k+h and l\lt j\leq l+w, how many distinct integers are written on the squares that are not blacked out?

Note, however, that you do not actually black out the squares (that is, the problems are independent).

Constraints

  • 1 \leq H,W,N \leq 300
  • 1 \leq h \leq H
  • 1 \leq w \leq W
  • (h,w)\neq(H,W)
  • 1 \leq A _ {i,j} \leq N\ (1\leq i\leq H,1\leq j\leq W)
  • All values in the input are integers.

Input

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

H W N h w
A _ {1,1} A _ {1,2} \dots A _ {1,W}
A _ {2,1} A _ {2,2} \dots A _ {2,W}
\vdots
A _ {H,1} A _ {H,2} \dots A _ {H,W}

Output

Print the answers in the following format, where \operatorname{ans}_{k,l} denotes the answer to (k, l):

\operatorname{ans} _ {0,0} \operatorname{ans} _ {0,1} \dots \operatorname{ans} _ {0,W-w}
\operatorname{ans} _ {1,0} \operatorname{ans} _ {1,1} \dots \operatorname{ans} _ {1,W-w}
\vdots
\operatorname{ans} _ {H-h,0} \operatorname{ans} _ {H-h,1} \dots \operatorname{ans} _ {H-h,W-w}

Sample Input 1

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

Sample Output 1

4 4 3
5 3 4

The given grid is as follows:

For example, when (k,l)=(0,0), four distinct integers 1,3,4, and 5 are written on the squares that are not blacked out, so 4 is the answer.


Sample Input 2

5 6 9 3 4
7 1 5 3 9 5
4 5 4 5 1 2
6 1 6 2 9 7
4 7 1 5 8 8
3 4 3 3 5 3

Sample Output 2

8 8 7
8 9 7
8 9 8

Sample Input 3

9 12 30 4 7
2 2 2 2 2 2 2 2 2 2 2 2
2 2 20 20 2 2 5 9 10 9 9 23
2 29 29 29 29 29 28 28 26 26 26 15
2 29 29 29 29 29 25 25 26 26 26 15
2 29 29 29 29 29 25 25 8 25 15 15
2 18 18 18 18 1 27 27 25 25 16 16
2 19 22 1 1 1 7 3 7 7 7 7
2 19 22 22 6 6 21 21 21 7 7 7
2 19 22 22 22 22 21 21 21 24 24 24

Sample Output 3

21 20 19 20 18 17
20 19 18 19 17 15
21 19 20 19 18 16
21 19 19 18 19 18
20 18 18 18 19 18
18 16 17 18 19 17
F - Shiritori

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

N 個の文字列 S _ 1,S _ 2,\ldots,S _ N が与えられます。 S _ i\ (1\leq i\leq N) は英小文字からなる長さ 10 以下の空でない文字列で、互いに異なります。

先手太郎君と後手次郎君がしりとりをします。 このしりとりでは、先手太郎君と後手次郎君の手番が交互に訪れます。 はじめの手番は先手太郎君の手番です。 それぞれのプレイヤーは自分の手番において整数 i\ (1\leq i\leq N)1 つ選びます。 このとき、i は次の 2 つの条件を満たしていなければなりません。

  • i は、しりとりが開始してからこれまでの 2 人の手番で選ばれたどの整数とも異なる
  • この手番がしりとりの最初の手番であるか、直前に選ばれた整数を j として、S _ j の最後の文字と S _ i の最初の文字が等しい

条件を満たす i を選べなくなったプレイヤーの負けで、負けなかったプレイヤーの勝ちです。

2 人が最適に行動したときに勝つのはどちらかを判定してください。

制約

  • 1 \leq N \leq 16
  • N は整数
  • S _ i\ (1\leq i\leq N) は英小文字からなる長さ 10 以下の空でない文字列
  • S _ i\neq S _ j\ (1\leq i\lt j\leq N)

入力

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

N
S_1
S_2
\vdots
S_N

出力

2 人が最適に行動したとき、先手太郎君が勝つなら First、後手次郎君が勝つなら Second と出力せよ。


入力例 1

6
enum
float
if
modint
takahashi
template

出力例 1

First

例えば、ゲームは以下のように進行します。 この進行例では 2 人の行動が必ずしも最適とは限らないことに注意してください。

  • 先手太郎君が i=3 を選ぶ。S _ i=if である。
  • 後手次郎君が i=2 を選ぶ。S _ i=float であり、if の最後の文字と float の最初の文字は等しい。
  • 先手太郎君が i=5 を選ぶ。S _ i=takahashi であり、float の最後の文字と takahashi の最初の文字は等しい。
  • 後手次郎君は i\neq2,3,5 であって S _ i の最初の文字が i と等しいものを選べないため、負ける。

このとき、先手太郎君が勝ちます。


入力例 2

10
catch
chokudai
class
continue
copy
exec
havoc
intrinsic
static
yucatec

出力例 2

Second

入力例 3

16
mnofcmzsdx
lgeowlxuqm
ouimgdjxlo
jhwttcycwl
jbcuioqbsj
mdjfikdwix
jhvdpuxfil
peekycgxco
sbvxszools
xuuqebcrzp
jsciwvdqzl
obblxzjhco
ptobhnpfpo
muizaqtpgx
jtgjnbtzcl
sivwidaszs

出力例 3

First

Score : 500 points

Problem Statement

You are given N strings S _ 1,S _ 2,\ldots,S _ N. S _ i\ (1\leq i\leq N) is a non-empty string of length at most 10 consisting of lowercase English letters, and the strings are pairwise distinct.

Taro the First and Jiro the Second play a word-chain game. In this game, the two players take alternating turns, with Taro the First going first. In each player's turn, the player chooses an integer i\ (1\leq i\leq N), which should satisfy the following two conditions:

  • i is different from any integer chosen by the two players so far since the game started;
  • the current turn is the first turn of the game, or the last character of S_j equals the first character of S_i, where j is the last integer chosen.

The player who is unable to choose a conforming i loses; the other player wins.

Determine which player will win if the two players play optimally.

Constraints

  • 1 \leq N \leq 16
  • N is an integer.
  • S _ i\ (1\leq i\leq N) is a non-empty string of length at most 10 consisting of lowercase English letters.
  • S _ i\neq S _ j\ (1\leq i\lt j\leq N)

Input

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

N
S_1
S_2
\vdots
S_N

Output

Print First if Taro the First wins when the two players play optimally; print Second if Jiro the Second wins.


Sample Input 1

6
enum
float
if
modint
takahashi
template

Sample Output 1

First

For example, the game progresses as follows. Note that the two players may not be playing optimally in this example.

  • Taro the First chooses i=3. S _ i=if.
  • Jiro the Second chooses i=2. S _ i=float, and the last character of if equals the first character of float.
  • Taro the First chooses i=5. S _ i=takahashi, and the last character of float equals the first character of takahashi.
  • Jiro the Second is unable to choose i\neq2,3,5 such that S _ i starts with i, so he loses.

In this case, Taro the First wins.


Sample Input 2

10
catch
chokudai
class
continue
copy
exec
havoc
intrinsic
static
yucatec

Sample Output 2

Second

Sample Input 3

16
mnofcmzsdx
lgeowlxuqm
ouimgdjxlo
jhwttcycwl
jbcuioqbsj
mdjfikdwix
jhvdpuxfil
peekycgxco
sbvxszools
xuuqebcrzp
jsciwvdqzl
obblxzjhco
ptobhnpfpo
muizaqtpgx
jtgjnbtzcl
sivwidaszs

Sample Output 3

First
G - Generalized Subtraction Game

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

この問題は インタラクティブな問題(あなたの作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。

整数 N, L, R が与えられます。
あなたはジャッジシステムと次のゲームで対戦します。

1 から N までの番号がついた N 枚のカードが場に置かれています。
先攻から交互に以下の操作を繰り返します。

  • 1 \leq x \leq N, L \leq y \leq R かつカード x, x+1, \dots, x+y-1y 枚がすべて場に存在するような整数の組 (x, y) を 1 つ選び、カード x, x+1, \dots, x+y-1 を場から取り除く。

先に操作が行えなくなった方が負けで、そうでない方が勝ちです。

あなたは先攻か後攻の一方を選んでください。そして、選んだ方の手番でジャッジシステムとゲームをして勝利してください。

制約

  • 1 \leq N \leq 2000
  • 1 \leq L \leq R \leq N
  • N, L, R は整数

入出力

この問題はインタラクティブな問題(あなたの作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。

最初に、N, L, R が以下の形式で入力から与えられるので、これを受け取ってください。

N L R

まず、あなたは一方の手番を選びます。そして、選んだ手番が先攻ならば First を、後攻ならば Second を出力してください。

その後、あなたは出力した方の手番で、ジャッジシステムがそうでない方の手番でゲームが直ちに開始されます。あなたはゲームが終了するまで入出力を利用してジャッジシステムと対話をして、ゲームに勝利してください。

あなたは手番が回ってきたら、操作で選ぶ整数の組 (x, y) を次の形式で出力してください。ただし、選ぶことのできる (x, y) が存在しない場合は (x, y) = (0, 0) を出力してください。

x y

ジャッジシステムの手番では、ジャッジシステムが以下の形式で整数の組 (a, b) を出力します。

a b

ここで a, b は次の 3 種類のいずれかであることが保証されます。

  • (a, b) = (0, 0) の場合:ジャッジシステムは操作を行えなくなったことを意味します。つまり、あなたはゲームに勝利しました。
  • (a, b) = (-1, -1) の場合:あなたは 1 つ前に非合法な (x, y) を選んだか、あるいは (0, 0) を出力したことを意味します。つまり、あなたはゲームに敗北しました。
  • それ以外の場合:ジャッジシステムは (x,y) = (a,b) として操作を行ったことを意味します。ここでジャッジシステムが選んだ (x, y) は合法であることが保証されます。

ジャッジが (a,b)=(0,0) または (a,b)=(-1,-1) を返した場合、ゲームはすでに終了しています。この場合、プログラムをただちに終了してください。

注意点

  • 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
  • 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。 特に、プログラムの実行中に実行時エラーが起こった場合に、ジャッジ結果が ではなく TLE になる可能性があることに注意してください。
  • ゲームが終了したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。

入出力例

以下は、N = 6, L = 1, R = 2 の場合の入出力例です。

入力 出力 説明
6 1 2 まず整数 N, L, R が与えられます。
First 先攻を選び、ゲームを開始します。
2 1 (x, y) = (2, 1) を選び、カード 2 を取り除きます。
3 2 (x, y) = (3, 2) を選び、カード 3, 4 を取り除きます。
6 1 (x, y) = (6, 1) を選び、カード 6 を取り除きます。
5 1 (x, y) = (5, 1) を選び、カード 5 を取り除きます。
1 1 (x, y) = (1, 1) を選び、カード 1 を取り除きます。
0 0 ジャッジシステムは操作を行うことができなくなったので、あなたの勝ちです。

Score : 600 points

Problem Statement

This is an interactive task (where your program interacts with the judge's program via Standard Input and Output).

You are given integers N, L, and R.
You play the following game against the judge:

There are N cards numbered 1 through N on the table.
The players alternately perform the following operation:

  • choose an integer pair (x, y) satisfying 1 \leq x \leq N, L \leq y \leq R such that all of the y cards x, x+1, \dots, x+y-1 remain on the table, and remove cards x, x+1, \dots, x+y-1 from the table.

The first player to become unable to perform the operation loses, and the other player wins.

Choose whether to go first or second, and play the game against the judge to win.

Constraints

  • 1 \leq N \leq 2000
  • 1 \leq L \leq R \leq N
  • N, L, and R are integers.

Input and Output

This is an interactive task (where your program interacts with the judge's program via Standard Input and Output).

Initially, receive N, L, and R, given from the input in the following format:

N L R

First, you choose whether to go first or second. Print First if you choose to go first, and Second if you choose to go second.

Then, the game immediately starts. If you choose to go first, the judge goes second, and vice versa. You are to interact with the judge via input and output until the game ends to win the game.

In your turn, print an integer pair (x, y) that you choose in the operation in the following format. If there is no (x, y) that you can choose, print (x, y) = (0, 0) instead.

x y

In the judge's turn, the judge print an integer pair (a, b) in the following format:

a b

Here, it is guaranteed that (a, b) is of one of the following three kinds.

  • If (a, b) = (0, 0): the judge is unable to perform the operation. In other words, you have won the game.
  • If (a, b) = (-1, -1): you have chosen an illegal (x, y) or printed (0, 0). In other words, you have lost the game.
  • Otherwise: the judge has performed the operation with (x,y) = (a,b). It is guaranteed that judge chooses valid (x, y).

If the judge returns (a,b)=(0,0) or (a,b)=(-1,-1), the game has already ended. In that case, terminate the program immediately.

Notes

  • After each output, add a newline and then flush Standard Output. Otherwise, you may get a TLE verdict.
  • If an invalid output is printed during the interaction, or if the program terminates halfway, the verdict will be indeterminate. Especially, note that if a runtime error occurs during the execution of the program, you may get a or TLE verdict instead of a verdict.
  • Terminate the program immediately after the game ends. Otherwise, the verdict will be indeterminate.

Sample Interaction

The following is a sample interaction where N = 6, L = 1, and R = 2.

Input Output Description
6 1 2 Initially, you are given integers N, L, and R.
First You choose to go first and start the game.
2 1 (x, y) = (2, 1) is chosen to remove card 2.
3 2 (x, y) = (3, 2) is chosen to remove cards 3, 4.
6 1 (x, y) = (6, 1) is chosen to remove card 6.
5 1 (x, y) = (5, 1) is chosen to remove card 5.
1 1 (x, y) = (1, 1) is chosen to remove card 1.
0 0 The judge is unable to perform the operation, so you win.
Ex - make 1

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

次の条件を満たす非負整数列 S良い数列 と呼びます。

  • S の(連続とは限らない)非空な部分列 T であって、T のすべての要素のビットごとの xor が 1 であるようなものが存在する。

空の数列 A 、および 0 以上 2^B 未満の整数が 1 つずつ書かれた 2^B 枚のカードがあります。
あなたは次の操作を A が良い数列になるまで繰り返します。

  • カードを 1 枚自由に選び、カードに書かれている数を A の末尾に追加する。そして選んだカードを食べる。(食べたカードはその後選ぶことはできない)

操作後の A としてあり得る数列のうち長さが N であるものは何種類ありますか? 答えを \text{mod }998244353 で出力してください。

ビットごとの xor とは? 非負整数 A, B のビット単位 xor 、A \oplus B は、以下のように定義されます。
  • A \oplus B を二進表記した際の 2^k (k \geq 0) の位の数は、A, B を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1、そうでなければ 0 である。
例えば、3 \oplus 5 = 6 となります (二進表記すると: 011 \oplus 101 = 110)。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq B \leq 10^7
  • N \leq 2^B
  • N, B は整数

入力

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

N B

出力

答えを出力せよ。


入力例 1

2 2

出力例 1

5

操作後の A としてあり得る数列のうち長さが 2 であるものは次の 5 種類です。

  • (0, 1)
  • (2, 1)
  • (2, 3)
  • (3, 1)
  • (3, 2)

入力例 2

2022 1119

出力例 2

293184537

入力例 3

200000 10000000

出力例 3

383948354

Score : 600 points

Problem Statement

A sequence S of non-negative integers is said to be a good sequence if:

  • there exists a non-empty (not necessarily contiguous) subsequence T of S such that the bitwise XOR of all elements in T is 1.

There are an empty sequence A, and 2^B cards with each of the integers between 0 and 2^B-1 written on them.
You repeat the following operation until A becomes a good sequence:

  • You freely choose a card and append the integer written on it to the tail of A. Then, you eat the card. (Once eaten, the card cannot be chosen anymore.)

How many sequences of length N can be the final A after the operations? Find the count modulo 998244353.

What is bitwise XOR? The bitwise \mathrm{XOR} of non-negative integers A and B, A \oplus B, is defined as follows.
  • When A \oplus B is written in binary, the k-th lowest bit (k \geq 0) is 1 if exactly one of the k-th lowest bits of A and B is 1, and 0 otherwise.
For instance, 3 \oplus 5 = 6 (in binary: 011 \oplus 101 = 110).

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq B \leq 10^7
  • N \leq 2^B
  • N and B are integers.

Input

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

N B

Output

Print the answer.


Sample Input 1

2 2

Sample Output 1

5

The following five sequences of length 2 can be the final A after the operations.

  • (0, 1)
  • (2, 1)
  • (2, 3)
  • (3, 1)
  • (3, 2)

Sample Input 2

2022 1119

Sample Output 2

293184537

Sample Input 3

200000 10000000

Sample Output 3

383948354