import sys def readint(): x = 0 ch = sys.stdin.read(1) while '0' <= ch <= '9': x = x * 10 + int(ch) ch = sys.stdin.read(1) return x def writeint(x): buf = [] while x != 0: buf.append(x % 10) x //= 10 while len(buf) != 0: sys.stdout.write(str(buf.pop())) N = readint() LIMIT = 0 A = [0] * 10240 cnt = [0] * 10240 divpos = [0] * 10240 divsep = [0] * 10240 divs = [0] * 94208 canuse = [False] * 10240 for i in range(N): A[i] = readint() if LIMIT < A[i]: LIMIT = A[i] for i in range(1, N): cnt[A[i]] += 1 for i in range(1, LIMIT + 1): for j in range(i, LIMIT + 1, i): divsep[j + 2] += 1 for i in range(1, LIMIT + 1): divsep[i + 2] += divsep[i + 1] for i in range(1, LIMIT + 1): for j in range(i, LIMIT + 1, i): divs[divsep[j + 1]] = i divsep[j + 1] += 1 preval = A[0] for i in range(1, N): canuse[A[i]] = True writeint(A[0]) while True: optval = -1 optlcm = (1 << 30) for i in range(divsep[preval], divsep[preval + 1]): x = divs[i] while divpos[x] <= LIMIT and not canuse[divpos[x]]: divpos[x] += x if divpos[x] <= LIMIT: curlcm = preval // x * divpos[x] if optlcm > curlcm: optlcm = curlcm optval = divpos[x] if optval == -1: break for i in range(cnt[optval]): sys.stdout.write(' ') writeint(optval) canuse[optval] = False preval = optval sys.stdout.write('\n')