Sorting by sum of digits and length

JavaScript Medium sorting

Task «Sorting by sum of digits and length»

Write a program that takes an array of integers and sorts it in ascending order of the sum of the digits of each number. If the sum of digits is the same, then the lengths of the numbers (number of digits) are compared. If the lengths are also equal, then the numbers themselves are sorted in ascending order. Print the sorted array separated by spaces.

Input Format

The first line contains an integer N (1 ≤ N ≤ 1000) — the number of values. The second line contains N integers, each not exceeding 10^9 in absolute value, separated by spaces.

Output Format

One line with sorted numbers separated by spaces.

Examples

Example 1

INPUT
4 99 9 999 90
OUTPUT
9 90 99 999

Example 2

INPUT
3
OUTPUT

Example 3

INPUT
3 111 222 333
OUTPUT
111 222 333

Example 4

INPUT
5
OUTPUT
main.js