from collections import defaultdict import heapq from math import gcd def getdiv(n): res = set() for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.add(i) res.add(n // i) return tuple(sorted(res)) N = int(input()) A = list(map(int, input().split())) div = [getdiv(a) for a in A] d = defaultdict(list) for i, a in enumerate(A): for x in div[i]: heapq.heappush(d[x], (a, i)) seen = [0] * N seen[0] = 1 ans = [0] a = A[0] now = 0 for _ in range(N - 1): min_val = 10 ** 18 min_x = -1 for x in div[now]: while d[x] and seen[d[x][0][1]]: heapq.heappop(d[x]) if not d[x]: continue tmp_val = d[x][0][0]//x if tmp_val < min_val: min_val = tmp_val min_x = x a, now = heapq.heappop(d[min_x]) ans.append(now) seen[now] = 1 print(*[A[i] for i in ans])