#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a ; i <= b; ++ i) 
const int N = 2005, inf = 1e9 + 7 ;
using namespace std ;

int n, a[N], cnt ;
bool G[N][N], vis[N] ;

int gcd(int x, int y) {
	return (y ? gcd(y, x % y) : x) ;
}

vector <int> dfs(int p) {
	vis[p] = false ;
	vector <int> res, A, B ;
	res.push_back(a[p]) ;
	rep(i, 0, n) A.push_back(0) ;
	rep(u, 1, n) if (G[p][u] && vis[u]) {
		B = dfs(u) ;
		int na = (int) res.size() - 2, nb = (int) B.size() - 1, topa = 0, topb = 0 ;
		rep(i, 0, na) A[i] = res[i + 1] ;
		rep(i, 1, nb + 1) res.push_back(0) ;
		rep(i, 1, na + nb + 2) {
			if (topa <= na && (topb > nb || A[topa] >= B[topb])) res[i] = A[topa ++] ; else res[i] = B[topb ++] ;
		} 
	}
	return res ;
}

int main() {
	scanf("%d", &n) ;
	cnt = 0 ;
	rep(i, 1, n) scanf("%d", &a[i]) ; sort(a + 1, a + n + 1) ;
	rep(i, 0, n) G[i][0] = G[0][i] = vis[i] = true ;
	rep(i, 1, n) rep(j, 1, n) G[i][j] = G[j][i] = (gcd(a[i], a[j]) != 1) ;
	vector <int> ans = dfs(0) ;
	rep(i, 0, n - 1) printf("%d ", ans[i + 1]) ; puts("") ;
	return 0 ; 
}