#C9380. Custom Digit Sum Sort

    ID: 53467 Type: Default 1000ms 256MiB

Custom Digit Sum Sort

Custom Digit Sum Sort

You are given a list of subject codes represented by integers. Your task is to sort these codes according to the following rules:

  • The primary key of sorting is the sum of digits of the number, in non-decreasing order. In other words, if we denote the sum of digits of a number \(n\) as \(S(n)\), then the numbers should be sorted in increasing order of \(S(n)\).
  • If two numbers have the same digit sum, they should be sorted by their numeric value in non-decreasing order.

For example, if the input is 56 23 89 12 34, the digit sums are \(5+6=11,\; 2+3=5,\; 8+9=17,\; 1+2=3,\; 3+4=7\) respectively. Thus, after sorting, the expected output is 12 23 34 56 89 each on a new line.

Note: All formulas are represented in \(\LaTeX\) format when applicable.

inputFormat

The first line contains a single integer \(n\) representing the number of subject codes.

The second line contains \(n\) space-separated integers representing the subject codes.

Input is read from standard input (stdin).

outputFormat

Output the sorted subject codes, one per line, according to the rules described above.

Output is written to standard output (stdout).

## sample
5
56 23 89 12 34
12

23 34 56 89

</p>