#K57087. Sort by Digit Sum

    ID: 30342 Type: Default 1000ms 256MiB

Sort by Digit Sum

Sort by Digit Sum

Given a list of non-negative integers, your task is to sort the list based on the sum of their digits. In other words, for any two integers \(a\) and \(b\), if the digit sum of \(a\) is less than the digit sum of \(b\), then \(a\) should appear before \(b\) in the sorted list. If two numbers have the same digit sum, the smaller number should come first.

The digit sum of an integer \(n\) is defined as \(\sum_{i} d_i\), where \(d_i\) represents each digit in \(n\). For example, the digit sum of 103 is \(1+0+3=4\).

You are required to read from stdin and output the result to stdout as described in the input and output sections.

inputFormat

The first line contains an integer \(n\) (where \(n \geq 0\)), which represents the number of integers to sort. The second line contains \(n\) space-separated non-negative integers.

outputFormat

Output the sorted list in a single line with each number separated by a single space.

## sample
5
56 32 103 12 97
12 103 32 56 97