A - ケース・センシティブ

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

配点 : 9

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

長さ 3 の英大文字・英小文字のみからなる文字列 s,t が与えられます。

s,t が大文字と小文字の違いを含めて一致するなら same を、そうではないが大文字と小文字の違いを区別しない場合に一致するなら case-insensitive を、以上に該当しないなら different を出力してください。

制約

  • s,t は長さ 3 の英大文字・英小文字のみからなる文字列

入力

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

s
t

出力

問題文で指示された通りに文字列を出力せよ。


入力例 1

AbC
ABc

出力例 1

case-insensitive
  • AbCABc は、大文字と小文字の違いを区別しない場合に一致するので case-insensitive を出力してください。

入力例 2

xyz
xyz

出力例 2

same
  • st はどちらも xyz で完全に一致するので same を出力してください。

入力例 3

aDs
kjH

出力例 3

different

Score : 9 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

You are given two strings s and t of length 3 consisting of only lowercase and uppercase English letters.

If the strings s and t are completely equal despite we distinguish letter case (i.e. lowercase and uppercase), print same; if they can read the same if we remove the distinction of letter case, print case-insensitive; otherwise, print different.

Constraints

  • The strings s and t have length 3 and contain only lowercase and uppercase English letters.

Input

Input is given from Standard Input in the following format:

s
t

Output

Print the answer, as specified in the problem statement.


Sample Input 1

AbC
ABc

Sample Output 1

case-insensitive
  • Since AbC and ABc can read the same if we treat the uppercase and lowercase letters as equivalent, print case-insensitive.

Sample Input 2

xyz
xyz

Sample Output 2

same
  • Since s and t are completely the same strings as xyz, print same.

Sample Input 3

aDs
kjH

Sample Output 3

different
B - ダイナミック・スコアリング

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

配点 : 8

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

プログラミングコンテストが開催されます。 このコンテストの参加者は N 人で、コンテストには M 個の問題が出題されます。 参加者には 1,2,\ldots,N の番号が、問題には 1,2,\ldots,M の番号が振られています。

このコンテストにおいて、問題の得点はその問題を解いた人間の人数によって変化します。 具体的には、N - \text{(現時点でこの問題を解いた人数)} が得点となります。

参加者のスコアは解いた問題の得点の合計です。問題の得点が変化した場合、参加者のスコアも変化することに注意してください。 例えば、N=2, M=1 の場合において、はじめ問題 1 の得点は 2 です。 その後、参加者 1 が問題 1 を解いたとき、問題 1 の得点は 1、参加者 1 のスコアは 1 となります。 さらにその後、参加者 2 が問題 1 を解いたとき、問題 1 の得点は 0 となり、参加者 1,2 のスコアは 0 となることに注意してください。

以下の形式で与えられる Q 個のクエリ s_1, s_2, \ldots, s_Q を順番に処理してください。

  • 参加者 n の現在のスコアを出力せよ。 1 n という形式で与えられる。
  • 参加者 n が問題 m を解いた。2 n m という形式で与えられる。

制約

  • 1 \leq N, Q \leq 10^5
  • 1 \leq M \leq 50
  • s_i は下記のいずれかの形式の文字列
    • 1 n (1 \leq n \leq N)
    • 2 n m (1 \leq n \leq N, 1 \leq m \leq M)
      • どの参加者も同じ問題を複数回解くことはない

入力

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

N M Q
s_1
\vdots
s_Q

出力

1 n という形式で与えられたクエリに対して、与えられた順に参加者 n のその時点でのスコアを出力せよ。


入力例 1

2 1 6
2 1 1
1 1
1 2
2 2 1
1 1
1 2

出力例 1

1
0
0
0
  • はじめ、問題 1 の得点は 2、参加者 1,2 のスコアはどちらも 0 です。
  • 1 番目のクエリにおいて参加者 1 が問題 1 を解いたことにより、問題 1 の得点は 1、参加者 1,2 のスコアはそれぞれ 1,0 となります。
  • 2 番目のクエリにおいて参加者 1 のスコアである 1 が出力されます。
  • 3 番目のクエリにおいて参加者 2 のスコアである 0 が出力されます。
  • 4 番目のクエリにおいて参加者 2 が問題 1 を解いたことにより、問題 1 の得点は 0、参加者 1,2 のスコアはどちらも 0 となります。
  • 5 番目のクエリにおいて参加者 1 のスコアである 0 が出力されます。
  • 6 番目のクエリにおいて参加者 2 のスコアである 0 が出力されます。

入力例 2

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

出力例 2

0
4
3
0
3
10
9
4
4
4
0
0
9
3
9
0
3

Score : 8 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Contest

We will hold a programming contest. There will be N participants and M problems in this contest. The participants are numbered 1,2,\ldots,N, and the problems are numbered 1,2,\ldots,M.

In this contest, the score for a problem will depend on the number of participants who solve that problem. More specifically, the score is N - \text{(the number of participants who have solved the problem at the moment)}.

The score of a participant is the sum of the scores for the problems solved by that participant. Note that a change in the score for a problem will also change the score of participants. For example, in the case N=2 and M=1, the score for Problem 1 is initially 2. If Participant 1 solves Problem 1, the score for Problem 1 becomes 1, and his score also becomes 1. If Participant 2 then solves Problem 1, the score for Problem 2 becomes 0, and the score of Participant 1 and 2 both become 0.

Process Q queries s_1, s_2, \ldots, s_Q in order, which will be given in the formats below:

  • Print the current score of Participant n. This query is given in the format 1 n.
  • It is reported that Participant n solves Problem m. This query is given in the format 2 n m.

Constraints

  • 1 \leq N, Q \leq 10^5
  • 1 \leq M \leq 50
  • s_i is a string in one of the following formats:
    • 1 n (1 \leq n \leq N)
    • 2 n m (1 \leq n \leq N, 1 \leq m \leq M)
      • No participant solves the same problem multiple times.

Input

Input is given from Standard Input in the following format:

N M Q
s_1
\vdots
s_Q

Output

For each query in the format 1 n, in the order given, print the score of Participant n at that time.


Sample Input 1

2 1 6
2 1 1
1 1
1 2
2 2 1
1 1
1 2

Sample Output 1

1
0
0
0
  • Initially, the score for Problem 1 is 2, and the score of Participant 1 and 2 are both 0.
  • After Participant 1 solves Problem 1 in the first query, the score for Problem 1 becomes 1, and the score of Participant 1 and 2 becomes 1 and 0, respectively.
  • In the second query, the score of Participant 1 - which is 1 - is printed.
  • In the third query, the score of Participant 2 - which is 0 - is printed.
  • After Participant 2 solves Problem 1 in the fourth query, the score for Problem 1 becomes 0, and the score of Participant 1 and 2 both become 0.
  • In the fifth query, the score of Participant 1 - which is 0 - is printed.
  • In the sixth query, the score of Participant 2 - which is 0 - is printed.

Sample Input 2

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

Sample Output 2

0
4
3
0
3
10
9
4
4
4
0
0
9
3
9
0
3
C - 等比数列

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

配点 : 8

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

初項 A、公比 R の等比数列の第 N 項が 10^9 より大きければ large を、10^9 以下ならその値を整数で出力してください。

制約

  • 入力はすべて整数
  • 1 \leq A, R, N \leq 10^9

入力

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

A R N

出力

問題で指定された値または文字列を出力せよ。


入力例 1

2 3 4

出力例 1

54

初項 2、公比 3 の等比数列は 2, 6, 18, 54, \ldots です。これの第 4 項は 54 であるため、54 を出力します。


入力例 2

4 3 21

出力例 2

large

初項 4、公比 3 の等比数列の第 21 項は 13947137604 であり、これは 10^9 より大きいため、large を出力します。


入力例 3

12 34 5

出力例 3

16036032

Score : 8 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Consider the N-th term of a geometric sequence with the initial value of A and the common ratio of R. If it is greater than 10^9, print large; otherwise, print its value as an integer.

