#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define ll long long
int cmp(const void *a, const void * b){
int *p1 = (int*)a;
int *p2 = (int*)b;
return *p1 - *p2;
}
int newnum(int n){ //tra ve so moi lon nhat co cung do dai newnum(-7310) - > -1073
int soam = n < 0; //so am = 1 khi n <0;
int a[10] = {0}; //bieu dien cac chu so
int scs = 0; //tinh so chu so cua n
if(soam){
n *= -1;
}
while(n){
a[scs++] = n % 10;
n /= 10;
}
qsort(a, scs, sizeof(int), cmp);
int res = 0;
if(soam){
int p = 0;
while(a[p] == 0) p++;
res = res * 10 + a[p];
for(int i = 0; i < p; i++) res = res * 10;
p++;
for(p; p < scs; p++) res = res * 10 + a[p];
return -1 * res;
}else{
//[0,1,2,3] -> 3210 lap tu scs -> 0;
for(int p = scs-1; p >=0; p--) res = res * 10 + a[p];
return res;
}
}
void solve(){
int n; scanf("%d", &n);
int a[n];
for(int i=0; i <n; i++){
scanf("%d", a + i);
a[i] = newnum(a[i]);
}
qsort(a, n, sizeof(int), cmp);
for(int i=n-1; i >=0; i--){
printf("%d ", a[i]);
}
}
int main(){
int typetest = 0;
if(typetest){
int t; scanf("%d", &t);
while(t--){
solve();
}
}else solve();
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2RlZmluZSBsbCBsb25nIGxvbmcKCmludCBjbXAoY29uc3Qgdm9pZCAqYSwgY29uc3Qgdm9pZCAqIGIpewogICAgaW50ICpwMSA9IChpbnQqKWE7CiAgICBpbnQgKnAyID0gKGludCopYjsKICAgIHJldHVybiAqcDEgIC0gKnAyOwp9CgppbnQgbmV3bnVtKGludCBuKXsgIC8vdHJhIHZlIHNvIG1vaSBsb24gbmhhdCBjbyBjdW5nIGRvIGRhaSBuZXdudW0oLTczMTApIC0gPiAtMTA3MwogICAgaW50IHNvYW0gPSAgbiA8IDA7ICAvL3NvIGFtID0gMSBraGkgbiA8MDsKICAgIGludCBhWzEwXSA9IHswfTsgLy9iaWV1IGRpZW4gY2FjIGNodSBzbyAKICAgIGludCBzY3MgPSAwOyAvL3Rpbmggc28gY2h1IHNvIGN1YSBuCiAgICBpZihzb2FtKXsKICAgICAgICBuICo9IC0xOwogICAgfQogICAgd2hpbGUobil7CiAgICAgICAgICAgIGFbc2NzKytdID0gbiAlIDEwOwogICAgICAgICAgICBuIC89IDEwOwogICAgfQogICAgcXNvcnQoYSwgc2NzLCBzaXplb2YoaW50KSwgY21wKTsKICAgIGludCByZXMgPSAwOwogICAgaWYoc29hbSl7CiAgICAgICAgaW50IHAgPSAwOwogICAgICAgIHdoaWxlKGFbcF0gPT0gMCkgcCsrOwogICAgICAgIHJlcyA9IHJlcyAqIDEwICArIGFbcF07CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IHA7IGkrKykgcmVzID0gcmVzICogMTA7CiAgICAgICAgcCsrOwogICAgICAgIGZvcihwOyBwIDwgc2NzOyBwKyspIHJlcyA9IHJlcyAqIDEwICsgYVtwXTsKICAgICAgICByZXR1cm4gLTEgKiByZXM7CiAgICB9ZWxzZXsKICAgICAgICAvL1swLDEsMiwzXSAtPiAzMjEwIGxhcCB0dSBzY3MgLT4gMDsKICAgICAgICBmb3IoaW50IHAgPSBzY3MtMTsgcCA+PTA7IHAtLSkgcmVzID0gcmVzICogMTAgKyBhW3BdOwogICAgICAgIHJldHVybiByZXM7CiAgICB9Cn0KCgp2b2lkIHNvbHZlKCl7CiAgICBpbnQgbjsgc2NhbmYoIiVkIiwgJm4pOwogICAgaW50IGFbbl07CiAgICBmb3IoaW50IGk9MDsgaSA8bjsgaSsrKXsKICAgICAgICBzY2FuZigiJWQiLCBhICsgaSk7CiAgICAgICAgYVtpXSA9IG5ld251bShhW2ldKTsKICAgIH0KICAgIHFzb3J0KGEsIG4sIHNpemVvZihpbnQpLCBjbXApOwogICAgZm9yKGludCBpPW4tMTsgaSA+PTA7IGktLSl7CiAgICAgICAgcHJpbnRmKCIlZCAiLCBhW2ldKTsKICAgIH0KfQoKaW50IG1haW4oKXsKICAgIGludCB0eXBldGVzdCA9IDA7CiAgICBpZih0eXBldGVzdCl7CiAgICAgICAgaW50IHQ7IHNjYW5mKCIlZCIsICZ0KTsKICAgICAgICB3aGlsZSh0LS0pewogICAgICAgICAgICBzb2x2ZSgpOwogICAgICAgIH0KICAgIH1lbHNlIHNvbHZlKCk7Cn0=