#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=2005;

int n,a[N],last[N],deg[N],cnt;
bool vis[N];
struct edge{int to,next;}e[N*N];

int gcd(int x,int y)
{
	if (!y) return x;
	else return gcd(y,x%y);
}

void addedge(int u,int v)
{
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
	deg[v]++;
}

void dfs(int x)
{
	vis[x]=1;
	for (int i=1;i<=n;i++)
		if (!vis[i]&&gcd(a[x],a[i])>1)
		{
			addedge(x,i);
			dfs(i);
		}
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++) if (!vis[i]) dfs(i);
	memset(vis,0,sizeof(vis));
	for (int i=1;i<=n;i++)
	{
		for (int j=n;j>=1;j--)
			if (!vis[j]&&!deg[j])
			{
				vis[j]=1;
				printf("%d ",a[j]);
				for (int k=last[j];k;k=e[k].next) deg[e[k].to]--;
				break;
			}
	}
	return 0;
}