import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; ArrayList> list = new ArrayList<>(); for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); list.add(getHashMap(arr[i])); } for (int i = 0; i < n - 2; i++) { HashMap target = list.get(i); int min = Integer.MAX_VALUE; int minIdx = 0; for (int j = i + 1; j < n; j++) { HashMap current = list.get(j); int sum = 1; for (int x : current.keySet()) { sum *= getInt(x, current.get(x), target.getOrDefault(x, 0)); } if ((min == sum && arr[minIdx] > arr[j]) || min > sum) { min = sum; minIdx = j; } } int tmp = arr[i + 1]; arr[i + 1] = arr[minIdx]; arr[minIdx] = tmp; HashMap tMap = list.get(i + 1); list.set(i + 1, list.get(minIdx)); list.set(minIdx, tMap); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { if (i > 0) { sb.append(" "); } sb.append(arr[i]); } System.out.println(sb); } static int getInt(int base, int left, int right) { return pow(base, Math.max(0, left - right)); } static int pow(int x, int p) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x, p / 2); } else { return pow(x, p - 1) * x; } } static HashMap getHashMap(int x) { HashMap ans = new HashMap<>(); for (int i = 2; i <= Math.sqrt(x); i++) { while (x % i == 0) { ans.put(i, ans.getOrDefault(i, 0) + 1); x /= i; } } if (x > 0) { ans.put(x, ans.getOrDefault(x, 0) + 1); } return ans; } }