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