import math n = int(input()) a = list(map(int, input().split())) for i in range(n): pivot = a[i] s = a[i+1:] s_with_lcm = [((pivot * x) // math.gcd(pivot, x), x) for x in s] s_sorted = sorted(s_with_lcm, key=lambda t: (t[0], t[1])) sorted_x = [x for (lcm, x) in s_sorted] a[i+1:] = sorted_x print(' '.join(map(str, a)))