#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#define MAXN 2048
#define MAXM 4194304
using namespace std;
inline int read()
{
	int x=0,t=1,c;
	while(!isdigit(c=getchar()))if(c=='-')t=-1;
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*t;
}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int n,A[MAXN];
bool edge[MAXN][MAXN];
int first[MAXN],targ[MAXN],nxt[MAXN],lead[MAXN],cnte=1;
void AddEdge(int u,int v)
{
	lead[v]++;targ[cnte]=v;nxt[cnte]=first[u];first[u]=cnte++;
}
int deep[MAXN];
void Search(int x=0,int depth=1)
{
	//printf("%d %d\n",x,depth);
	deep[x]=depth;
	for(int i=1;i<=n;i++)
		if(edge[x][i])
			if(!deep[i])
			{
				Search(i,depth+1);
				AddEdge(x,i);
			}
}
int main()
{
	n=read();
	A[0]=0;
	for(int i=1;i<=n;i++)A[i]=read();
	sort(A,A+1+n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i!=j)
				if(gcd(A[i],A[j])!=1)
					edge[i][j]=1;
	for(int i=1;i<=n;i++)
		edge[0][i]=1;
	Search();
	priority_queue<int> PQ;
	PQ.push(0);
	while(!PQ.empty())
	{
		int x=PQ.top();PQ.pop();
		if(x)printf("%d ",A[x]);
		for(int i=first[x];i;i=nxt[i])
		{
			lead[targ[i]]--;
			if(!lead[targ[i]])PQ.push(targ[i]);
		}
	}
}