import math n = int(input()) a = list(map(int, input().split())) for i in range(n): ai = a[i] sub = a[i+1:] # Sort sub based on LCM with ai and then by the element value sub_sorted = sorted(sub, key=lambda x: ((ai * x) // math.gcd(ai, x), x)) a = a[:i+1] + sub_sorted print(' '.join(map(str, a)))