実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
英大文字および英小文字からなる文字列 S が与えられます。
ここで、 S のうちちょうど 1 文字だけが英大文字であり、それ以外は全て英小文字です。
大文字が S の先頭から何文字目に登場するか出力してください。
ただし、S の先頭の文字を 1 文字目とします。
制約
- S は英大文字および英小文字からなる長さ 2 以上 100 以下の文字列
- S に大文字はちょうど 1 つ含まれる。
入力
入力は以下の形式で標準入力から与えられる。
S
出力
大文字が S の先頭から何文字目に登場するかを、整数で出力せよ。
入力例 1
aBc
出力例 1
2
aBc
の先頭から 1 文字目は a
, 2 文字目は B
, 3 文字目は c
であり、
このうち大文字は 2 文字目です。
よって、2 を出力します。
入力例 2
xxxxxxXxxx
出力例 2
7
S=xxxxxxXxxx
の 7 文字目に、大文字である X
が登場しています。よって、7 を出力します。
入力例 3
Zz
出力例 3
1
Score : 100 points
Problem Statement
You are given a string S consisting of uppercase and lowercase English letters.
Here, exactly one character of S is uppercase, and the others are all lowercase.
Find the integer x such that the x-th character of S is uppercase.
Here, the initial character of S is considered the 1-st one.
Constraints
- S is a string of length between 2 and 100, inclusive, consisting of uppercase and lowercase English letters.
- S has exactly one uppercase letter.
Input
The input is given from Standard Input in the following format:
S
Output
Print the integer x such that the x-th character of S is uppercase.
Sample Input 1
aBc
Sample Output 1
2
The 1-st character of aBc
is a
, the 2-nd is B
, and the 3-rd is c
;
the 2-nd character is uppercase.
Thus, 2 should be printed.
Sample Input 2
xxxxxxXxxx
Sample Output 2
7
An uppercase letter X
occurs as the 7-th character of S=xxxxxxXxxx
, so 7 should be printed.
Sample Input 3
Zz
Sample Output 3
1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
水圧は水深のみに依存し、水深 x [m] の場所では \dfrac{x}{100} [MPa] になるものとします。
水深 D [m] の場所の水圧は何 [MPa] ですか?
制約
- 1 \leq D \leq 10000
- D は整数である。
入力
入力は以下の形式で標準入力から与えられる。
D
出力
答えを出力せよ。想定解答との絶対誤差または相対誤差が 10^{-3} 以下であれば正解として扱われる。
入力例 1
1000
出力例 1
10
水深 1000 [m] の場所の水圧は 10 [MPa] です。10.0
や 9.999999
などを出力しても正解となります。
入力例 2
50
出力例 2
0.5
入力例 3
3141
出力例 3
31.41
Score : 100 points
Problem Statement
Let us assume that water pressure depends only on depth and is \dfrac{x}{100} megapascal at a depth of x meters.
What is the water pressure in megapascals at a depth of D meters?
Constraints
- 1 \leq D \leq 10000
- D is an integer.
Input
Input is given from Standard Input in the following format:
D
Output
Print the answer. Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-3}.
Sample Input 1
1000
Sample Output 1
10
The water pressure at a depth of 1000 meters is 10 megapascal. Outputs such as 10.0
and 9.999999
would also be accepted.
Sample Input 2
50
Sample Output 2
0.5
Sample Input 3
3141
Sample Output 3
31.41
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
4 桁の暗証番号 X_1X_2X_3X_4 が与えられます。 番号は先頭の桁が 0 であることもあり得ます。 暗証番号は以下のいずれかの条件をみたすとき弱い暗証番号と呼ばれます。
- 4 桁とも同じ数字である。
- 1\leq i\leq 3 をみたす任意の整数 i について、 X_{i+1} が、 X_i の次の数字である。 ただし、 0\leq j\leq 8 について j の次の数字は j+1 であり、 9 の次の数字は 0 である。
与えられた暗証番号が弱い暗証番号ならば Weak
を、そうでないならば Strong
を出力してください。
制約
- 0 \leq X_1, X_2, X_3, X_4 \leq 9
- X_1, X_2, X_3, X_4 は整数である。
入力
入力は以下の形式で標準入力から与えられる。
X_1X_2X_3X_4
出力
与えられた暗証番号が弱い暗証番号ならば Weak
を、そうでないならば Strong
を出力せよ。
入力例 1
7777
出力例 1
Weak
4 桁ともすべて 7 であるため、 1 つめの条件をみたしており、弱い暗証番号です。
入力例 2
0112
出力例 2
Strong
1 桁目と 2 桁目が異なっており、 3 桁目は 2 桁目の次の数字ではないため、どちらの条件もみたしていません。
入力例 3
9012
出力例 3
Weak
9 の次の数字が 0 であることに注意してください。
Score : 200 points
Problem Statement
You are given a 4-digit PIN: X_1X_2X_3X_4, which may begin with a 0. The PIN is said to be weak when it satisfies one of the following conditions:
- All of the four digits are the same.
- For each integer i such that 1\leq i\leq 3, X_{i+1} follows X_i. Here, j+1 follows j for each 0\leq j\leq 8, and 0 follows 9.
If the given PIN is weak, print Weak
; otherwise, print Strong
.
Constraints
- 0 \leq X_1, X_2, X_3, X_4 \leq 9
- X_1, X_2, X_3, and X_4 are integers.
Input
Input is given from Standard Input in the following format:
X_1X_2X_3X_4
Output
If the given PIN is weak, print Weak
; otherwise, print Strong
.
Sample Input 1
7777
Sample Output 1
Weak
All four digits are 7, satisfying the first condition, so this PIN is weak.
Sample Input 2
0112
Sample Output 2
Strong
The first and second digits differ, and the third digit does not follow the second digit, so neither condition is satisfied.
Sample Input 3
9012
Sample Output 3
Weak
Note that 0 follows 9.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 匹のヘビがいます。
はじめ、i 匹目のヘビの太さは T_i、長さは L_i です。
ヘビの重さは太さと長さの積となります。
1 \leq k \leq D を満たす各整数 k について、すべてのヘビの長さが k 伸びたときの最も重いヘビの重さを求めてください。
制約
- 1 \leq N, D \leq 100
- 1 \leq T_i, L_i \leq 100
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N D T_1 L_1 T_2 L_2 \vdots T_N L_N
出力
D 行出力せよ。k 行目には、すべてのヘビの長さが k 伸びたときの最も重いヘビの重さを出力せよ。
入力例 1
4 3 3 3 5 1 2 4 1 10
出力例 1
12 15 20
すべてのヘビの長さが 1 伸びたとき、ヘビの重さはそれぞれ 12, 10, 10, 11 となるので 1 行目には 12 を出力します。
すべてのヘビの長さが 2 伸びたとき、ヘビの重さはそれぞれ 15, 15, 12, 12 となるので 2 行目には 15 を出力します。
すべてのヘビの長さが 3 伸びたとき、ヘビの重さはそれぞれ 18, 20, 14, 13 となるので 3 行目には 20 を出力します。
入力例 2
1 4 100 100
出力例 2
10100 10200 10300 10400
Score : 200 points
Problem Statement
There are N snakes.
Initially, the thickness of the i-th snake is T_i, and its length is L_i.
The weight of a snake is defined as the product of its thickness and length.
For each integer k satisfying 1 \leq k \leq D, find the weight of the heaviest snake when every snake's length has increased by k.
Constraints
- 1 \leq N, D \leq 100
- 1 \leq T_i, L_i \leq 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N D T_1 L_1 T_2 L_2 \vdots T_N L_N
Output
Print D lines. The k-th line should contain the weight of the heaviest snake when every snake's length has increased by k.
Sample Input 1
4 3 3 3 5 1 2 4 1 10
Sample Output 1
12 15 20
When every snake’s length has increased by 1, the snakes' weights become 12, 10, 10, 11, so print 12 on the first line.
When every snake’s length has increased by 2, the snakes' weights become 15, 15, 12, 12, so print 15 on the second line.
When every snake’s length has increased by 3, the snakes' weights become 18, 20, 14, 13, so print 20 on the third line.
Sample Input 2
1 4 100 100
Sample Output 2
10100 10200 10300 10400
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
長さ N の正整数列 A=(A_1,A_2,\dots,A_N) および正整数 K が与えられます。
1 以上 K 以下の整数のうち、A の中に一度も現れないものの総和を求めてください。
制約
- 1\leq N \leq 2\times 10^5
- 1\leq K \leq 2\times 10^9
- 1\leq A_i \leq 2\times 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
4 5 1 6 3 1
出力例 1
11
1 以上 5 以下の整数のうち、A の中に一度も現れないものは 2,4,5 の 3 つです。
よって、それらの総和である 2+4+5=11 を出力します。
入力例 2
1 3 346
出力例 2
6
入力例 3
10 158260522 877914575 24979445 623690081 262703497 24979445 1822804784 1430302156 1161735902 923078537 1189330739
出力例 3
12523196466007058
Score: 250 points
Problem Statement
You are given a sequence of positive integers A=(A_1,A_2,\dots,A_N) of length N and a positive integer K.
Find the sum of the integers between 1 and K, inclusive, that do not appear in the sequence A.
Constraints
- 1\leq N \leq 2\times 10^5
- 1\leq K \leq 2\times 10^9
- 1\leq A_i \leq 2\times 10^9
- All input values 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 answer.
Sample Input 1
4 5 1 6 3 1
Sample Output 1
11
Among the integers between 1 and 5, three numbers, 2, 4, and 5, do not appear in A.
Thus, print their sum: 2+4+5=11.
Sample Input 2
1 3 346
Sample Output 2
6
Sample Input 3
10 158260522 877914575 24979445 623690081 262703497 24979445 1822804784 1430302156 1161735902 923078537 1189330739
Sample Output 3
12523196466007058
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
N 人のプレイヤーが参加するプログラミングコンテスト World Tour Finals が行われており、競技時間の半分が過ぎました。 このコンテストでは M 問の問題が出題されており、問題 i の点数 A_i は 500 以上 2500 以下の 100 の倍数です。
各 i = 1, \ldots, N について、プレイヤー i がどの問題を既に解いたかを表す文字列 S_i が与えられます。
S_i は o
, x
からなる長さ M の文字列で、S_i の j 文字目が o
のときプレイヤー i は問題 j を既に解いており、x
のときまだ解いていません。
ただし、どのプレイヤーもまだ全ての問題を解いてはいません。
プレイヤー i の総合得点は、解いた問題の点数の合計に、ボーナス点 i 点を加えた点数として計算されます。
さて、各 i = 1, \ldots, N について以下の質問に答えてください。
- プレイヤー i がまだ解いていない問題を少なくとも何問解くことで、プレイヤー i の総合得点が他のプレイヤー全員の現在の総合得点を上回ることができますか?
なお、問題文中の条件と制約から、プレイヤー i が全ての問題を解くことで、他のプレイヤー全員の現在の総合得点を上回ることができることが証明できます。 このことから、答えは常に定義されることに注意してください。
制約
- 2\leq N\leq 100
- 1\leq M\leq 100
- 500\leq A_i\leq 2500
- A_i は 100 の倍数
- S_i は
o
,x
からなる長さ M の文字列 - S_i には
x
が一個以上含まれる - 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \ldots A_M S_1 S_2 \vdots S_N
出力
N 行出力せよ。 i 行目にはプレイヤー i に関する質問の答えを出力せよ。
入力例 1
3 4 1000 500 700 2000 xxxo ooxx oxox
出力例 1
0 1 1
競技時間の半分の経過時の各プレイヤーの総合得点は、プレイヤー 1 が 2001 点、プレイヤー 2 が 1502 点、プレイヤー 3 が 1703 点です。
プレイヤー 1 は 1 問も解かずとも、他のプレイヤー全員の総合得点を上回っています。
プレイヤー 2 は、例えば問題 4 を解けば総合得点が 3502 点となり、他のプレイヤー全員の総合得点を上回ります。
プレイヤー 3 も、例えば問題 4 を解けば総合得点が 3703 点となり、他のプレイヤー全員の総合得点を上回ります。
入力例 2
5 5 1000 1500 2000 2000 2500 xxxxx oxxxx xxxxx oxxxx oxxxx
出力例 2
1 1 1 1 0
入力例 3
7 8 500 500 500 500 500 500 500 500 xxxxxxxx oxxxxxxx ooxxxxxx oooxxxxx ooooxxxx oooooxxx ooooooxx
出力例 3
7 6 5 4 3 2 0
Score : 250 points
Problem Statement
The programming contest World Tour Finals is underway, where N players are participating, and half of the competition time has passed. There are M problems in this contest, and the score A_i of problem i is a multiple of 100 between 500 and 2500, inclusive.
For each i = 1, \ldots, N, you are given a string S_i that indicates which problems player i has already solved.
S_i is a string of length M consisting of o
and x
, where the j-th character of S_i is o
if player i has already solved problem j, and x
if they have not yet solved it.
Here, none of the players have solved all the problems yet.
The total score of player i is calculated as the sum of the scores of the problems they have solved, plus a bonus score of i points.
For each i = 1, \ldots, N, answer the following question.
- At least how many of the problems that player i has not yet solved must player i solve to exceed all other players' current total scores?
Note that under the conditions in this statement and the constraints, it can be proved that player i can exceed all other players' current total scores by solving all the problems, so the answer is always defined.
Constraints
- 2\leq N\leq 100
- 1\leq M\leq 100
- 500\leq A_i\leq 2500
- A_i is a multiple of 100.
- S_i is a string of length M consisting of
o
andx
. - S_i contains at least one
x
. - All numeric values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \ldots A_M S_1 S_2 \vdots S_N
Output
Print N lines. The i-th line should contain the answer to the question for player i.
Sample Input 1
3 4 1000 500 700 2000 xxxo ooxx oxox
Sample Output 1
0 1 1
The players' total scores at the halfway point of the competition time are 2001 points for player 1, 1502 points for player 2, and 1703 points for player 3.
Player 1 is already ahead of all other players' total scores without solving any more problems.
Player 2 can, for example, solve problem 4 to have a total score of 3502 points, which would exceed all other players' total scores.
Player 3 can also, for example, solve problem 4 to have a total score of 3703 points, which would exceed all other players' total scores.
Sample Input 2
5 5 1000 1500 2000 2000 2500 xxxxx oxxxx xxxxx oxxxx oxxxx
Sample Output 2
1 1 1 1 0
Sample Input 3
7 8 500 500 500 500 500 500 500 500 xxxxxxxx oxxxxxxx ooxxxxxx oooxxxxx ooooxxxx oooooxxx ooooooxx
Sample Output 3
7 6 5 4 3 2 0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
縦 H 行、横 W 行の H \times W マスからなるグリッドがあります。上から i 行目、左から j 列目のマスを (i, j) と表します。
各マスの状態は文字 C_{i, j} で表され、C_{i, j} = .
ならばマス (i, j) は空きマスであり、C_{i, j} = #
ならばマス (i, j) は壁です。
高橋君がグリッド上を歩こうとしています。彼がマス (i, j) にいるとき、マス (i, j + 1) またはマス (i + 1, j) に移動することができます。ただし、グリッドの外に出るような移動や、壁のマスへの移動を行うことはできません。高橋君は、移動することのできるマスが無くなった時点で立ち止まります。
高橋君がマス (1, 1) から歩き始めるとき、彼が立ち止まるまでに通ることのできるマスは最大で何マスですか?
制約
- 1 \leq H, W \leq 100
- H, W は整数
- C_{i, j} =
.
または C_{i, j} =#
(1 \leq i \leq H, 1 \leq j \leq W) - C_{1, 1} =
.
入力
入力は以下の形式で標準入力から与えられる。
H W C_{1, 1} \ldots C_{1, W} \vdots C_{H, 1} \ldots C_{H, W}
出力
答えを出力せよ。
入力例 1
3 4 .#.. ..#. ..##
出力例 1
4
例えば (1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) と進むことで、4 マス通ることができます。
5 マス以上通ることはできないので、4 と出力します。
入力例 2
1 1 .
出力例 2
1
入力例 3
5 5 ..... ..... ..... ..... .....
出力例 3
9
Score : 400 points
Problem Statement
There is a H \times W-square grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left.
Each square is described by a character C_{i, j}, where C_{i, j} = .
means (i, j) is an empty square, and C_{i, j} = #
means (i, j) is a wall.
Takahashi is about to start walking in this grid. When he is on (i, j), he can go to (i, j + 1) or (i + 1, j). However, he cannot exit the grid or enter a wall square. He will stop when there is no more square to go to.
When starting on (1, 1), at most how many squares can Takahashi visit before he stops?
Constraints
- 1 \leq H, W \leq 100
- H and W are integers.
- C_{i, j} =
.
or C_{i, j} =#
. (1 \leq i \leq H, 1 \leq j \leq W) - C_{1, 1} =
.
Input
Input is given from Standard Input in the following format:
H W C_{1, 1} \ldots C_{1, W} \vdots C_{H, 1} \ldots C_{H, W}
Output
Print the answer.
Sample Input 1
3 4 .#.. ..#. ..##
Sample Output 1
4
For example, by going (1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2), he can visit 4 squares.
He cannot visit 5 or more squares, so we should print 4.
Sample Input 2
1 1 .
Sample Output 2
1
Sample Input 3
5 5 ..... ..... ..... ..... .....
Sample Output 3
9
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 475 点
問題文
1 から N の番号がついた N 人の人が輪になってならんでいます。人 1 の右隣には人 2 が、人 2 の右隣には人 3 が、……、人 N の右隣には人 1 がいます。
N 人の人にそれぞれ 0 以上 M 未満の整数を 1 つずつ渡します。
M^N 通りの渡し方のうち、どの隣り合う 2 人が渡された数も異なるものの数を、998244353 で割ったあまりを求めてください。
制約
- 2 \leq N,M \leq 10^6
- N,M は整数である
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
答えを出力せよ。
入力例 1
3 3
出力例 1
6
人 1,2,3 に渡す整数がそれぞれ (0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,0,1),(2,1,0) のときの 6 通りです。
入力例 2
4 2
出力例 2
2
人 1,2,3,4 に渡す整数がそれぞれ (0,1,0,1),(1,0,1,0) のときの 2 通りです。
入力例 3
987654 456789
出力例 3
778634319
998244353 で割ったあまりを求めてください。
Score : 475 points
Problem Statement
There are N people numbered from 1 to N standing in a circle. Person 1 is to the right of person 2, person 2 is to the right of person 3, ..., and person N is to the right of person 1.
We will give each of the N people an integer between 0 and M-1, inclusive.
Among the M^N ways to distribute integers, find the number, modulo 998244353, of such ways that no two adjacent people have the same integer.
Constraints
- 2 \leq N,M \leq 10^6
- N and M are integers.
Input
The input is given from Standard Input in the following format:
N M
Output
Print the answer.
Sample Input 1
3 3
Sample Output 1
6
There are six desired ways, where the integers given to persons 1,2,3 are (0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,0,1),(2,1,0).
Sample Input 2
4 2
Sample Output 2
2
There are two desired ways, where the integers given to persons 1,2,3,4 are (0,1,0,1),(1,0,1,0).
Sample Input 3
987654 456789
Sample Output 3
778634319
Be sure to find the number modulo 998244353.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
N 個の箱 1,2,\dots,N と、 10^{100} 個のボール 1,2,\dots,10^{100} があります。 最初、箱 i にはボール i のみが入っています。
ここに以下の操作が合計 Q 回行われるので、処理してください。
操作にはタイプ 1,2,3 の 3 種類があります。
タイプ 1 : 箱 X に箱 Y の中身を全て入れる。 この操作では X \neq Y が保証される。
1 X Y
タイプ 2 : 現在いずれかの箱に入っているボールの数の合計を k とすると、箱 X にボール k+1 を入れる。
2 X
タイプ 3 : ボール X が入っている箱の番号を答える。
3 X
制約
- 入力は全て整数
- 2 \le N \le 3 \times 10^5
- 1 \le Q \le 3 \times 10^5
- タイプ 1 の操作について、 1 \le X,Y \le N かつ X \neq Y
- タイプ 2 の操作について、 1 \le X \le N
- タイプ 3 の操作について、その時点でボール X がいずれかの箱に入っている
- タイプ 3 の操作が少なくとも 1 つ与えられる
入力
入力は以下の形式で標準入力から与えられる。
但し、 op_i は i 回目の操作を表す。
N Q op_1 op_2 \vdots op_Q
出力
各タイプ 3 の操作に対して、答えを 1 行に 1 つ、整数として出力せよ。
入力例 1
5 10 3 5 1 1 4 2 1 2 4 3 7 1 3 1 3 4 1 1 4 3 7 3 6
出力例 1
5 4 3 1 3
この入力は 10 個の操作を含みます。
- 1 回目の操作はタイプ 3 です。ボール 5 は箱 5 に入っています。
- 2 回目の操作はタイプ 1 です。箱 1 に箱 4 の中身を全て入れます。
- 箱 1 の中身はボール 1,4 、箱 4 の中身は空になります。
- 3 回目の操作はタイプ 2 です。箱 1 にボール 6 を入れます。
- 4 回目の操作はタイプ 2 です。箱 4 にボール 7 を入れます。
- 5 回目の操作はタイプ 3 です。ボール 7 は箱 4 に入っています。
- 6 回目の操作はタイプ 1 です。箱 3 に箱 1 の中身を全て入れます。
- 箱 3 の中身はボール 1,3,4,6 、箱 1 の中身は空になります。
- 7 回目の操作はタイプ 3 です。ボール 4 は箱 3 に入っています。
- 8 回目の操作はタイプ 1 です。箱 1 に箱 4 の中身を全て入れます。
- 箱 1 の中身はボール 7 、箱 4 の中身は空になります。
- 9 回目の操作はタイプ 3 です。ボール 7 は箱 1 に入っています。
- 10 回目の操作はタイプ 3 です。ボール 6 は箱 3 に入っています。
Score : 500 points
Problem Statement
There are N boxes numbered 1,2,\ldots,N, and 10^{100} balls numbered 1,2,\dots,10^{100}. Initially, box i contains just ball i.
Process a total of Q operations that will be performed.
There are three types of operations: 1, 2, and 3.
Type 1: Put all contents of box Y into box X. It is guaranteed that X \neq Y.
1 X Y
Type 2: Put ball k+1 into box X, where k is the current total number of balls contained in the boxes.
2 X
Type 3: Report the number of the box that contains ball X.
3 X
Constraints
- All values in the input are integers.
- 2 \le N \le 3 \times 10^5
- 1 \le Q \le 3 \times 10^5
- For each type-1 operation, 1 \le X,Y \le N and X \neq Y.
- For each type-2 operation, 1 \le X \le N.
- For each type-3 operation, ball X is contained in some box at that point.
- There is at least one type-3 operation.
Input
The input is given from Standard Input in the following format.
Here, op_i represents the i-th operation.
N Q op_1 op_2 \vdots op_Q
Output
For each type-3 operation, print a line containing the response as an integer.
Sample Input 1
5 10 3 5 1 1 4 2 1 2 4 3 7 1 3 1 3 4 1 1 4 3 7 3 6
Sample Output 1
5 4 3 1 3
This input contains ten operations.
- The first operation is of type 3. Ball 5 is in box 5.
- The second operation is of type 1. Put all contents of box 4 into box 1.
- Box 1 now contains balls 1 and 4, and box 4 is now empty.
- The third operation is of type 2. Put ball 6 into box 1.
- The fourth operation is of type 2. Put ball 7 into box 4.
- The fifth operation is of type 3. Ball 7 is in box 4.
- The sixth operation is of type 1. Put all contents of box 1 into box 3.
- Box 3 now contains balls 1, 3, 4, and 6, and box 1 is now empty.
- The seventh operation is of type 3. Ball 4 is in box 3.
- The eighth operation is of type 1. Put all contents of box 4 into box 1.
- Box 1 now contains ball 7, and box 4 is now empty.
- The ninth operation is of type 3. Ball 7 is in box 1.
- The tenth operation is of type 3. Ball 6 is in box 3.