Constraints

  • All values in input are integers.
  • 1 \leq A, R, N \leq 10^9

Input

Input is given from Standard Input in the following format:

A R N

Output

Print a value or a string as specified in Problem Statement.


Sample Input 1

2 3 4

Sample Output 1

54

The geometric sequence with the initial value of 2 and the common ratio of 3 is: 2, 6, 18, 54, \ldots. Its fourth term is 54, so we should print 54.


Sample Input 2

4 3 21

Sample Output 2

large

The 21-st term of a geometric sequence with the initial value of 4 and the common ratio of 3 is 13947137604, which is greater than 10^9. Thus, we should print large.


Sample Input 3

12 34 5

Sample Output 3

16036032
D - 電光掲示板

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

配点 : 7

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

N 桁の数字列を表示する電光掲示板があります。 この電光掲示板は 54N+1 列に並べられたランプにより構成されます。 1 \leq j \leq N を満たす j について、左から j 桁目の数字の表示には左から 4j-2,4j-1,4j 列目のランプが用いられます。 それ以外の 1,5, \ldots, 4N+1 列目のランプは全て消灯しています。

電光掲示板の表示の状況は 5 つの長さ 4N+1 の文字列 s_1,s_2,s_3,s_4,s_5 により表されます。 具体的には、1 \leq i \leq 5, 1 \leq j \leq 4N+1 を満たす (i,j) について、 s_{i} の先頭から j 番目の文字は上から i 行目、左から j 列目のランプの点灯状況を表しています。

文字列中の # は対応する位置のランプが点灯していることを、. は消灯していることを表します。

電光掲示板に表示されている N 桁の数字列を出力してください。

各数字の表示の仕方については入力例 1 を参考にしてください。

制約

  • 1 \leq N \leq 50
  • s_1,s_2,s_3,s_4,s_5#. のみからなる長さ 4N+1 の文字列
  • s_1,s_2,s_3,s_4,s_51,5, \ldots, 4N+1 文字目は全て .
  • 入力に対応する数字列が必ず存在し、各数字の表示の仕方は入力例 1 のものと同様

入力

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

N
s_1
s_2
s_3
s_4
s_5

出力

電光掲示板で表示されている N 桁の数字列を出力せよ。


入力例 1

10
.###..#..###.###.#.#.###.###.###.###.###.
.#.#.##....#...#.#.#.#...#.....#.#.#.#.#.
.#.#..#..###.###.###.###.###...#.###.###.
.#.#..#..#.....#...#...#.#.#...#.#.#...#.
.###.###.###.###...#.###.###...#.###.###.

出力例 1

0123456789

入力例 2

29
.###.###.###.###.###.###.###.###.###.#.#.###.#.#.#.#.#.#.###.###.###.###..#..###.###.###.###.###.#.#.###.###.###.###.
...#.#.#...#.#.#.#.#.#...#.#...#.#.#.#.#.#...#.#.#.#.#.#.#.....#.#.#.#.#.##..#.#...#.#.#...#.#...#.#...#.#.....#...#.
.###.#.#...#.###.#.#.###.###...#.###.###.###.###.###.###.###...#.###.#.#..#..###...#.###.###.###.###.###.###.###.###.
.#...#.#...#...#.#.#.#.#...#...#.#.#...#.#.#...#...#...#.#.#...#...#.#.#..#..#.#...#...#.#...#.#...#.#.....#...#.#...
.###.###...#.###.###.###.###...#.###...#.###...#...#...#.###...#.###.###.###.###...#.###.###.###...#.###.###.###.###.

出力例 2

20790697846444679018792642532

Score : 7 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

We have an electric bulletin board that shows an N-digit number. The board is made of a grid of lamps with 5 rows and 4N+1 columns. For each j such that 1 \leq j \leq N, the j-th digit from the left is displayed using the lamps in the (4j-2)-th, (4j-1)-th, and (4j)-th columns from the left. All the remaining lamps in the 1-st, 5-th, \ldots, (4N+1)-th columns are off.

The state of the board is represented by five strings of length 4N+1 each: s_1, s_2, s_3, s_4, and s_5. More specifically, for each pair (i,j) such that 1 \leq i \leq 5 and 1 \leq j \leq 4N+1, the j-th character of s_{i} repsesents the state of the lamp at the i-th row from the top and the j-th column from the left.

The characters # and . stand for "on" and "off" states, respectively.

Print the sequence of digits displayed on the board.

To see how the board displays each digit, refer to Sample Input 1.

Constraints

  • 1 \leq N \leq 50
  • s_1, s_2, s_3, s_4, and s_5 are strings of length 4N+1 each and consist of # and ..
  • The 1-st, 5-th, \ldots, (4N+1)-th characters of each of the strings s_1, s_2, s_3, s_4, and s_5 are all .s.
  • The input is a valid representation of a sequence of digits in the same way as in Sample Input 1.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
s_3
s_4
s_5

Output

Print the N-digit sequence displayed on the board.


Sample Input 1

10
.###..#..###.###.#.#.###.###.###.###.###.
.#.#.##....#...#.#.#.#...#.....#.#.#.#.#.
.#.#..#..###.###.###.###.###...#.###.###.
.#.#..#..#.....#...#...#.#.#...#.#.#...#.
.###.###.###.###...#.###.###...#.###.###.

Sample Output 1

0123456789

Sample Input 2

29
.###.###.###.###.###.###.###.###.###.#.#.###.#.#.#.#.#.#.###.###.###.###..#..###.###.###.###.###.#.#.###.###.###.###.
...#.#.#...#.#.#.#.#.#...#.#...#.#.#.#.#.#...#.#.#.#.#.#.#.....#.#.#.#.#.##..#.#...#.#.#...#.#...#.#...#.#.....#...#.
.###.#.#...#.###.#.#.###.###...#.###.###.###.###.###.###.###...#.###.#.#..#..###...#.###.###.###.###.###.###.###.###.
.#...#.#...#...#.#.#.#.#...#...#.#.#...#.#.#...#...#...#.#.#...#...#.#.#..#..#.#...#...#.#...#.#...#.#.....#...#.#...
.###.###...#.###.###.###.###...#.###...#.###...#...#...#.###...#.###.###.###.###...#.###.###.###...#.###.###.###.###.

Sample Output 2

20790697846444679018792642532
E - スプリンクラー

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

配点 : 7

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

1,2,3,\ldots,N の番号がついた N 個の頂点と 1,2,3,\ldots,M の番号がついた M 本の無向辺からなる無向グラフが与えられます。 辺 i は頂点 u_iv_i を双方向につないでいます。

それぞれの頂点には色を塗ることが可能で、はじめ頂点 i は色 c_i で塗られています(この問題において、色は 1 以上 10^5 以下の整数で表されます)。

それぞれの頂点にはスプリンクラーが設置されています。 頂点 i にあるスプリンクラーを起動すると、頂点 i に隣接する全ての頂点の色がスプリンクラー起動時点の頂点 i の色で塗り替えられます。

以下の形式で与えられる Q 個のクエリ s_1, s_2, \ldots, s_Q を順番に処理してください。

  • 頂点 x の現在の色を出力する。その後、頂点 x にあるスプリンクラーを起動する。1 x という形式で与えられる。
  • 頂点 x の現在の色を出力する。その後、頂点 x の色を y で上書きする。2 x y という形式で与えられる。

制約

  • 与えられる入力は全て整数
  • 1 \leq N,Q \leq 200
  • 0 \leq M \leq N(N-1)/2
  • 1 \leq u_i, v_i\leq N
  • 1 \leq c_i\leq 10^5
  • s_i は下記のいずれかの形式の文字列
    • 1 x (1 \leq x \leq N)
    • 2 x y (1 \leq x \leq N, 1 \leq y \leq 10^{5})
  • 与えられるグラフに多重辺や自己ループは存在しない

入力

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

N M Q
u_1 v_1
\vdots
u_M v_M
c_1 c_2 \cdots c_N
s_1
\vdots
s_Q

出力

