n=int(input()) a=list(map(int,input().split())) sa=[] sa+=[a[0]] sa+=[1]*a[1:].count(1) a=[a[i] for i in range(1,n) if a[i]!=1] a.sort() if sa[-1]==1: sa+=[a[0]] a=a[1:] n=len(a) L=10000 f=[[] for i in range(L+1)] for i in range(1,L+1): j=1 while j*j<=i: if i%j==0: f[i]+=[j] if j0 and u[q[j][0][1]]: heappop(q[j]) if len(q[j])>0: p1,p2=q[j][0] b=min(b,(sa[-1]*p1//j,a[p2],p2)) c=b[2] sa+=[a[c]] u[c]=1 print(*sa)