from math import sqrt, gcd from heapq import heappop, heappush def Divisor(N): ret = [] for i in range(1,int(sqrt(N))+1): if N % i == 0: ret.append(i) if N // i != i: ret.append(N//i) ret.sort() return ret M = 20000 N = int(input()) a = list(map(int,input().split())) D = [] H = [[] for _ in range(M+1)] for i in range(N): D.append(Divisor(a[i])) for k in D[i]: heappush(H[k], (a[i], i)) flg = [True] * N flg[0] = False ans = [a[0]] idx = 0 for _ in range(N-1): lcm = 1<<32 nxt = idx ret = [] for k in D[idx]: while H[k]: A,P = heappop(H[k]) if flg[P]: heappush(H[k], (A, P)) break if not H[k]: continue L = A * a[idx] // gcd(A, a[idx]) if L < lcm or (L == lcm and A < a[nxt]): lcm = L nxt = P flg[nxt] = False ans.append(a[nxt]) idx = nxt print(*ans)