Q 行出力せよ。i 行目では i 番目のクエリで指定された頂点 x の現在の色を出力せよ。


入力例 1

3 2 3
1 2
2 3
5 10 15
1 2
2 1 20
1 1

出力例 1

10
10
20
  • はじめ、頂点 1,2,3 は色 5,10,15 でそれぞれ塗られています。
  • 1 番目のクエリにより、頂点 2 に隣接する全ての頂点が色 10 に塗り替えられます。これにより、頂点 1,2,3 は全て 10 で塗られている状態になります。
  • 2 番目のクエリにより、頂点 1 の色が色 20 に上書きされます。
  • 3 番目のクエリにより、頂点 1 に隣接する全ての頂点が色 20 に上書きされます。

入力例 2

30 10 20
11 13
30 14
6 4
7 23
30 8
17 4
6 23
24 18
26 25
9 3
18 4 36 46 28 16 34 19 37 23 25 7 24 16 17 41 24 38 6 29 10 33 38 25 47 8 13 8 42 40
2 1 9
1 8
1 9
2 20 24
2 26 18
1 20
1 26
2 24 31
1 4
2 21 27
1 25
1 29
2 10 14
2 2 19
2 15 36
2 28 6
2 13 5
1 12
1 11
2 14 43

出力例 2

18
19
37
29
8
24
18
25
46
10
18
42
23
4
17
8
24
7
25
16

Score : 7 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Given is an undirected graph with N vertices numbered 1,2,3,\ldots,N and M edges numbered 1,2,3,\ldots,M. Edge i connects Vertex u_i and v_i bidirectionally.

Each vertex can be painted in a color. Initially, Vertex i is painted in Color c_i. (In this problem, colors are represented by integers from 1 through 10^5.)

Each vertex has a sprinkler on it. When the sprinkler at Vertex i is activated, it will repaint all the vertices adjacent to Vertex i in the color of Vertex i when it is activated.

Process Q queries s_1, s_2, \ldots, s_Q in order, which will be given in the formats below:

  • Print the current color of Vertex x, and then activate the sprinkler on Vertex x. This query is given in the format 1 x.
  • Print the current color of Vertex x, and then overwrite the color of Vertex x to y. This query is given in the format 2 x y.

Constraints

  • All values in input are integers.
  • 1 \leq N,Q \leq 200
  • 0 \leq M \leq N(N-1)/2
  • 1 \leq u_i, v_i\leq N
  • 1 \leq c_i\leq 10^5
  • s_i is a string in one of the following formats:
    • 1 x (1 \leq x \leq N)
    • 2 x y (1 \leq x \leq N, 1 \leq y \leq 10^{5})
  • The given graph contains no multiple edges or self-loops.

Input

Input is given from Standard Input in the following format:

N M Q
u_1 v_1
\vdots
u_M v_M
c_1 c_2 \cdots c_N
s_1
\vdots
s_Q

Output

Print Q lines. The i-th line should contain the color of the vertex x specified in the i-th query.


Sample Input 1

3 2 3
1 2
2 3
5 10 15
1 2
2 1 20
1 1

Sample Output 1

10
10
20
  • Initially, Vertex 1, 2, and 3 are painted in Color 5, 10, and 15, respectively.
  • The first query repaints all the vertices adjacent to Vertex 2 in Color 10. After that, Vertex 1, 2 and 3 are all painted in Color 10.
  • The second query overwrites the color of Vertex 1 to Color 20.
  • The third query repaints all the vertices adjacent to Vertex 2 in Color 20.

Sample Input 2

30 10 20
11 13
30 14
6 4
7 23
30 8
17 4
6 23
24 18
26 25
9 3
18 4 36 46 28 16 34 19 37 23 25 7 24 16 17 41 24 38 6 29 10 33 38 25 47 8 13 8 42 40
2 1 9
1 8
1 9
2 20 24
2 26 18
1 20
1 26
2 24 31
1 4
2 21 27
1 25
1 29
2 10 14
2 2 19
2 15 36
2 28 6
2 13 5
1 12
1 11
2 14 43

Sample Output 2

18
19
37
29
8
24
18
25
46
10
18
42
23
4
17
8
24
7
25
16
F - 回文行列

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

配点 : 7

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

整数 N 及び 小文字アルファベットからなる N×N 行列 a が与えられます。 以下の条件を満たすような 長さ N の文字列 S をいずれか 1 つ構築してください。

  • 文字列 S は英小文字から構成される。
  • 文字列 S は回文である。なお, 回文とは前から読んでも後ろから読んでも同じである文字列である。
  • S_{i}a_{i,1},a_{i,2}, \ldots, a_{i,N} のいずれかと同じ文字である。

ただし、条件を満たす文字列が存在しない場合はそれを指摘してください。

制約

  • N は整数
  • 1 \leq N \leq 500
  • a_{i,j} は英小文字

入力

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

N
a_{1,1}a_{1,2}\cdotsa_{1,N}
\vdots
a_{N,1}a_{N,2}\cdotsa_{N,N}

出力

条件を満たす文字列が存在する場合は、そのような文字列を以下の形式で出力せよ。

S_{1}S_{2}S_{3}\cdotsS_{N}

条件を満たす文字列が複数存在する場合は、そのうちのいずれを出力してもよい。

条件を満たす文字列が存在しない場合は、-1 を出力せよ。


入力例 1

2
yc
ys

出力例 1

yy

入力例 2

2
rv
jh

出力例 2

-1

Score : 7 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Given an integer N and a matrix a of size N×N consisting of lowercase English letters. Your task is to construct a string S of length N that satisfies the following conditions:

  • The string S contains only lowercase English letters.
  • The string S is a palindrome. Recall that a string is called a palindrome if it reads the same way in both directions.
  • Every character S_{i} equals at least one of the characters a_{i,1},a_{i,2}, \ldots, a_{i,N}.

If no strings can satisfy all the above conditions, you have to point out this fact.

Constraints

  • N is an integer.
  • 1 \leq N \leq 500
  • Each character a_{i,j} is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

N 
a_{1,1}a_{1,2}\cdotsa_{1,N}
\vdots
a_{N,1}a_{N,2}\cdotsa_{N,N}

Output

If there exists a string S that satisfies all the conditions, print the answer in the following format:

S_{1}S_{2}S_{3}\cdotsS_{N}

If there exist multiple strings satisfying all the conditions, you can print any of them.

If there is no solution, print -1.


Sample Input 1

2
yc
ys

Sample Output 1

yy

Sample Input 2

2
rv
jh

Sample Output 2

-1
G - グリッド金移動

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

配点 : 6

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

無限に広がる二次元グリッドがあります。 すぬけ君ははじめマス (0,0) にいます。 障害物のあるマスが N 個あり、すぬけ君は障害物のあるマスに移動することができません。i 番目の障害物はマス (x_i, y_i) にあります。 すぬけ君の現在位置をマス (x,y) としたとき、一回の移動で以下の 6 箇所のうちいずれかに移動できます。

  • (x+1, y+1)
  • (x, y+1)
  • (x-1, y+1)
  • (x+1, y)
  • (x-1, y)
  • (x, y-1)

最小で何回移動するとマス (X,Y) に到達できるか出力してください。到達することが不可能であれば -1 を出力してください。

制約

  • 入力はすべて整数
  • 1 \leq N \leq 800
  • -200 \leq x_i, y_i, X, Y \leq 200
  • (x_i, y_i) は相異なる。つまり、同じマスに 2 個以上の障害物はない。
  • (0, 0) および (X, Y) には障害物はない
  • (X, Y) \neq (0, 0)

入力

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

N X Y
x_1 y_1
:
x_N y_N

出力

問題で指定された整数を出力せよ。


入力例 1

1 2 2
1 1

出力例 1

3

以下にグリッドの一部を図示します。

..G
.#.
S..

ここで、S はマス (0, 0) を、G はマス (X, Y) = (2, 2) を、# は障害物のあるマスを表します。

