#137Medium
Largest number
Time: 1 s · Memory: 256 MB
- Sorting
Statement
You are given non-negative integers. They are written one after another in some order to form a single number. Find the largest number that can be formed.
Input format
The first line contains (). The second line contains integers ().
Output format
A single number — the largest result, without extra leading zeros.
Examples
Input
5 3 30 34 5 9
Output
9534330
Input
2 10 2
Output
210
Note
Sorting by value is wrong: needs 210, so goes first. Sorting the strings lexicographically is wrong too: for 330 > 303. The right comparator puts before if a + b > b + a (string concatenation). In the first example the answer is 9534330.
If all numbers are , the answer is 0, not 000.
Source: UVa 10905.
