F - Maximum Concatenation Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

問題文

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

A の異なる 2 つの要素を選びそれらを文字列として結合して得られる整数の最大値を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^8
  • 入力される値はすべて整数

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

4
2 12 323 50

出力例 1

50323

50, 323 をこの順に結合して得られる 50323 が最大値となります。


入力例 2

2
100000000 100000000

出力例 2

100000000100000000

数列 A 内の異なる場所から選ばれた 2 要素であれば、それらの値が等しくても異なる要素とみなされます。


入力例 3

8
3 14 15 9 26 53 5 89

出力例 3

8953

Problem Statement

You are given an integer sequence A = (A_1, A_2, \ldots, A_N) of length N.

Find the maximum integer that can be obtained by choosing two distinct elements from A and concatenating them as strings.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^8
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

4
2 12 323 50

Sample Output 1

50323

The maximum value can be obtained by concatenating 50 and 323 in this order: 50323.


Sample Input 2

2
100000000 100000000

Sample Output 2

100000000100000000

Two elements are considered distinct if they are chosen from different positions in the sequence A, even if they have the same value.


Sample Input 3

8
3 14 15 9 26 53 5 89

Sample Output 3

8953