実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
4 枚のカードがあり、それぞれのカードには整数 A,B,C,D が書かれています。
ここに 1 枚カードを加え、フルハウスとできるか判定してください。
ただし、 5 枚組のカードは以下の条件を満たすとき、またそのときに限って、フルハウスであると呼ばれます。
- 異なる整数 x,y について、 x が書かれたカード 3 枚と y が書かれたカード 2 枚からなる。
制約
- 入力は全て整数
- 1 \le A,B,C,D \le 13
入力
入力は以下の形式で標準入力から与えられる。
A B C D
出力
1 枚カードを加えてフルハウスとできる場合は Yes 、そうでないときは No と出力せよ。
入力例 1
7 7 7 1
出力例 1
Yes
7,7,7,1 に 1 を加えた時、フルハウスとなります。
入力例 2
13 12 11 10
出力例 2
No
13,12,11,10 に何を加えてもフルハウスにはなりません。
入力例 3
3 3 5 5
出力例 3
Yes
3,3,5,5 に 3 を加えた時、フルハウスとなります。
また、 5 を加えてもフルハウスとなります。
入力例 4
8 8 8 8
出力例 4
No
8,8,8,8 に何を加えてもフルハウスにはなりません。
同じ 5 枚のカードはフルハウスではないことに注意してください。
入力例 5
1 3 4 1
出力例 5
No
Score : 100 points
Problem Statement
There are four cards with integers A,B,C,D written on them.
Determine whether a Full House can be formed by adding one card.
A set of five cards is called a Full House if and only if the following condition is satisfied:
- For two distinct integers x and y, there are three cards with x written on them and two cards with y written on them.
Constraints
- All input values are integers.
- 1 \le A,B,C,D \le 13
Input
The input is given from Standard Input in the following format:
A B C D
Output
If adding one card can form a Full House, print Yes; otherwise, print No.
Sample Input 1
7 7 7 1
Sample Output 1
Yes
Adding 1 to 7,7,7,1 forms a Full House.
Sample Input 2
13 12 11 10
Sample Output 2
No
Adding anything to 13,12,11,10 does not form a Full House.
Sample Input 3
3 3 5 5
Sample Output 3
Yes
Adding 3,3,5,5 to 3 forms a Full House.
Also, adding 5 forms a Full House.
Sample Input 4
8 8 8 8
Sample Output 4
No
Adding anything to 8,8,8,8 does not form a Full House.
Note that five identical cards do not form a Full House.
Sample Input 5
1 3 4 1
Sample Output 5
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
整数 K が与えられます。
英大文字を A から昇順に K 個繋げて得られる文字列を答えてください。
制約
- K は 1 以上 26 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
K
出力
答えを出力せよ。
入力例 1
3
出力例 1
ABC
英大文字は A から昇順に A, B, C, ... です。
A から昇順に 3 個繋げて得られる文字列は ABC です。
入力例 2
1
出力例 2
A
Score : 100 points
Problem Statement
You are given an integer K.
Print a string that is a concatenation of the first K uppercase English letters in ascending order, starting from A.
Constraints
- K is an integer between 1 and 26, inclusive.
Input
The input is given from Standard Input in the following format:
K
Output
Print the answer.
Sample Input 1
3
Sample Output 1
ABC
The uppercase English letters in ascending order are A, B, C, ...
By concatenating the first three uppercase English letters, we get ABC.
Sample Input 2
1
Sample Output 2
A
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋君はゲームの中で洞窟を探索しています。
洞窟は N 個の部屋が一列に並んだ構造であり、入り口から順に部屋 1,2,\ldots,N と番号がついています。
最初、高橋君は部屋 1 におり、持ち時間 は T です。
各 1 \leq i \leq N-1 について、持ち時間を A_i 消費することで、部屋 i から部屋 i+1 へ移動することができます。これ以外に部屋を移動する方法はありません。
また、持ち時間が 0 以下になるような移動は行うことができません。
洞窟内には M 個のボーナス部屋があります。i 番目のボーナス部屋は部屋 X_i であり、この部屋に到達すると持ち時間が Y_i 増加します。
高橋君は部屋 N にたどりつくことができますか?
制約
- 2 \leq N \leq 10^5
- 0 \leq M \leq N-2
- 1 \leq T \leq 10^9
- 1 \leq A_i \leq 10^9
- 1 < X_1 < \ldots < X_M < N
- 1 \leq Y_i \leq 10^9
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N M T
A_1 A_2 \ldots A_{N-1}
X_1 Y_1
X_2 Y_2
\vdots
X_M Y_M
出力
高橋君が部屋 N にたどりつくことができるなら Yes を、できないなら No を出力せよ。
入力例 1
4 1 10 5 7 5 2 10
出力例 1
Yes
- 高橋君は最初、部屋 1 にいて持ち時間は 10 です。
- 持ち時間を 5 消費して部屋 2 に移動します。持ち時間は 5 になります。その後、持ち時間が 10 増え 15 になります。
- 持ち時間を 7 消費して部屋 3 に移動します。持ち時間は 8 になります。
- 持ち時間を 5 消費して部屋 4 に移動します。持ち時間は 3 になります。
入力例 2
4 1 10 10 7 5 2 10
出力例 2
No
部屋 1 から部屋 2 へ移動することができません。
Score : 200 points
Problem Statement
Takahashi is exploring a cave in a video game.
The cave consists of N rooms arranged in a row. The rooms are numbered Room 1,2,\ldots,N from the entrance.
Takahashi is initially in Room 1, and the time limit is T.
For each 1 \leq i \leq N-1, he may consume a time of A_i to move from Room i to Room (i+1). There is no other way to move between rooms.
He cannot make a move that makes the time limit 0 or less.
There are M bonus rooms in the cave. The i-th bonus room is Room X_i; when he arrives at the room, the time limit increases by Y_i.
Can Takahashi reach Room N?
Constraints
- 2 \leq N \leq 10^5
- 0 \leq M \leq N-2
- 1 \leq T \leq 10^9
- 1 \leq A_i \leq 10^9
- 1 < X_1 < \ldots < X_M < N
- 1 \leq Y_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M T
A_1 A_2 \ldots A_{N-1}
X_1 Y_1
X_2 Y_2
\vdots
X_M Y_M
Output
If Takahashi can reach Room N, print Yes; otherwise, print No.
Sample Input 1
4 1 10 5 7 5 2 10
Sample Output 1
Yes
- Takahashi is initially in Room 1, and the time limit is 10.
- He consumes a time of 5 to move to Room 2. Now the time limit is 5. Then, the time limit increases by 10; it is now 15.
- He consumes a time of 7 to move to Room 3. Now the time limit is 8.
- He consumes a time of 5 to move to Room 4. Now the time limit is 3.
Sample Input 2
4 1 10 10 7 5 2 10
Sample Output 2
No
He cannot move from Room 1 to Room 2.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
いろはちゃんは長さ N ( N \ge 1 ) の正整数列 A=(A_1,A_2,\dots,A_N) を持っています。
いろはちゃんは A を使って、次のように文字列 S を生成しました。
- S=
|から始める。 - i=1,2,\dots,N の順に、次の操作を行う。
- S の末尾に
-を A_i 個追加する。 - その後、 S の末尾に
|を 1 個追加する。
- S の末尾に
生成された文字列 S が与えられるので、正整数列 A を復元してください。
制約
- S は問題文中の方法で生成された長さ 3 以上 100 以下の文字列
- A は長さ 1 以上の正整数列
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを以下の形式で、 1 行に空白区切りで出力せよ。
A_1 A_2 \dots A_N
入力例 1
|---|-|----|-|-----|
出力例 1
3 1 4 1 5
S= |---|-|----|-|-----| が生成されるような A は (3,1,4,1,5) です。
入力例 2
|----------|
出力例 2
10
入力例 3
|-|-|-|------|
出力例 3
1 1 1 6
Score : 200 points
Problem Statement
Iroha has a sequence of positive integers A = (A_1, A_2, \dots, A_N) of length N (N \ge 1).
She generated a string S using A as follows:
- Start with S =
|. - For i = 1, 2, \dots, N, perform the following operations in order:
- Append A_i copies of
-to the end of S. - Then, append one
|to the end of S.
- Append A_i copies of
Given the generated string S, reconstruct the sequence A.
Constraints
- S is a string of length between 3 and 100, inclusive, generated by the method in the problem statement.
- A is a sequence of positive integers of length at least 1.
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer in the following format, with elements separated by spaces in a single line:
A_1 A_2 \dots A_N
Sample Input 1
|---|-|----|-|-----|
Sample Output 1
3 1 4 1 5
S = |---|-|----|-|-----| is generated by A = (3, 1, 4, 1, 5).
Sample Input 2
|----------|
Sample Output 2
10
Sample Input 3
|-|-|-|------|
Sample Output 3
1 1 1 6
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
非負整数 n が次の条件を満たすとき、n を 良い整数 と呼びます。
- n を 10 進法で表したときに、偶数の数字 (0, 2, 4, 6, 8) のみが登場する。
例えば 0、68 および 2024 は良い整数です。
整数 N が与えられます。良い整数のうち小さい方から N 番目の整数を求めてください。
制約
- 1 \leq N \leq 10^{12}
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
小さい方から N 番目の良い整数を出力せよ。
入力例 1
8
出力例 1
24
良い整数を小さい方から順に並べると 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots となります。
小さい方から 8 番目の良い整数は 24 なので、これを出力します。
入力例 2
133
出力例 2
2024
入力例 3
31415926535
出力例 3
2006628868244228
Score: 300 points
Problem Statement
A non-negative integer n is called a good integer when it satisfies the following condition:
- All digits in the decimal notation of n are even numbers (0, 2, 4, 6, and 8).
For example, 0, 68, and 2024 are good integers.
You are given an integer N. Find the N-th smallest good integer.
Constraints
- 1 \leq N \leq 10^{12}
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the N-th smallest good integer.
Sample Input 1
8
Sample Output 1
24
The good integers in ascending order are 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots.
The eighth smallest is 24, which should be printed.
Sample Input 2
133
Sample Output 2
2024
Sample Input 3
31415926535
Sample Output 3
2006628868244228
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
1,2,\dots,N がちょうど 3 回ずつ現れる長さ 3N の数列 A=(A_1,A_2,\dots,A_{3N}) が与えられます。
i=1,2,\dots,N について、A の中にある i のうち真ん中にあるものの添字を f(i) と定めます。 1,2,\dots,N を f(i) の昇順に並べ替えてください。
f(i) の定義は厳密には以下の通りです。
- A_j = i を満たす j が j=\alpha,\beta,\gamma\ (\alpha < \beta < \gamma) であるとする。このとき、f(i) = \beta である。
制約
- 1\leq N \leq 10^5
- 1 \leq A_j \leq N
- i=1,2,\dots,N それぞれについて、A の中に i はちょうど 3 回現れる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
A_1 A_2 \dots A_{3N}
出力
1,2,\dots,N を f(i) の昇順に並べ替えてできる長さ N の数列を空白区切りで出力せよ。
入力例 1
3 1 1 3 2 3 2 2 3 1
出力例 1
1 3 2
- A の中にある 1 は A_1,A_2,A_9 なので、f(1) = 2 です。
- A の中にある 2 は A_4,A_6,A_7 なので、f(2) = 6 です。
- A の中にある 3 は A_3,A_5,A_8 なので、f(3) = 5 です。
よって、f(1) < f(3) < f(2) であるため 1,3,2 の順に出力します。
入力例 2
1 1 1 1
出力例 2
1
入力例 3
4 2 3 4 3 4 1 3 1 1 4 2 2
出力例 3
3 4 1 2
Score : 250 points
Problem Statement
You are given a sequence A=(A_1,A_2,\dots,A_{3N}) of length 3N where each of 1,2,\dots, and N occurs exactly three times.
For i=1,2,\dots,N, let f(i) be the index of the middle occurrence of i in A. Sort 1,2,\dots,N in ascending order of f(i).
Formally, f(i) is defined as follows.
- Suppose that those j such that A_j = i are j=\alpha,\beta,\gamma\ (\alpha < \beta < \gamma). Then, f(i) = \beta.
Constraints
- 1\leq N \leq 10^5
- 1 \leq A_j \leq N
- i occurs in A exactly three times, for each i=1,2,\dots,N.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
A_1 A_2 \dots A_{3N}
Output
Print the sequence of length N obtained by sorting 1,2,\dots,N in ascending order of f(i), separated by spaces.
Sample Input 1
3 1 1 3 2 3 2 2 3 1
Sample Output 1
1 3 2
- 1 occurs in A at A_1,A_2,A_9, so f(1) = 2.
- 2 occurs in A at A_4,A_6,A_7, so f(2) = 6.
- 3 occurs in A at A_3,A_5,A_8, so f(3) = 5.
Thus, f(1) < f(3) < f(2), so 1,3, and 2 should be printed in this order.
Sample Input 2
1 1 1 1
Sample Output 2
1
Sample Input 3
4 2 3 4 3 4 1 3 1 1 4 2 2
Sample Output 3
3 4 1 2
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
N \times N のマス目があります。上から i 行目、左から j 列目のマスを (i,j) と表します。
始め、(1,1) に駒が 1 個置かれています。あなたは以下の操作を何度でも行うことができます。
- 今駒が置かれているマスと距離がちょうど \sqrt{M} であるマスに駒を移動させる。
ここで、マス (i,j) とマス (k,l) の距離は \sqrt{(i-k)^2+(j-l)^2} とします。
全てのマス (i,j) に対して、以下の問題を解いてください。
- 駒を (1,1) から (i,j) に移動させることができるかを判定し、できる場合は操作回数の最小値を求めてください。
制約
- 1 \le N \le 400
- 1 \le M \le 10^6
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M
出力
N 行出力せよ。i 行目には N 個の整数を出力せよ。i 行目の j 個目の出力は、マス (i,j) に駒を移動させることができるのであれば操作回数の最小値を、そうでないのであれば -1 を出力せよ。
入力例 1
3 1
出力例 1
0 1 2 1 2 3 2 3 4
駒は上下左右の 4 個のマスに移動することができます。
例えば (2,2) に移動するには、以下のように 2 回の操作を行えばよいです。
- 今駒は (1,1) に置かれている。(1,1) と (1,2) の距離はちょうど \sqrt{1} であるため、駒を (1,2) に移動させる。
- 今駒は (1,2) に置かれている。(1,2) と (2,2) の距離はちょうど \sqrt{1} であるため、駒を (2,2) に移動させる。
入力例 2
10 5
出力例 2
0 3 2 3 2 3 4 5 4 5 3 4 1 2 3 4 3 4 5 6 2 1 4 3 2 3 4 5 4 5 3 2 3 2 3 4 3 4 5 6 2 3 2 3 4 3 4 5 4 5 3 4 3 4 3 4 5 4 5 6 4 3 4 3 4 5 4 5 6 5 5 4 5 4 5 4 5 6 5 6 4 5 4 5 4 5 6 5 6 7 5 6 5 6 5 6 5 6 7 6
Score : 400 points
Problem Statement
There is a grid with N \times N squares. We denote by (i, j) the square at the i-th row from the top and j-th column from the left.
Initially, a piece is placed on (1, 1). You may repeat the following operation any number of times:
- Let (i, j) be the square the piece is currently on. Move the piece to the square whose distance from (i, j) is exactly \sqrt{M}.
Here, we define the distance between square (i, j) and square (k, l) as \sqrt{(i-k)^2+(j-l)^2}.
For all squares (i, j), determine if the piece can reach (i, j). If it can, find the minimum number of operations required to do so.
Constraints
- 1 \le N \le 400
- 1 \le M \le 10^6
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M
Output
Print N lines. The i-th line should contain N integers. If the piece can reach (i, j), the j-th integer in the i-th line should be the minimum number of operations required to do so; otherwise, it should be -1.
Sample Input 1
3 1
Sample Output 1
0 1 2 1 2 3 2 3 4
You can move the piece to four adjacent squares.
For example, we can move the piece to (2,2) with two operations as follows.
- The piece is now on (1,1). The distance between (1,1) and (1,2) is exactly \sqrt{1}, so move the piece to (1,2).
- The piece is now on (1,2). The distance between (1,2) and (2,2) is exactly \sqrt{1}, so move the piece to (2,2).
Sample Input 2
10 5
Sample Output 2
0 3 2 3 2 3 4 5 4 5 3 4 1 2 3 4 3 4 5 6 2 1 4 3 2 3 4 5 4 5 3 2 3 2 3 4 3 4 5 6 2 3 2 3 4 3 4 5 4 5 3 4 3 4 3 4 5 4 5 6 4 3 4 3 4 5 4 5 6 5 5 4 5 4 5 4 5 6 5 6 4 5 4 5 4 5 6 5 6 7 5 6 5 6 5 6 5 6 7 6
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 450 点
問題文
N 頂点からなる重み付き無向グラフ G があります。 G の各頂点には 1 から N までの番号が付けられています。 最初、G には辺が 1 本も存在しません。
今から、M 回の操作を行うことによって G に辺を追加していきます。 i\ (1\leq i\leq M) 回目の操作は以下の通りです。
- K_i 頂点からなる頂点の部分集合 S_i=\lbrace A_{i,1},A_{i,2},\dots,A_{i,K_i}\rbrace が与えられる。 u,v\in S_i かつ u<v を満たす全ての u,v について、頂点 u と頂点 v の間に重み C_i の辺を追加する。
M 回の操作を全て行ったとき G が連結になるか判定し、連結になるならば G の最小全域木に含まれる辺の重みの総和を求めてください。
制約
- 2\leq N \leq 2\times 10^5
- 1\leq M \leq 2\times 10^5
- 2\leq K_i \leq N
- \displaystyle \sum_{i=1}^{M} K_i \leq 4\times 10^5
- 1\leq A_{i,1} < A_{i,2} < \dots < A_{i,K_i}\leq N
- 1\leq C_i\leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M
K_1 C_1
A_{1,1} A_{1,2} \dots A_{1,K_1}
K_2 C_2
A_{2,1} A_{2,2} \dots A_{2,K_2}
\vdots
K_M C_M
A_{M,1} A_{M,2} \dots A_{M,K_M}
出力
M 回の操作を全て行ったとき G が連結にならないならば -1 を、連結になるならば G の最小全域木に含まれる辺の重みの総和を出力せよ。
入力例 1
4 3 3 3 1 2 3 2 2 1 2 3 4 1 3 4
出力例 1
9

