#C8091. Form the Largest Number by Concatenation

    ID: 52035 Type: Default 1000ms 256MiB

Form the Largest Number by Concatenation

Form the Largest Number by Concatenation

Given a list of non-negative integers, arrange them such that they form the largest possible number when concatenated. For example, given the numbers [10, 2, 9], the largest number is 9210 and for [3, 30, 34, 5, 9] it is 9534330.

The key idea is to sort the numbers (as strings) with a custom comparator such that for any two numbers x and y, the order is determined by whether x+y is greater than y+x in lexicographical order. Note that if the largest number after sorting is 0, it implies all numbers are zeros, and the result should simply be 0.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains an integer n (1 ≤ n ≤ 105), representing the number of integers.
  2. The second line contains n non-negative integers separated by spaces.

outputFormat

Output to standard output (stdout) a single line containing the largest number formed by concatenating the given integers.

## sample
1
1
1