最小で 3 回の移動で (X, Y) = (2, 2) に到達することができます。この回数は、例えば (0, 0) \to (0, 1) \to (1, 2) \to (2, 2) と移動すれば達成できます。


入力例 2

1 2 2
2 1

出力例 2

2

入力例 3

5 -2 3
1 1
-1 1
0 1
-2 1
-3 1

出力例 3

6

Score : 6 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

We have an infinite two-dimensional grid. Snuke is initially standing at the square (0,0) in this grid. There are N squares that contain an obstacle, and Snuke cannot enter those squares. The i-th obstacle is at the square (x_i, y_i). When Snuke is at the square (x, y), he can get to one of the following six squares in one move:

  • (x+1, y+1)
  • (x, y+1)
  • (x-1, y+1)
  • (x+1, y)
  • (x-1, y)
  • (x, y-1)

Print the minimum number of moves Snuke needs to reach the square (X, Y). If this square is unreachable, print -1.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 800
  • -200 \leq x_i, y_i, X, Y \leq 200
  • The pairs (x_i, y_i) are distinct. That is, no square contains two or more obstacles.
  • The squares (0, 0) and (X, Y) do not contain an obstacle.
  • (X, Y) \neq (0, 0)

Input

Input is given from Standard Input in the following format:

N X Y
x_1 y_1
:
x_N y_N

Output

Print an integer as specified in Problem Statement.


Sample Input 1

1 2 2
1 1

Sample Output 1

3

Shown below is a part of the grid:

..G
.#.
S..

Here, S, G, and # stand for the square (0, 0), (X, Y) = (2, 2), and a square with an obstacle.

The minimum number of moves needed to reach (X, Y) = (2, 2) is three. One way to achieve it is (0, 0) \to (0, 1) \to (1, 2) \to (2, 2).


Sample Input 2

1 2 2
2 1

Sample Output 2

2

Sample Input 3

5 -2 3
1 1
-1 1
0 1
-2 1
-3 1

Sample Output 3

6
H - ハードル走

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

配点 : 6

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

すぬけ君は数直線上でハードル走をします。 座標 0 がスタート地点、座標 L がゴール地点です。 数直線上には N 個のハードルがあり、左から i 番目のハードルは座標 x_i にあります。(0 < x_1 < x_2 < \cdots < x_N < L が成立します。)

すぬけ君は、以下の 3 種類の行動のうち一つを選んで実行する、ということを繰り返し行うことができます。

  • 行動 1: 距離 1 を走って進む。
  • 行動 2: 距離 0.5 を走って進み、ジャンプして距離 1 を進み、また距離 0.5 を走って進む。合計で 2 の距離を進むことになる。
  • 行動 3: 距離 0.5 を走って進み、ジャンプして距離 3 を進み、また距離 0.5 を走って進む。合計で 4 の距離を進むことになる。

すぬけ君は、走っているときは距離 1 あたり T_1 秒、ジャンプ中は距離 1 あたり T_2 秒の速さで進みます。ただし、すぬけ君がジャンプ中でないときに座標 x にいて、座標 x にハードルがある場合、その地点を通り過ぎるのに追加で T_3 秒の時間がかかります。T_1, T_2, T_3 は全て偶数です。

すぬけ君が座標 L を通るまでにかかる秒数の最小値を求めてください。(座標 L をジャンプして通過する場合は、ジャンプ中に座標 L を通過するまでの秒数が「座標 L を通るまでにかかる秒数」です。) 答えは整数であることが証明できます。

制約

  • 入力は全て整数
  • 2 \leq L \leq 10^5
  • 1 \leq N < L
  • 0 < x_1 < x_2 < \cdots < x_N < L
  • 2 \leq T_1, T_2, T_3\leq 1000
  • T_1, T_2, T_3 は偶数

入力

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

N L
x_1 x_2 \cdots x_N
T_1 T_2 T_3

出力

すぬけ君が座標 L を通るまでにかかる秒数の最小値を整数として出力せよ。(答えは整数であることが証明できる。)


入力例 1

2 5
1 4
2 2 20

出力例 1

10

ハードルが座標 14 にあります。この場合、以下のようにするのが最適です。

  1. 行動 2 を実行する。走って進む距離は 1、ジャンプして進む距離は 1 であるため、合計で 2 \times 1 + 2 \times 1 = 4 秒かかる。
  2. 行動 1 を実行する。2 秒かかる。
  3. 行動 3 を実行する。行動の途中で座標 L=5 に到達し、到達までに走って進む距離は 0.5、ジャンプして進む距離は 1.5 であるため、合計で 2 \times 0.5 + 2 \times 1.5 = 4 秒かかる。

以上が最適であり、合計で 4 + 2 + 4 = 10 秒かかるため、10 を出力します。


入力例 2

4 5
1 2 3 4
2 20 100

出力例 2

164

入力例 3

10 19
1 3 4 5 7 8 10 13 15 17
2 1000 10

出力例 3

138

Score : 6 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Snuke will run the hurdles on a number line. He will start at coordinate 0 and finish at coordinate L. There are N hurdles on the number line, and the i-th hurdle from the left is at coordinate x_i. (0 < x_1 < x_2 < \cdots < x_N < L holds.)

Snuke can repeatedly choose one of the three actions below and do it:

  • Action 1: Run the distance of 1.
  • Action 2: Run the distance of 0.5, jump the distance of 1, and run the distance of 0.5, for a total distance of 2.
  • Action 3: Run the distance of 0.5, jump the distance of 3, and run the distance of 0.5, for a total distance of 4.

Snuke goes at the speed of 1 unit distance per T_1 seconds while running, and 1 unit distance per T_2 seconds while in the air. However, if Snuke is at coordinate x while he is not in the air and there is a hurdle at coordinate x, it takes extra T_3 seconds to go past the point. Here, T_1, T_2, and T_3 are even numbers.

Find the minimum number of seconds Snuke needs before he passes coordinate L. (If he jumps over coordinate L, we consider the time when he passes coordinate L in the air.) We can prove that the answer is an integer.

Constraints

  • All values in input are integers.
  • 2 \leq L \leq 10^5
  • 1 \leq N < L
  • 0 < x_1 < x_2 < \cdots < x_N < L
  • 2 \leq T_1, T_2, T_3\leq 1000
  • T_1, T_2, and T_3 are even numbers.

Input

Input is given from Standard Input in the following format:

N L
x_1 x_2 \cdots x_N
T_1 T_2 T_3

Output

Print the minimum number of seconds Snuke needs before he passes coordinate L, as an integer. (It can be proved that this number is an integer.)


Sample Input 1

2 5
1 4
2 2 20

Sample Output 1

10

There are hurdles at coordinate 1 and 4. In this case, the optimal strategy is as follows:

  1. Do Action 2. We run the distance of 1 in total and jump the distance of 1, so it takes 2 \times 1 + 2 \times 1 = 4 seconds in total.
  2. Do Action 1. It takes 2 seconds.
  3. Do Action 3, during which we pass coordinate L=5. Before we pass this point, we run the distance of 0.5 and jump the distance of 1.5, so it takes 2 \times 0.5 + 2 \times 1.5 = 4 seconds in total.

The time taken in this optimal strategy is 4 + 2 + 4 = 10 seconds in total, so we should print 10.


Sample Input 2

4 5
1 2 3 4
2 20 100

Sample Output 2

164

Sample Input 3

10 19
1 3 4 5 7 8 10 13 15 17
2 1000 10

Sample Output 3

138
I - 行列操作

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

配点 : 6

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

以下の条件を満たすような N \times N 行列 a があります。

  • a_{i,j} = N \times (i - 1) + j - 1 ( 1 \leq i,j \leq N )

Q 個のクエリ Query_{1}, \ldots, Query_{Q} が与えられるので、順番に処理してください。 クエリは 4 種類あり、入力形式とクエリの内容は以下の通りです。

  • Query_{i} = 1 A B のとき: 行列 aA 行目と B 行目の要素を列番号を維持しながら交換せよ。
  • Query_{i} =2 A B のとき: 行列 aA 列目と B 列目の要素を行番号を維持しながら交換せよ。
  • Query_{i} =3 のとき: 行列を転置せよ。つまり a_{i,j} の要素は転置後 a_{j,i} に位置する。
  • Query_{i} =4 A B のとき: 行列 aAB 列に位置する要素を出力せよ。

