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