## Another Sorting

View as PDF

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Sorting seems to be a big topic right now, so magicalsoup decides to create his own kind of sorting. Since he can't really code, he asks you to help him code his sorting algorithm. His sorting algorithm goes likes this:

He sorts the numbers by its unit digit in ascending order. For example, if the numbers were 12, 11, 13, the numbers would be 11, 12, 13.

If there are ties, break them by putting the bigger number first.

For example, given the array 59 107 99 27 13 47 51.

The array will be first sorted by their units digit, so the array becomes 51 13 107 27 47 59 99.

Then the array will be sorted in descending order, so the array now becomes 51 13 107 47 27 99 59.

#### Input Specification

First line: an integer .

The next line will contain space separated integers, , representing the elements of the array.

#### Output Specification

Output the sorted array on one line, with a space separating each of the elements.

#### Sample Input

6
33 33 88 88 83 38

#### Sample Output

83 33 33 88 88 38

#### Sample Explanation

The array will first be sorted by its units digit, so it becomes 33 33 83 88 88 38.

Then it's sorted by its value in descending order, so now it becomes 83 33 33 88 88 38.