Module: Sorting with comparator


Problem

4 /11


Sort by sum of digits

Theory Click to read/hide

According to the condition of the problem, it is clear that it is necessary to apply stable (stable) sorting, therefore, instead of sort, stable_sort should be used.

Problem

Write a program that sorts natural numbers in an array in descending order by the sum of the digits of the decimal representation of the number. If the sums of the digits are equal, the numbers must retain the original order.

Input
The first line contains the array size N . The second line contains N numbers separated by spaces – array elements. It is guaranteed that 0 < N ≤ 10000 .

Imprint
The program should display in one line the elements of the array, sorted in descending order by the sum of the digits of the decimal representation of the number, separating them with spaces.
 
Input Output
6
9 21 32 55 81 11
55 9 81 32 21 11