import math def main(): import sys input = sys.stdin.read data = input().split() n = int(data[0]) a = list(map(int, data[1:n+1])) for i in range(n-1): current = a[i] sub = a[i+1:] # Create a list of tuples (lcm, x) keys = [(current * x // math.gcd(current, x), x) for x in sub] # Sort the subarray based on the keys sorted_sub = [x for _, x in sorted(zip(keys, sub))] # Update the array a[i+1:] = sorted_sub print(' '.join(map(str, a))) if __name__ == "__main__": main()