from heapq import heappop, heappush, heapify n = int(input()) A = list(map(int,input().split())) count = [0]*(10**4+5) h = [] for a in A[1:]: count[a] += 1 heappush(h, a) now = A[0] ans = [now] cand = [[] for i in range(10**4+5)] for i in range(10**4+1): if count[i] or now==i: for j in range(i,10**4+2,i): if count[j]: cand[i].append(j) cand[i] = cand[i][::-1] for i in range(n-1): cand2 = [] for j in range(1,int(now**0.5)+1): if now%j == 0: if count[j]: cand2.append(j) if count[now//j]: cand2.append(now//j) if cand2 == []: while count[h[0]] == 0: heappop(h) while cand[now] and count[cand[now][-1]] == 0: cand[now].pop() if cand[now] == [] or h[0]*now <= cand[now][-1]: nex = heappop(h) else: nex = cand[now].pop() else: cand2.sort() nex = cand2[0] count[nex] -= 1 ans.append(nex) now = nex print(*ans)