#include <iostream>
using namespace std;
const int MAX_SIZE = 1000;
const int TEN = 10;
int reverseNum(int num) {
int reverse = 0;
while (num) {
reverse = reverse * TEN + num % TEN;
num /= TEN;
}
return reverse;
}
int existAllReverses(int fr[]) {
for (int i = 0; i < MAX_SIZE; ++i) {
if (fr[i] % TEN != 0 && fr[i] != fr[reverseNum(i)]) {
return 1;
}
}
return -1;
}
int main() {
int n, fr[MAX_SIZE] = {0};
cin >> n;
for (int i = 0; i < n; ++i) {
int currentNum;
cin >> currentNum;
++fr[currentNum];
}
int order = existAllReverses(fr);
if (order > 0) {
for (int i = 0; i < MAX_SIZE; ++i) {
if (fr[i]) {
cout << i << ' ';
}
}
} else {
for (int i = MAX_SIZE - 1; i >= 0; --i) {
if (fr[i]) {
cout << i << ' ';
}
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1BWF9TSVpFID0gMTAwMDsKY29uc3QgaW50IFRFTiA9IDEwOwoKaW50IHJldmVyc2VOdW0oaW50IG51bSkgewogICAgaW50IHJldmVyc2UgPSAwOwogICAgd2hpbGUgKG51bSkgewogICAgICAgIHJldmVyc2UgPSByZXZlcnNlICogVEVOICsgbnVtICUgVEVOOwogICAgICAgIG51bSAvPSBURU47CiAgICB9CiAgICByZXR1cm4gcmV2ZXJzZTsKfQoKaW50IGV4aXN0QWxsUmV2ZXJzZXMoaW50IGZyW10pIHsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTUFYX1NJWkU7ICsraSkgewogICAgICAgIGlmIChmcltpXSAlIFRFTiAhPSAwICYmIGZyW2ldICE9IGZyW3JldmVyc2VOdW0oaSldKSB7CiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAtMTsKfQoKaW50IG1haW4oKSB7CiAgICBpbnQgbiwgZnJbTUFYX1NJWkVdID0gezB9OwogICAgY2luID4+IG47CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47ICsraSkgewogICAgICAgIGludCBjdXJyZW50TnVtOwogICAgICAgIGNpbiA+PiBjdXJyZW50TnVtOwogICAgICAgICsrZnJbY3VycmVudE51bV07CiAgICB9CiAgICBpbnQgb3JkZXIgPSBleGlzdEFsbFJldmVyc2VzKGZyKTsKICAgIGlmIChvcmRlciA+IDApIHsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IE1BWF9TSVpFOyArK2kpIHsKICAgICAgICAgICAgaWYgKGZyW2ldKSB7CiAgICAgICAgICAgICAgICBjb3V0IDw8IGkgPDwgJyAnOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfSBlbHNlIHsKICAgICAgICBmb3IgKGludCBpID0gTUFYX1NJWkUgLSAxOyBpID49IDA7IC0taSkgewogICAgICAgICAgICBpZiAoZnJbaV0pIHsKICAgICAgICAgICAgICAgIGNvdXQgPDwgaSA8PCAnICc7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQ==