upp = 1000 mem = [[-1] * upp for i in range(upp)] def fast_gcd(x, y): if x < upp and y < upp and mem[x][y] != -1: return mem[x][y] mem[x][y] = x if not y else fast_gcd(y, x % y) return mem[x][y] n = int(input()) a = list(map(int, input().split())) for i in range(n - 1): x = i + 1 r = a[x] / fast_gcd(a[i], a[x]) for j in range(i + 2, n): t = a[j] / fast_gcd(a[i], a[j]) if t < r or (t == r and a[j] < a[x]): r, x = t, j a[i + 1], a[x] = a[x], a[i + 1] print(*a)