import math from math import gcd def main(): n = int(input()) a = list(map(int, input().split())) for i in range(n-1): x = a[i] start = i + 1 # Create a slice of the list from start to end tail = a[start:] # Sort the slice based on LCM with x and then by the element's value tail.sort(key=lambda y: (x * y // gcd(x, y), y)) # Replace the slice in the original list a[start:] = tail print(' '.join(map(str, a))) if __name__ == "__main__": main()