#K9611. Largest Concatenated Number

    ID: 39014 Type: Default 1000ms 256MiB

Largest Concatenated Number

Largest Concatenated Number

You are given a list of non-negative integers. Your task is to arrange them such that they form the largest possible number when concatenated together.

For example, given the numbers [50, 2, 1, 9], the largest number that can be formed is 95021. The key idea is to sort the numbers (converted to strings) by comparing the concatenated results in different orders. In mathematical terms, for two numbers with string representations \(x\) and \(y\), you should order them such that the condition
\( x+y \ge y+x \)
holds (where \(x+y\) denotes the concatenation of \(x\) followed by \(y\)).

inputFormat

The first line contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated non-negative integers.

outputFormat

Output a single line containing the largest concatenated number that can be formed from the given integers.

## sample
4
50 2 1 9
95021