Sorting by the last digit

Rust Easy sorting

Task «Sorting by the last digit»

Write a program that reads an array of integers and sorts it in ascending order by the last digit of each number. If the last digits match, the original order is preserved (stable sort). 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 separated by spaces.

Output Format

One line with N numbers, sorted by the last digit, separated by spaces.

Examples

Example 1

INPUT
5 12 23 34 45 56
OUTPUT
12 23 34 45 56

Example 2

INPUT
4 91 72 83 64
OUTPUT
91 72 83 64

Example 3

INPUT
3 10 20 30
OUTPUT
10 20 30
main.rs