Stable Sort by Digit Sum


Submit solution

Points: 100
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

Stably sort non-negative integers by the sum of their decimal digits.

Input

The first line contains \(n\). The second line contains \(n\) non-negative integers.

The input satisfies:

  • \(0 <= n <= 1000\)

Output

Print the sorted values separated by spaces. Values with equal digit sum retain their input order.

Example

Input
5
231 123 321 456 100
Output
100 321 231 123 456

Comments

There are no comments at the moment.