ただし、1 番目と 2 番目の種類のクエリにおいて A=B であったとき、クエリを処理したあとの行列は処理する前と同じであることに注意してください。

制約

  • 入力は全て整数
  • 1 \leq N, Q \leq 10^{5}
  • 1 \leq A, B \leq N
  • 4 A B という形式のクエリが 1 つ以上存在する

入力

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

N
Q
Query_{1}
Query_{2}
\vdots
Query_{Q}

出力

4 A B という形式のクエリに対する答えを、クエリが与えられた順にそれぞれ 1 行ずつ整数で出力せよ。 答えは 32 ビット整数に収まらない可能性があることに注意せよ。


入力例 1

2
19
4 1 1
4 1 2
4 2 1
4 2 2
3
4 1 1
4 1 2
4 2 1
4 2 2
1 1 2
4 1 1
4 1 2
4 2 1
4 2 2
2 2 1
4 1 1
4 1 2
4 2 1
4 2 2

出力例 1

0
1
2
3
0
2
1
3
1
3
0
2
3
1
2
0

入力例 1 では、各操作後の行列のそれぞれの要素の値を確かめることができます。


入力例 2

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

出力例 2

1
6
8

Score : 6 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

You have a matrix a of size N \times N satisfying the following condition:

  • a_{i,j} = N \times (i - 1) + j - 1 ( 1 \leq i,j \leq N )

You are given Q queries. Your task is to process them sequentially.

Each query Query_{1}, Query_{2} \cdots Query_{Q} is represented by one of the following four types of format:

  • 1 A B : Swap all the elements of the A-th row and the B-th row of the matrix a without changing their column numbers.
  • 2 A B : Swap all the elements of the A-th column and the B-th column of the matrix a without changing their row numbers.
  • 3 : Transpose the matrix a, i.e. the element of a_{i,j} will appear at a_{j,i} after performing this query.
  • 4 A B : Output the element of a_{i,j}, i.e. output the element located at the intersection of the A-th row and the B-th column of the matrix a.

Note that the matrix a will remain the same if the given queries are of format either 1 A B or 2 A B and A=B.

Constraints

  • All the values in the input are integers.
  • 1 \leq N, Q \leq 10^{5}
  • 1 \leq A, B \leq N
  • It is guaranteed that there is at least one query of format 4 A B in the input.

Input

Input is given from Standard Input in the following format:

N
Q 
Query_{1}
Query_{2}
\vdots
Query_{Q}

Output

Print answers to the queries of the format 4 A B in the order they appear in the input.

Be careful that the answers might not fit in the 32-bit data type.


Sample Input 1

2
19
4 1 1
4 1 2
4 2 1
4 2 2
3
4 1 1
4 1 2
4 2 1
4 2 2
1 1 2
4 1 1
4 1 2
4 2 1
4 2 2
2 2 1
4 1 1
4 1 2
4 2 1
4 2 2

Sample Output 1

0
1
2
3
0
2
1
3
1
3
0
2
3
1
2
0

In the sample 1, you can check all the elements of the matrix a after performing each type of query.


Sample Input 2

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

Sample Output 2

1
6
8
J - 回転寿司

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

配点 : 6

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

寿司を食べたことのない N 人の子供たちが回転寿司屋にやってきました。 それぞれの子供には 1,2,3,\ldots,N の番号がついています。

M 個の寿司が順番に流れてきます。i 番目に流れてくる寿司の美味しさは a_i です。 寿司は 1,2,3,\ldots,N 番の子供の前をこの順に通ります。

それぞれの子供は自分の前に寿司が流れてきたとき、以下のいずれかの条件を満たすときに限りその寿司を取って食べます。それ以外の場合は何もしません。

  • まだ寿司を一つも食べていない
  • 今までに食べたどの寿司よりも美味しさが大きい

それぞれの寿司について、何番の子供が食べるかを求めてください。

制約

  • 与えられる入力は全て整数
  • 1 \leq N \leq 10^5
  • 1 \leq M \leq 3 \times 10^5
  • 1 \leq a_i \leq 10^9

入力

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

N M
a_1 a_2 \cdots a_M

出力

M 行出力せよ。i 行目では i 番目に流れてきた寿司を食べた子供の番号を出力せよ。誰にも食べられない場合は -1 を出力せよ。


入力例 1

2 5
5 3 2 4 8

出力例 1

1
2
-1
2
1
  • 1 番目に美味しさ 5 の寿司が流れてきます。
    • 子供 1 の前を通ったとき、子供 1 はまだ寿司を食べていないので子供 1 はこの寿司を取って食べます。
  • 2 番目に美味しさ 3 の寿司が流れてきます。
    • 子供 1 の前を通ったとき、子供 1 が今までに食べた寿司にこの寿司の美味しさ以上のものがあるので子供 1 はこの寿司を取りません。
    • 子供 2 の前を通ったとき、子供 2 はまだ寿司を食べていないので子供 2 はこの寿司を取って食べます。
  • 3 番目に美味しさ 2 の寿司が流れてきます。
    • 子供 1 の前を通ったとき、子供 1 が今までに食べた寿司にこの寿司の美味しさ以上のものがあるので子供 1 はこの寿司を取りません。
    • 子供 2 の前を通ったとき、子供 2 が今までに食べた寿司にこの寿司の美味しさ以上のものがあるので子供 2 はこの寿司を取りません。
  • 4 番目に美味しさ 4 の寿司が流れてきます。
    • 子供 1 の前を通ったとき、子供 1 が今までに食べた寿司にこの寿司の美味しさ以上のものがあるので子供 1 はこの寿司を取りません。
    • 子供 2 の前を通ったとき、この寿司は子供 2 が今までに食べたどの寿司よりも美味しさが大きいので子供 2 はこの寿司を取って食べます。
  • 5 番目に美味しさ 8 の寿司が流れてきます。
    • 子供 1 の前を通ったとき、この寿司は子供 1 が今までに食べたどの寿司よりも美味しさが大きいので子供 1 はこの寿司を取って食べます。

入力例 2

5 10
13 16 6 15 10 18 13 17 11 3

出力例 2

1
1
2
2
3
1
3
2
4
5

入力例 3

10 30
35 23 43 33 38 25 22 39 22 6 41 1 15 41 3 20 50 17 25 14 1 22 5 10 34 38 1 12 15 1

出力例 3

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

Score : 6 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

N children, who have never had sushi, have come to a sushi-go-round. The children are numbered 1,2,3,\ldots,N.

The conveyer belt will convey M sushi plates one by one. The deliciousness of the i-th plate is a_i. The plates will pass in front of Child 1, 2, 3, \ldots, N, in this order.

When a plate is passing in front of a child, he/she will pick up the plate and eat it if and only if one of the following conditions is satisfied:

  • He/she has never had a plate.
  • The deliciousness of the plate is greater than those of all plates he/she has had so far.

For each plate, find which child will have it.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 10^5
  • 1 \leq M \leq 3 \times 10^5
  • 1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N M
a_1 a_2 \cdots a_M

Output

Print M lines. The i-th line should contain an integer representing the child who will have the i-th plate, or -1 if no child will have the plate.


Sample Input 1

2 5
5 3 2 4 8

Sample Output 1

