#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

const int N=2005; 

void read(int &x){
	x=0; 
	char c=getchar(); 
	for(;!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

int n,a[N],deg[N],vis[N];
vector<int> g[N]; 

int gcd(int a,int b){ return !b?a:gcd(b,a%b); } 

void dfs(int v){
	vis[v]=1; 
	rep(d,1,n)if(!vis[d]&&gcd(a[d],a[v])>1){
		g[v].pb(d);
		++deg[d];
		Pr("Link %d,%d\n",v,d); 
		dfs(d); 
	}
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	read(n); 
	rep(i,1,n)read(a[i]); 
	sort(a+1,a+n+1); 
	rep(i,1,n)if(!vis[i])dfs(i); 
	memset(vis,0,sizeof(vis)); 
	rep(i,1,n){
		dec(j,n,1){
			if(!vis[j]&&!deg[j]){
				vis[j]=1;
				printf("%d ",a[j]);
				for(int d:g[j])--deg[d];
				break;
			}
		}
	}
	return 0; 
}