package test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
/**
*
*
* @author michael
*/
public class Test {
public static void main(String[] args) throws IOException {
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String text;
while (!((text = buf.readLine()) == null || "".equals(text))) {
int number = Integer.parseInt(text);
text = buf.readLine();
String[] in = text.split(" ");
Arrays.sort(in, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
long a = Integer.parseInt(o1);
long b = Integer.parseInt(o2);
Long ans;
ans = a % 10 - b % 10;
if (ans != 0) {
return ans.intValue();
}
ans = b - a ;
if (ans != 0) {
return ans.intValue();
}
return 0;
}
});
for (String string : in) {
System.out.print(string + " ");
}
System.out.println();
}
}
}