#K2641. Form the Largest Number

    ID: 24782 Type: Default 1000ms 256MiB

Form the Largest Number

Form the Largest Number

You are given a list of non-negative integers. Your task is to arrange them such that when concatenated, they form the largest possible number. Note that the resulting number should not contain any unnecessary leading zeros; if the number is zero, then the output should be "0".

Hint: Use a custom comparator that compares two numbers by their concatenated results, e.g. compare the strings "a+b" and "b+a" to determine the order.

The problem can be thought of in a greedy manner using string comparisons. If needed, refer to the formula for string concatenation ordering: given two strings \(a\) and \(b\), the order is decided by evaluating whether \(a+b > b+a\) to place \(a\) before \(b\).

inputFormat

The first line of input contains an integer n, which represents the number of integers.

The second line contains n space-separated non-negative integers.

outputFormat

Output a single line containing the largest number formed by concatenating the given integers.

## sample
5
10 2 9 39 17
93921710