左の図は M 回の操作を全て行ったあとの G を、右の図はその最小全域木の 1 つを表しています(辺の横に書かれた数はその辺の重みを示します)。
最小全域木に含まれる辺の重みの総和は 3+2+4=9 です。
入力例 2
3 2 2 1 1 2 2 1 1 2
出力例 2
-1
M 回の操作を全て行っても G は連結になりません。
入力例 3
10 5 6 158260522 1 3 6 8 9 10 10 877914575 1 2 3 4 5 6 7 8 9 10 4 602436426 2 6 7 9 6 24979445 2 3 4 5 8 10 4 861648772 2 4 8 9
出力例 3
1202115217
Score: 450 points
Problem Statement
You are given a weighted undirected graph G with N vertices, numbered 1 to N. Initially, G has no edges.
You will perform M operations to add edges to G. The i-th operation (1 \leq i \leq M) is as follows:
- You are given a subset of vertices S_i=\lbrace A_{i,1},A_{i,2},\dots,A_{i,K_i}\rbrace consisting of K_i vertices. For every pair u, v such that u, v \in S_i and u < v, add an edge between vertices u and v with weight C_i.
After performing all M operations, determine whether G is connected. If it is, find the total weight of the edges in a minimum spanning tree of G.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 2 \leq K_i \leq N
- \sum_{i=1}^{M} K_i \leq 4 \times 10^5
- 1 \leq A_{i,1} < A_{i,2} < \dots < A_{i,K_i} \leq N
- 1 \leq C_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
K_1 C_1
A_{1,1} A_{1,2} \dots A_{1,K_1}
K_2 C_2
A_{2,1} A_{2,2} \dots A_{2,K_2}
\vdots
K_M C_M
A_{M,1} A_{M,2} \dots A_{M,K_M}
Output
If G is not connected after all M operations, print -1. If G is connected, print the total weight of the edges in a minimum spanning tree of G.
Sample Input 1
4 3 3 3 1 2 3 2 2 1 2 3 4 1 3 4
Sample Output 1
9

