#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool comp (const int& a, const int& b) {
if (a % 10 == b % 10) return (a < b);
else return a % 10 < b % 10;
}
int main() {
int n, a;
vector<int> array;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
array.push_back(a);
}
sort (array.begin(), array.end(), comp);
for (int a = 0; a < n; a++) {
cout << array[a] << " ";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKYm9vbCBjb21wIChjb25zdCBpbnQmIGEsIGNvbnN0IGludCYgYikgewoJaWYgKGEgJSAxMCA9PSBiICUgMTApIHJldHVybiAoYSA8IGIpOwoJZWxzZSByZXR1cm4gYSAlIDEwIDwgYiAlIDEwOwp9CgppbnQgbWFpbigpIHsKCWludCBuLCBhOwoJdmVjdG9yPGludD4gYXJyYXk7CgljaW4gPj4gbjsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CgkJY2luID4+IGE7CgkJYXJyYXkucHVzaF9iYWNrKGEpOwoJfQoJCglzb3J0IChhcnJheS5iZWdpbigpLCBhcnJheS5lbmQoKSwgY29tcCk7CgkKCWZvciAoaW50IGEgPSAwOyBhIDwgbjsgYSsrKSB7CiAgICAgICAgY291dCA8PCBhcnJheVthXSA8PCAiICI7CiAgICB9CglyZXR1cm4gMDsKfQ==