1
2
-1
2
1
  • First, the conveyer belt conveys a plate with the deliciousness of 5.
    • When the plate is passing in front of Child 1, he has never had a plate, so he gets it.
  • Second, the conveyer belt conveys a plate with the deliciousness of 3.
    • When the plate is passing in front of Child 1, its deliciousness is not greater than that of the plate he has had, so he ignores it.
    • When the plate is passing in front of Child 2, she has never had a plate, so she gets it.
  • Third, the conveyer belt conveys a plate with the deliciousness of 2.
    • When the plate is passing in front of Child 1, its deliciousness is not greater than those of the plates he has had, so he ignores it.
    • When the plate is passing in front of Child 2, its deliciousness is not greater than those of the plates she has had, so she ignores it.
    • When the plate is passing in front of Child 3, he has never had a plate, so he gets this plate.
  • Fourth, the conveyer belt conveys a plate with the deliciousness of 4.
    • When the plate is passing in front of Child 1, its deliciousness is not greater than those of the plates he has had, so he ignores it.
    • When the plate is passing in front of Child 2, its deliciousness is greater than those of the plates she has had, so she gets it.
  • Fifth, the conveyer belt conveys a plate with the deliciousness of 8.
    • When the plate is passing in front of Child 1, its deliciousness is greater than those of the plates he has had, so he gets it.

Sample Input 2

5 10
13 16 6 15 10 18 13 17 11 3

Sample Output 2

1
1
2
2
3
1
3
2
4
5

Sample Input 3

10 30
35 23 43 33 38 25 22 39 22 6 41 1 15 41 3 20 50 17 25 14 1 22 5 10 34 38 1 12 15 1

Sample Output 3

1
2
1
2
2
3
4
2
5
6
2
7
6
3
7
6
1
7
4
8
9
6
9
9
4
4
10
9
8
-1
K - コンテナの移動

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

配点 : 6

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

1,2,\ldots,N の番号がついた N 個の机と、1,2,\ldots,N の番号がついた N 個のコンテナがあります。 机の上には複数のコンテナを積み上げることができます。

はじめ、コンテナ i は机 i の上に置かれています。

Q 個のクエリが与えられるので、順番に処理してください。 i 番目のクエリでは机 f_i にあるコンテナ x_i とその上に積み上げられたコンテナたちを、机 t_i に順番を変えずに移動させてください。

このとき、机 t_i にすでにコンテナがある場合、以下の図のように既に積み上げられたコンテナたちの上にさらに積み上げるように移動させる必要があります。

510ebd9bf498cbd3c0e7b61b902ef09c.png
  • f=1,t=2,x=4 の例です。机 1 にあるコンテナ 4 とその上にあるコンテナ 2 を机 2 の上に動かします。
  • 2 の上にはコンテナ 3,5 が置かれているので、その上にさらに積み上げる必要があります。

Q 個のクエリを処理した後、それぞれのコンテナがどの机の上にあるかを求めてください。

制約

  • 与えられる入力は全て整数
  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq f_i, t_i, x_i\leq N
  • f_i \neq t_i
  • コンテナ x_i はクエリを処理する時点で机 f_i 上にあることが保証される

入力

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

N Q
f_1 t_1 x_1
\vdots
f_{Q} t_{Q} x_{Q}

出力

N 行出力せよ。i 行目にはコンテナ i が置かれている机の番号を出力せよ。


入力例 1

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

出力例 1

3
3
1
  • 1 番目のクエリで机 1 にあるコンテナ 1 を机 2 に移します。このとき、机 2 にはコンテナ 2 があるので、その上にコンテナ 1 を積み上げます。
  • 2 番目のクエリで机 2 にあるコンテナ 2 とその上にあるコンテナ 1 を机 3 に移します。このとき、机 3 にはコンテナ 3 があるので、その上にコンテナ 2,1 を積み上げます。
  • 3 番目のクエリで机 3 にあるコンテナ 3 とその上にあるコンテナ 2,1 を机 1 に移します。
  • 4 番目のクエリで机 1 にあるコンテナ 2 とその上にあるコンテナ 1 を机 3 に移します。
  • 最終的にコンテナ 1,2 は机 3 に、コンテナ 3 は机 1 にあります。

入力例 2

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

出力例 2

7
3
7
7
5
9
7
7
10
7

Score : 6 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

We have N desks numbered 1,2,\ldots,N, and N containers numbered 1,2,\ldots,N. We can pile multiple containers on a desk.

Initially, Container i is placed on Desk i.

We will ask you to process Q queries in order. In the i-th query, move Container x_i and the containers above it from Desk f_i to Desk t_i, without changing the order they are piled in.

Here, if there are already some containers on Desk t_i, place Container x_i on top of the containers on Desk t_i. See the figure below:

510ebd9bf498cbd3c0e7b61b902ef09c.png
  • In this example, f=1,t=2,x=4. We are moving Container 4 and the container above it - Container 2 - from Desk 1 to Desk 2.
  • Since there are already some containers - Container 3 and 5 - on Desk 2, so we place Container 4 on top of them.

After processing the Q queries, find the desk on which each container lies.

Constraints

  • All values in input are integers.
  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq f_i, t_i, x_i\leq N
  • f_i \neq t_i
  • Container x_i is guaranteed to be placed on Desk f_i when the query is given.

Input

Input is given from Standard Input in the following format:

N Q
f_1 t_1 x_1
\vdots
f_{Q} t_{Q} x_{Q}

Output

Print N lines. The i-th line should contain the integer representing the desk on which Container i lies.


Sample Input 1

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

Sample Output 1

3
3
1
  • In the first query, we move Container 1 from Desk 1 to Desk 2. Container 2 is already on Desk 2, so we place Container 1 on top of it.
  • In the second query, we move Container 2 and the container above it - Container 1 - from Desk 2 to Desk 3. Container 3 is already on Desk 3, so we place Container 2 and 1 on top of it.
  • In the third query, we move Container 3 and the containers above it - Container 2 and 1 - from Desk 2 to Desk 1.
  • In the fourth query, we move Container 2 and the container above it - Container 1 - from Desk 1 to Desk 3.
  • In the end, Container 1 and 2 lie on Desk 3, and Container 3 lies on Desk 1.

Sample Input 2

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

Sample Output 2

7
3
7
7
5
9
7
7
10
7
L - スーパーマーケット

実行時間制限: 4 sec / メモリ制限: 1024 MB

配点 : 6

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

高橋君のスーパーマーケットには陳列棚があります。 この陳列棚には商品を並べられる列が N 本あり、それぞれの列には 1,2,\ldots,N の番号がついています。 列 i には K_i 個の商品が手前から奥へと一列に並べられており、手前から j 番目の商品の消費期限は T_{i,j} です。

ここで、全ての商品の消費期限は相異なることが保証されます。

M 人の客が順番にやってきます。 i 番目にやってきた客は全ての列について現在の時点で手前から a_i 番目までにある商品を見た後、見た商品のうち最も消費期限の値が大きいものを選んで棚から取って購入します。

それぞれの客について、購入した商品の消費期限の値を求めてください。

制約

  • 与えられる入力は全て整数
  • 1 \leq N \leq 10^5
  • 1 \leq K_i \leq 10^5
  • 1 \leq M \leq \sum_{i=1}^{N}K_i \leq 3 \times 10^5
  • 1 \leq T_{i,j} \leq 10^9
  • T_{i,j} は相異なる
  • 1 \leq a_i \leq 2

入力

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

N
K_1 T_{1,1} T_{1,2} \cdots T_{1,K_1}
\vdots
K_N T_{N,1} T_{N,2} \cdots T_{N,K_N}
M
a_1 a_2 \cdots a_M

出力

M 行出力せよ。i 行目では i 番目にやってきた客が購入した商品の消費期限の値を出力せよ。


入力例 1

2
3 1 200 1000
5 20 30 40 50 2
5
1 1 1 2 2

出力例 1

20
30
40
200
1000
  • 現在、棚の 1 番手前にある商品の消費期限は列 11、列 220 です。これらのうち値が最大である 20 の商品を 1 番目にやってきた客は購入します。
  • 現在、棚の 1 番手前にある商品の消費期限は列 11、列 230 です。これらのうち値が最大である 30 の商品を 2 番目にやってきた客は購入します。
  • 現在、棚の 1 番手前にある商品の消費期限は列 11、列 240 です。これらのうち値が最大である 40 の商品を 3 番目にやってきた客は購入します。
  • 現在、棚の 1 番手前にある商品の消費期限は列 11、列 250 です。棚の 2 番目に手前にある商品の消費期限は列 1200、列 22 です。これらのうち値が最大である 200 の商品を 4 番目にやってきた客は購入します。
  • 現在、棚の 1 番手前にある商品の消費期限は列 11、列 250 です。棚の 2 番目に手前にある商品の消費期限は列 11000、列 22 です。これらのうち値が最大である 1000 の商品を 5 番目にやってきた客は購入します。