The left diagram shows G after all M operations, and the right diagram shows a minimum spanning tree of G (the numbers next to the edges indicate their weights).
The total weight of the edges in the minimum spanning tree is 3 + 2 + 4 = 9.
Sample Input 2
3 2 2 1 1 2 2 1 1 2
Sample Output 2
-1
G is not connected even after all M operations.
Sample Input 3
10 5 6 158260522 1 3 6 8 9 10 10 877914575 1 2 3 4 5 6 7 8 9 10 4 602436426 2 6 7 9 6 24979445 2 3 4 5 8 10 4 861648772 2 4 8 9
Sample Output 3
1202115217
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 550 点
問題文
数字のみからなる N 個の文字列 S_1,\ldots,S_N が与えられます。
これらからちょうど K 個を選んで好きな順序で連結した文字列を、(先頭の余分なゼロを除いて)十進表記の整数として解釈したときの値として考えられる最大値を求めてください。
なお、全ての文字が 0 である文字列を、先頭の余分なゼロを除いて十進表記の整数として解釈したときの値は 0 であるとします。
制約
- 1 \leq K \leq N \leq 10^5
- S_i は数字のみからなる長さ 1 以上 10 以下の文字列
- N,K は整数である
入力
入力は以下の形式で標準入力から与えられる。
N K S_1 \vdots S_N
出力
答えを出力せよ。
入力例 1
3 2 123 45 6
出力例 1
45123
123, 45, 6 から 2 個選んで連結してできる文字列は 12345, 1236, 45123, 456, 6123, 645 の 6 種類あります。
これを十進表記の整数と解釈したときの最大値は 45123 です。
入力例 2
5 3 00000 00 1 0000 000
出力例 2
1000000000
入力例 3
9 9 0000000001 000000002 00000003 0000004 000005 00006 0007 008 09
出力例 3
90080007000060000050000004000000030000000020000000001
答えは先頭の余分なゼロなしで出力する必要があります。
Score : 550 points
Problem Statement
You are given N strings S_1,\ldots,S_N consisting of digits.
Find the maximum possible value, when interpreted as a decimal integer (after removing extra leading zeros), of a string obtained by choosing exactly K of these strings and concatenating them in any order of your choice.
Here, the value obtained by interpreting a string consisting entirely of the character 0 as a decimal integer after removing extra leading zeros is defined to be 0.
Constraints
- 1 \leq K \leq N \leq 10^5
- S_i is a string of length between 1 and 10 (inclusive) consisting of digits.
- N and K are integers.
Input
The input is given from Standard Input in the following format:
N K S_1 \vdots S_N
Output
Output the answer.
Sample Input 1
3 2 123 45 6
Sample Output 1
45123
There are six strings obtained by choosing two of 123, 45, 6 and concatenating them: 12345, 1236, 45123, 456, 6123, 645.
Among these, the maximum value when interpreted as a decimal integer is 45123.
Sample Input 2
5 3 00000 00 1 0000 000
Sample Output 2
1000000000
Sample Input 3
9 9 0000000001 000000002 00000003 0000004 000005 00006 0007 008 09
Sample Output 3
90080007000060000050000004000000030000000020000000001
The answer must be output without extra leading zeros.