Олимпиадный тренинг

Задача 45241. Sort by sum of digits


Given an array of integers. Sort the array by non-increasing sum of digits of each number. If the sum of the digits of two numbers is equal, the numbers must follow in descending order.

Input
The program receives as input in the first line a natural number n - the size of the array. The second line contains n integers a- array elements (1 <= n <= 1031  ;<= ai <= 104).

Imprint
Output the resulting array.
 
 
Examples
# Input Output
1 4
1 43 ​​12 10
43 12 10 1

Запрещенные операторы:sort