#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
using namespace std;

bool vis[2005];
int d[2005],h[2005],tot;
int n,v[2005];
struct Edge{
	int x,next;
}e[10005];

void add_edge(int x,int y){
	e[++tot].x=y;
	e[tot].next=h[x],h[x]=tot;
}

int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}

void dfs(int x){
	vis[x]=true;
	for(int i=1;i<=n;i++){
		if(vis[i])continue;
		if(gcd(v[x],v[i])==1)continue;
		add_edge(x,i),d[i]++;
		dfs(i);
	}
}

void solve(){
	priority_queue<int> q;
	for(int i=1;i<=n;i++)
		if(d[i]==0)q.push(i),vis[i]=false;
	while(!q.empty()){
		int x=q.top();q.pop();
		for(int i=h[x];i;i=e[i].next){
			if(!vis[e[i].x])continue;
			d[e[i].x]--;
			if(d[e[i].x]==0){
				vis[e[i].x]=false;
				q.push(e[i].x);
			}
		}
		printf("%d ",v[x]);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",v+i);
	sort(v+1,v+n+1);
	for(int i=1;i<=n;i++)if(!vis[i])dfs(i);
	solve();
}