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