#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020;
int gcd(int a, int b){
	while(b){
		a %= b;
		swap(a, b);
	}
	return a;
}
vector<int> to[maxn];
int a[maxn], vis[maxn];
vector<int> merge(const vector<int> &a, const vector<int> &b){
	int pa = 0, pb = 0, la = a.size(), lb = b.size();
	vector<int> ans;
	while(pa < la && pb < lb){
		if(a[pa] > b[pb]) ans.push_back(a[pa++]);
		else ans.push_back(b[pb++]);
	}
	while(pa < la) ans.push_back(a[pa++]);
	while(pb < lb) ans.push_back(b[pb++]);
	return ans;
}
vector<int> dfs(int u){
	vector<int> ans;
	vis[u] = 1;
	for(int v : to[u]){
		if(!vis[v]){
			ans = merge(ans, dfs(v));
		}
	}
	ans.insert(ans.begin(), a[u]);
	return ans;
}
int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(i != j) {
		if(gcd(a[i], a[j]) != 1){
			to[i].push_back(j);
		}
	}
	vector<int> ans;
	for(int i = 0; i < n; i++){
		if(!vis[i]){
			ans = merge(ans, dfs(i));
		}
	}
	for(int v : ans) cout << v << " ";
	return 0;
}

