import math n = int(input()) arr = list(map(int, input().split())) def lcm(a, b): return a * b // math.gcd(a, b) for i in range(n - 1): current = arr[i] # Sort the subarray from i+1 to end based on LCM with current and x arr[i+1:] = sorted(arr[i+1:], key=lambda x: (lcm(current, x), x)) print(' '.join(map(str, arr)))