#include<bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
    return !y ? x : gcd(y, x % y);
}
const int N = 2010;
int a[N], e[N][N], n, d[N];
bool vis[N];
vector<int> g[N];
void dfs(int x) {
    vis[x] = 1;
    for (int i = 1; i <= n; i++) 
        if (!vis[i] && e[x][i]) {
            g[x].push_back(i); d[i]++;
            dfs(i);
        }
}
priority_queue<int> q;
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
            if (gcd(a[i], a[j]) > 1)
                e[i][j] = e[j][i] = 1;
    for (int i = 1; i <= n; i++)
        if (!vis[i]) dfs(i);
    for (int i = 1; i <= n; i++) if (!d[i]) q.push(i);
    while (!q.empty()) {
        int u = q.top(); q.pop();
        printf("%d ", a[u]);
        for (int i = 0; i < g[u].size(); i++) {
            int v = g[u][i];
            if (!(--d[v])) q.push(v);
        }
    }
    return 0;
}