def gdc(a, b): if b == 0: return a else: return gdc(b, a % b) if __name__ == '__main__': N = int(input()) a = list(map(int, input().split())) for i in range(N - 1): idx = 0 low_value = 999999 a = a[:i + 1] + sorted(a[i + 1:]) # print(a) for j in range(i + 1, N): d = gdc(a[i], a[j]) lcm = a[i] / d * a[j] # print('a[{}]:{},a[{}]:{},lcm:{}'.format(i, a[i], j, a[j], lcm)) if(low_value > lcm): low_value = lcm idx = j if idx != 0: temp = a[i + 1] a[i + 1] = a[idx] a[idx] = temp print(' '.join(map(str,a)))