#include <bits/stdc++.h>
using namespace std;
int n, i, j, s, aux, v[102], w[102], x;
bool ok;
int main()
{
ifstream f("sortcif.in");
ofstream g("sortcif.out");
f >> n;
for(i = 1; i <= n; i ++)
{
f >> v[i];
x = v[i];
s = 0;
while(x)
{
s = s + x % 10;
x = x / 10;
}
w[i] = s;
}
do
{
ok = true;
for(i = 1; i < n; i ++)
if(w[i] > w[i+1])
{
aux = w[i];
w[i] = w[i + 1];
w[i + 1] = aux;
aux = v[i];
v[i] = v[i + 1];
v[i + 1] = aux;
ok = false;
}
}while(!ok);
for(i = 1; i <= n; i ++)
g << v[i] << " ";
return 0;
}