入力例 2

10
6 8 24 47 29 73 13
1 4
5 72 15 68 49 16
5 65 20 93 64 91
6 100 88 63 50 90 44
2 6 1
10 14 2 76 28 21 78 43 11 97 70
5 31 9 62 84 40
8 10 46 96 23 98 19 38 51
2 37 77
20
1 1 1 1 2 2 2 1 1 2 2 2 2 2 1 2 1 2 2 1

出力例 2

100
88
72
65
93
77
68
63
50
90
64
91
49
46
44
96
37
31
62
20

Score : 6 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

Takahashi's grocery store has a display rack. The rack has N sections numbered 1 to N, each of which contains a queue of products. In Section i, K_i products line up from front to back, and the expiry date of the j-th product from the front is T_{i,j}.

Here, it is guaranteed that all the products have distinct expiry dates.

M customers will visit the store one by one. The i-th customer will check the frontmost a_i products for every section. (If a section has less than a_i products, he/she will check all those products.) Then, he/she will pick up the product with the greatest value of the expiry date among the products checked, and buy it.

For each of the customers, find the expiry date of the product he/she will buy.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 10^5
  • 1 \leq K_i \leq 10^5
  • 1 \leq M \leq \sum_{i=1}^{N}K_i \leq 3 \times 10^5
  • 1 \leq T_{i,j} \leq 10^9
  • T_{i,j} are distinct.
  • 1 \leq a_i \leq 2

Input

Input is given from Standard Input in the following format:

N
K_1 T_{1,1} T_{1,2} \cdots T_{1,K_1}
\vdots
K_N T_{N,1} T_{N,2} \cdots T_{N,K_N}
M
a_1 a_2 \cdots a_M

Output

Print M lines. The i-th line should contain the expiry date of the product he/she will buy.


Sample Input 1

2
3 1 200 1000
5 20 30 40 50 2
5
1 1 1 2 2

Sample Output 1

20
30
40
200
1000
  • The expiry dates of the frontmost products in Section 1 and 2 are now 1 and 20, respectively. Among them, 20 is greater, so the first customer will buy that product.
  • The expiry dates of the frontmost products in Section 1 and 2 are now 1 and 30, respectively. Among them, 30 is greater, so the second customer will buy that product.
  • The expiry dates of the frontmost products in Section 1 and 2 are now 1 and 40, respectively. Among them, 40 is greater, so the third customer will buy that product.
  • The expiry dates of the frontmost products in Section 1 and 2 are now 1 and 50, respectively, and the expiry dates of the second frontmost products in Section 1 and 2 are now 200 and 2, respectively. Among these values, 200 is the greatest, so the fourth customer will buy that product.
  • The expiry dates of the frontmost products in Section 1 and 2 are now 1 and 50, respectively, and the expiry dates of the second frontmost products in Section 1 and 2 are now 1000 and 2, respectively. Among these values, 1000 is the greatest, so the fifth customer will buy that product.

Sample Input 2

10
6 8 24 47 29 73 13
1 4
5 72 15 68 49 16
5 65 20 93 64 91
6 100 88 63 50 90 44
2 6 1
10 14 2 76 28 21 78 43 11 97 70
5 31 9 62 84 40
8 10 46 96 23 98 19 38 51
2 37 77
20
1 1 1 1 2 2 2 1 1 2 2 2 2 2 1 2 1 2 2 1

Sample Output 2

100
88
72
65
93
77
68
63
50
90
64
91
49
46
44
96
37
31
62
20
M - 行商計画問題

実行時間制限: 2.5 sec / メモリ制限: 1024 MB

配点 : 6

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

スーヌケ王国には N 個の街があります。

王国には M 本の道が存在していて、i 番目の道は、街 u_i, v_i を双方向に繋いでいます。 ある道を 1 回利用するためには、通行料として 1 円を払う必要があります。 任意の街から出発して、いくつかの道を経由することで任意の街に辿り着けることが分かっています。

王国の行商人であるタカーハ氏は現在街 s にいて、これから K 個の街 t_1, t_2, \ldots, t_K で取引をしたいと思っています。

s から出発して K 個の街それぞれを少なくとも 1 回は訪れるために、タカーハ氏が払う必要のある通行料の合計は最小で何円でしょうか。 最終的に街 s に戻ってくる必要はありません。

同じ道を複数回利用するとき、その都度通行料を払う必要があることに注意してください。

制約

  • 入力は全て整数である。
  • 2 \leq N \leq 10^5
  • N - 1 \leq M \leq 10^5
  • 1 \leq u_i < v_i \leq N
  • i \neq j のとき (u_i, v_i) \neq (u_j, v_j)
  • 1 \leq s \leq N
  • 1 \leq K \leq \min (N - 1, 16)
  • 1 \leq t_i \leq N
  • i \neq j のとき t_i \neq t_j
  • s \neq t_i

入力

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

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M
s
K
t_1 t_2 \ldots t_K

出力

タカーハ氏が払う必要のある通行料の合計の最小値を整数として出力せよ。


入力例 1

3 2
1 2
2 3
2
2
1 3

出力例 1

3

まず街 2 から街 1 に移動して、その後再び街 2 へと戻り、次に街 3 へと移動することで、 合計 3 円の通行料で街 1 と街 3 を訪れることができます。


入力例 2

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

出力例 2

4

Score : 6 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

The Kingdom of Soonuke has N towns.

There are M roads in the kingdom. The i-th road connects Town u_i and v_i bidirectionally. You need to pay the toll of 1 yen each time you use a road. We know that any town can be reached from any town by using some number of roads.

Takaaha, a merchant, is now at Town s and wants to make transactions in K towns t_1, t_2, \ldots, t_K

What is the minimum total toll Takaaha needs to pay when he starts at Town s and visit each of the K towns at least once? He does not need to come back to Town s in the end.

Note that using the same road multiple times will cost you the toll that number of times.

Constraints

  • All values in input are integers.
  • 2 \leq N \leq 10^5
  • N - 1 \leq M \leq 10^5
  • 1 \leq u_i < v_i \leq N
  • If i \neq j, (u_i, v_i) \neq (u_j, v_j).
  • 1 \leq s \leq N
  • 1 \leq K \leq \min (N - 1, 16)
  • 1 \leq t_i \leq N
  • If i \neq j, t_i \neq t_j.
  • s \neq t_i

Input

Input is given from Standard Input in the following format:

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M
s
K
t_1 t_2 \ldots t_K

Output

Print the minimum total toll Takaaha needs to pay, as an integer.


Sample Input 1

3 2
1 2
2 3
2
2
1 3

Sample Output 1

3

If we go from Town 2 to Town 1, then go back to Town 2, then go to Town 3, we can visit the towns 1 and 3 with the total toll of 3 yen.


Sample Input 2

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

Sample Output 2

4
N - 入れ替えと並び替え

実行時間制限: 3.5 sec / メモリ制限: 1024 MB

配点 : 6

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

長さ N の数列 a_1, a_2, \ldots, a_N があります。 最初、a_i = i です。

この数列に対するクエリが Q 個与えられます。

i 番目のクエリの内容は t_i, x_i, y_i3 つの整数によって表され、その意味は以下の通りです。

  • t_i = 1 のとき、a_{x_i}a_{x_i + 1} をスワップする
  • t_i = 2 のとき、a_{x_i}, a_{x_i + 1}, \ldots a_{y_i} を昇順に並べ替える

全てのクエリを順番に処理したあとの数列 a を出力してください。

