#C14621. Largest Number

    ID: 44291 Type: Default 1000ms 256MiB

Largest Number

Largest Number

Given a list of non-negative integers, rearrange them to form the largest possible number. In other words, order the integers such that when concatenated, they yield the maximum numerical value possible.

For example, given the list [54, 546, 548, 60], the largest possible number is 6054854654.

Note: If the list is empty, output an empty string. If the list consists exclusively of zeros, output a single "0".

The key observation is that for any two numbers \(x\) and \(y\), you must compare the two concatenated strings \(x||y\) and \(y||x\) (i.e., in LaTeX: $x\Vert y$ and $y\Vert x$) to decide their order.

inputFormat

The input is given in two lines:

  • The first line contains an integer \(N\) $(0 \leq N \leq 10^5)$, representing the number of integers.
  • The second line contains \(N\) space-separated non-negative integers.

outputFormat

Output a single line containing the largest possible number (as a string) formed by concatenating the given integers. If the resulting number has leading zeros, output a single "0".

## sample
4
54 546 548 60
6054854654