#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,v[2010][2010],mp[2010],a[2010],ru[2010];
priority_queue<int>q;
vector<int>zh[2010];
void dfs(int x){
	int i;
	mp[x]=1;
	for(i=1;i<=n;i++)if(!mp[i]&&v[x][i]){
		ru[i]++;
		zh[x].push_back(i);
		dfs(i);
	}
}
void topsort(){
	int i,j,x;
	for(i=1;i<=n;i++)if(!ru[i])q.push(i);
	while(!q.empty()){
		x=q.top();
		q.pop();
		printf("%d ",a[x]);
		for(i=0;i<zh[x].size();i++)q.push(zh[x][i]);
	}
}
int gcd(int x,int y){
	if(!y)return x;
	return gcd(y,x%y);
}
int main(){
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++)
	 for(j=i+1;j<=n;j++)if(gcd(a[i],a[j])!=1)v[i][j]=v[j][i]=1;
	for(i=1;i<=n;i++)if(!mp[i])dfs(i);
	topsort();
}