One day, Gary woke up to realize that the foundations of mathematics had been completely restructured overnight.
It turns out that adding two numbers now means writing them side by side; that is, adding the digit number and the digit number is now defined as:
For example, , and .
Mr. Ing draws positive integers on the board, and he asks the class to determine the maximum possible sum of all integers, provided they can be ordered in any way possible. Gary gets a little nervous when everyone else raises their hands almost instantly, and he needs your help to solve the question.
Input Specification
On the first line will be . On the next lines, a single integer denoting one of the numbers Ing has written upon the board.
Output Specification
The maximum possible sum that can be obtained by adding the numbers together in any order. Keep in mind that the output will be possibly extremely long and thus may not fit in a 128-bit integer.
Sample Input 1
4
1
2
3
4
Sample Output 1
4321
Sample Input 2
4
2
32
555
16
Sample Output 2
55532216
Comments
This comment is hidden due to too much negative feedback. Show it anyway.
https://www.geeksforgeeks.org/lexicographically-smallest-string-obtained-concatenating-array/