制約

  • 入力は全て整数である。
  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • t_i1 または 2 である。
  • t_i = 1 のとき、1 \leq x_i < N かつ y_i = 0 が成り立つ。
  • t_i = 2 のとき、1 \leq x_i < y_i \leq N が成り立つ。

入力

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

N Q
t_1 x_1 y_1
t_2 x_2 y_2
\vdots
t_Q x_Q y_Q

出力

全てのクエリを順番に処理したあとの a の要素を空白区切りで出力せよ。


入力例 1

5 3
1 1 0
1 2 0
2 2 4

出力例 1

2 1 3 4 5
  • 1 番目のクエリを処理すると a2, 1, 3, 4, 5 になります。
  • 2 番目のクエリを処理すると a2, 3, 1, 4, 5 になります。
  • 3 番目のクエリを処理すると a2, 1, 3, 4, 5 になります。

入力例 2

10 15
1 3 0
1 5 0
1 4 0
1 2 0
1 3 0
2 4 7
1 5 0
1 7 0
1 9 0
1 8 0
2 3 5
1 8 0
1 9 0
1 5 0
1 2 0

出力例 2

1 2 4 5 3 6 8 7 9 10

Score : 6 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

We have a sequence of length N: a_1, a_2, \ldots, a_N. Initially, a_i = i.

You will be given Q queries regarding this sequence.

The i-th query will be described by three integers t_i, x_i, and y_i, as follows:

  • if t_i = 1, swap a_{x_i} and a_{x_i + 1};
  • if t_i = 2, rearrange a_{x_i}, a_{x_i + 1}, \ldots a_{y_i} in ascending order.

Print the sequence a after all the queries are processed in order.

Constraints

  • All values in input are integers.
  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • t_i is 1 or 2.
  • If t_i = 1, then 1 \leq x_i < N and y_i = 0.
  • If t_i = 2, then 1 \leq x_i < y_i \leq N.

Input

Input is given from Standard Input in the following format:

N Q
t_1 x_1 y_1
t_2 x_2 y_2
\vdots
t_Q x_Q y_Q

Output

Print the elements of a after all the queries are processed in order, with space in between.


Sample Input 1

5 3
1 1 0
1 2 0
2 2 4

Sample Output 1

2 1 3 4 5
  • After the first query is processed, a is 2, 1, 3, 4, 5.
  • After the second query is processed, a is 2, 3, 1, 4, 5.
  • After the third query is processed, a is 2, 1, 3, 4, 5.

Sample Input 2

10 15
1 3 0
1 5 0
1 4 0
1 2 0
1 3 0
2 4 7
1 5 0
1 7 0
1 9 0
1 8 0
2 3 5
1 8 0
1 9 0
1 5 0
1 2 0

Sample Output 2

1 2 4 5 3 6 8 7 9 10
O - 輪投げ

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

配点 : 6

注意

この問題に対する言及は、2020/6/6 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。

問題文

あなたは、1 から N までの番号が振られた N 本の棒を使って輪投げをします。

輪投げは ラウンド 1、ラウンド 2、ラウンド 33 つのラウンドに分かれていて、各ラウンドではあなたは必ず M 本の相異なる棒に輪を命中させます。輪は必ずすべて投げなければならず、各ラウンドで命中させた輪はそのラウンドが終わっても棒に残されることに注意してください。

ラウンド i で輪を棒 j に命中させると、あなたは (A_{j} \times (B_{j})^{i} \mod R_{i}) 点を得ます。

しかし、同じ棒にたくさん輪がかかっているのは面白くありません。各棒にかかっている輪の個数の一様性をできるだけ保たせるために、次のルールが追加されます: すべてのラウンドが終了した後、1 個以上の輪がかかっている各棒 j について、かかっている輪の個数が i のとき、あなたの得点は A_{j} \times (B_{j}) ^{i} 点減算されます。このため、最終得点は負となる可能性もあります。

あなたは、各ラウンドにどの棒を命中させるか適切に決めることで最終得点を最大化しようとしています。

制約

  • 入力は全て整数
  • 1 \leq M \leq N \leq 500
  • 2 \leq A_{i}, B_{i} \leq 1000
  • 2 \leq R_{1}, R_{2}, R_{3} \leq 10^{5}

入力

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

N M
A_{1} A_{2} \ldots A_{N}
B_{1} B_{2} \ldots B_{N}
R_{1} R_{2} R_{3}

出力

あなたの最終得点の最大値を整数として出力せよ。


入力例 1

2 1
3 2
3 3
100000 100000 100000

出力例 1

81
  • ラウンド 1, 2, 3 のそれぞれにおいて、輪を棒 1 に命中させて得られる得点は 9, 27, 81 点です。
  • ラウンド 1, 2, 3 のそれぞれにおいて、輪を棒 2 に命中させて得られる得点は 6, 18, 54 点です。
  • すべてのラウンドの終了後、棒 1 に輪が 1, 2, 3 本かかっているときに減点される点数は、それぞれ 9, 27, 81 点です。
  • すべてのラウンドの終了後、棒 2 に輪が 1, 2, 3 本かかっているときに減点される点数は、それぞれ 6, 18, 54 点です。

最適な戦略は、ラウンド 1 では輪を棒 2 に、ラウンド 2, 3 では輪を棒 1 に命中させることです。


入力例 2

4 2
2 4 3 3
4 2 3 3
100000 100000 100000

出力例 2

210

入力例 3

20 19
3 2 3 4 3 3 2 3 2 2 3 3 4 3 2 4 4 3 3 4
2 3 4 2 4 3 3 2 4 2 4 3 3 2 3 4 4 4 2 2
3 4 5

出力例 3

-1417

Score : 6 points

Warning

Do not make any mention of this problem until June 6, 2020, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).

Problem Statement

You are playing a quoits game with N pins numbered from 1 to N.

The game is divided into three rounds, round 1, round 2, and round 3. In each round, you will hit exactly M distinct pins by throwing hoops. You have to throw all the hoops, and the hoops you have made encircle the pins (i.e. hit) in each round will remain in that place until the game ends.

If you hit the pin j in the round i, you will gain (A_{j} \times (B_{j})^{i} \mod R_{i}) points.

However, having the same pins encircled by many hoops is not exciting. In order to encourage the uniformity of the number of hits for each pin, you get another rule: after the game is over, if the pin j is being encircled by a positive number of hoops, in particular, by i hoops, then you will lose A_{j} \times (B_{j}) ^{i} points. Thus, your total points might be negative.

You want to maximize the total points you can get by wisely deciding which set of pins you will hit in each round.

Constraints

  • All the values in the input are integers.
  • 1 \leq M \leq N \leq 500
  • 2 \leq A_{i}, B_{i} \leq 1000
  • 2 \leq R_{1}, R_{2}, R_{3} \leq 10^{5}

Input

Input is given from Standard Input in the following format:

N M
A_{1} A_{2} \ldots A_{N}
B_{1} B_{2} \ldots B_{N}
R_{1} R_{2} R_{3}

Output

Print a single integer - the maximum possible total points you can gain.


Sample Input 1

2 1
3 2
3 3
100000 100000 100000

Sample Output 1

81

In each round, if you hit the pin 1, you will gain 9, 27, 81 points, respectively.

In each round, if you hit the pin 2, you will gain 6, 18, 54 points, respectively.

After the all rounds end, if the pin 1 is encircled by 1, 2, 3 hoops, then you will lose 9, 27, 81 points, respectively.

After the all rounds end, if the pin 2 is encircled by 1, 2, 3 hoops, then you will lose 6, 18, 54 points, respectively.

The optimal way in this example is to hit the pin 2 in the round 1 and hit the pin 1 in the round 2, and 3.


Sample Input 2

4 2
2 4 3 3
4 2 3 3
100000 100000 100000

Sample Output 2

210

Sample Input 3

20 19
3 2 3 4 3 3 2 3 2 2 3 3 4 3 2 4 4 3 3 4
2 3 4 2 4 3 3 2 4 2 4 3 3 2 3 4 4 4 2 2
3 4 5

Sample Output 3

-1417