#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define N 5010
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
priority_queue<pii> q;
vector<int> g[N];int vis[N],a[N];
int gcd(int a,int b) { return a?gcd(b%a,a):b; }
int dfs(int x,int n)
{
	for(int y=1;y<=n;y++)
		if(!vis[y]&&gcd(a[x],a[y])>1)
			vis[y]=1,dfs(y,n),g[x].push_back(y);
	return 0;
}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);while(!q.empty()) q.pop();
	for(int i=1;i<=n;i++)
		if(!vis[i]) vis[i]=1,dfs(i,n),q.push(mp(a[i],i));
	while(!q.empty())
	{
		int x=q.top().second;
		q.pop(),printf("%d ",a[x]);
		for(int i=0;i<(int)g[x].size();i++)
			q.push(mp(a[g[x][i]],g[x][i]));
	}
	return !printf("\n");
}
