#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
int mass[n];
for (int i = 0; i < n; i++) {
cin >> mass[i];
}
for (int i = 0; i < n; i++){
for (int j = 1; j < (n - i); j++) {
if (mass[j] % 10 < mass[j-1] % 10) {
swap (mass[j-1], mass[j]);
}
else if ( mass[j] % 10 == mass[j-1] % 10 and mass[j] < mass[j-1]){
swap (mass[j-1], mass[j]);
}
}
}
for (int i = 0; i < n; i++) {
cout << mass[i] << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmludCBtYWluKCkgewoJaW50IG47CgljaW4gPj4gbjsKICAgIGludCBtYXNzW25dOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgIAljaW4gPj4gbWFzc1tpXTsKICAgIH0KICAgIAoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspewoJCWZvciAoaW50IGogPSAxOyBqIDwgKG4gLSBpKTsgIGorKykgewogICAgIAlpZiAobWFzc1tqXSAlIDEwIDwgbWFzc1tqLTFdICUgMTApIHsKICAgICAgICAgICAgICAgIHN3YXAgKG1hc3Nbai0xXSwgbWFzc1tqXSk7CiAgICAgCX0gCiAgICAgCWVsc2UgaWYgKCBtYXNzW2pdICUgMTAgPT0gbWFzc1tqLTFdICUgMTAgYW5kIG1hc3Nbal0gPCBtYXNzW2otMV0pewogICAgIAkJc3dhcCAobWFzc1tqLTFdLCBtYXNzW2pdKTsKICAgICAJfQoJCX0KCX0KCiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIGNvdXQgPDwgbWFzc1tpXSA8PCAiICI7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==