#C3878. Forming the Largest Number

    ID: 47353 Type: Default 1000ms 256MiB

Forming the Largest Number

Forming the Largest Number

You are given a list of non-negative integers. Your task is to arrange the numbers such that they form the largest possible number when concatenated together. More formally, given a sequence of integers (a_1, a_2, \dots, a_n), you need to find a permutation (p_1, p_2, \dots, p_n) such that the concatenated number (S = p_1p_2\cdots p_n) is maximized.

Note that if the resulting number has leading zeros (i.e. the first character is '0'), then the answer should be simply "0".

For example, if the input is 10 2, the largest number is 210; if the input is 3 30 34 5 9, the largest possible number is 9534330.

inputFormat

The input is read from standard input (stdin). The first line contains an integer (n) representing the number of elements. The second line contains (n) space-separated non-negative integers.

outputFormat

Output a single line containing the largest number that can be formed by concatenating the given integers.## sample

2
10 2
210

</p>