import math n = int(input()) a = list(map(int, input().split())) gcd = math.gcd for i in range(n-1): current = a[i] a[i+1:] = sorted(a[i+1:], key=lambda x: (current * x // gcd(current, x), x)) print(' '.join(map(str, a)))