#C753. Largest Possible Number

    ID: 51411 Type: Default 1000ms 256MiB

Largest Possible Number

Largest Possible Number

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

For example, given the array \( [3, 30, 34, 5, 9] \), the largest formed number is 9534330.

The idea is to sort the numbers not by their numerical value but by a custom comparison: for any two numbers \(a\) and \(b\), we compare the concatenated strings \(ab\) and \(ba\) in lexicographical order. If \(ab > ba\), then \(a\) should come before \(b\) in the sorted order.

inputFormat

The input is given in two lines:

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

outputFormat

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

## sample
5
3 30 34 5 9
9534330