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