import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; ArrayList in = new ArrayList(); ArrayList out = new ArrayList(); //1個目は固定 out.add(sc.nextInt()); for (int i = 1; i < n; i++) { in.add(sc.nextInt()); } in.sort(null); while (!in.isEmpty()) { int fixed = out.get(out.size() - 1); ArrayList primes = getPrime(fixed); boolean get = false; for (int i = 0; i < in.size(); i++) { int target = in.get(i); if(target == 1){ break; } for (int prime : primes) { if (target % prime == 0) { out.add(target); in.remove(i); i--; get = true; } } } if (!get) { out.add(in.get(0)); in.remove(0); } } System.out.print(out.get(0)); for (int i = 1; i < out.size(); i++) { System.out.print(" " + out.get(i)); } System.out.println(); } private static ArrayList getPrime(int source) { ArrayList ret = new ArrayList(); for (int i = 2; source != 1; i++) { while (source % i == 0) { ret.add(i); source /= i; } } return ret; } }