
import java.util.*;
import java.io.*;

class Num implements Comparable<Num>{
	int x;
	public Num(int x) {
		this.x = x;
	}
	public int compareTo (Num x2){
		if (this.x == x2.x){			
			return 0;
		}else{
			if (this.x < x2.x)
				return -1;
			else {
				return 1;
			}
		}
		
	}
}

class Number  {
	
	ArrayList<ArrayList<Num>>nums = new ArrayList<ArrayList<Num>>();
		
	public Number() throws Exception{
		Scanner in = new Scanner(new File("numbers.in"));
		PrintWriter out = new PrintWriter("numbers.out");
		int k = in.nextInt();
		
		for(int l =0; l<k; l++)
			nums.add(new ArrayList<Num>());
		
		while(in.hasNextInt()){
			int n = in.nextInt();
			int i = n % k;
			
			nums.get(i).add(new Num(n));
		}
		
		for(int i = 1; i< nums.size(); i++){
			Collections.sort(nums.get(i));
			ArrayList<Num> e = nums.get(i);
			for(int j = 0; j<e.size();j++ )
				out.print(e.get(j).x + " ");
		}
		Collections.sort(nums.get(0));
		ArrayList<Num> e = nums.get(0);
		for(int j = 0; j<e.size();j++ )
		out.print(e.get(j).x + " ");
	
		in.close();
		out.close();
	}
	
}
public class Snumbers{
	public static void main(String[] args) throws Exception{
	new Number();	
	}
}
