#include <bits/stdc++.h>
using namespace std;
namespace Flandre_Scarlet
{
	#define N 2333
	#define F(i,l,r) for(int i=l;i<=r;++i)
	#define D(i,r,l) for(int i=r;i>=l;--i)
	#define Fs(i,l,r,c) for(int i=l;i<=r;c)
	#define Ds(i,r,l,c) for(int i=r;i>=l;c)
	#define MEM(x,a) memset(x,a,sizeof(x))
	#define FK(x) MEM(x,0)
	#define Tra(i,u) for(int i=G.Start(u),v=G.To(i);~i;i=G.Next(i),v=G.To(i))
	#define p_b push_back
	#define sz(a) ((int)a.size())
	#define iter(a,p) (a.begin()+p)
	int I()
	{
	    int x=0;char c=getchar();int f=1;
	    while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar();
	    while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	    return (x=(f==1)?x:-x);
	}
	void Rd(int cnt,...)
	{
	    va_list args; va_start(args,cnt);
	    F(i,1,cnt) {int* x=va_arg(args,int*);(*x)=I();}
	    va_end(args);
	}

	int n,a[N];
	void Input()
	{
		n=I(); F(i,1,n) a[i]=I();
	}

	vector<int> g[N],g2[N];
	bool vis[N];int ideg[N];
	void DFS(int u)
	{
		vis[u]=1;
		F(i,0,sz(g[u])-1)
		{int v=g[u][i];
			if (vis[v]) continue;
			++ideg[v]; g2[u].p_b(v);
			DFS(v);
		}
	}
	priority_queue<int> Q;
	void TopoSort()
	{
		F(i,1,n) if (!ideg[i]) Q.push(i);
		while(!Q.empty())
		{
			int u=Q.top(); Q.pop();
			printf("%d ",a[u]);
			F(i,0,sz(g2[u])-1) Q.push(g2[u][i]);
		}
	}
	void Soviet()
	{
		sort(a+1,a+n+1);
		F(i,1,n) F(j,i+1,n) if (__gcd(a[i],a[j])!=1) g[i].p_b(j),g[j].p_b(i);
		F(i,1,n) if (!vis[i]) DFS(i);
		TopoSort();
	}

	#define Flan void
	Flan IsMyWife()
	{
		Input();
		Soviet();
	}
}
int main()
{
	Flandre_Scarlet::IsMyWife();
	getchar();getchar();
	return 0;
}