#include <bits/stdc++.h>
using namespace std;
#define N 2010
inline int read() {
    int x=0;
    char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x;
}
inline int gcd(int x,int y) {
    return y?gcd(y,x%y):x;
}
int f[N][N];
int a[N],vis[N],ind[N];
vector<int> v[N];
inline void dfs(int x,int n) {
    vis[x]=true;
    for (int i=1;i<=n;i++) {
        if (!f[x][i] || vis[i]) continue;
        ind[i]++,v[x].push_back(i),dfs(i,n);
    }
}
inline void Top(int n) {
    priority_queue<int> q;
    for (int i=1;i<=n;i++) 
        if (!ind[i]) q.push(i);
    while (!q.empty()) {
        int x=q.top(); q.pop();
        printf("%d ",a[x]);
        for (int i=0;i<v[x].size();i++) q.push(v[x][i]);
    }
}
int main() {
    int n=read();
    for (int i=1;i<=n;i++) a[i]=read();
    sort(a+1,a+n+1);
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=n;j++) {
            if (gcd(a[i],a[j])!=1) f[i][j]=true;
        }
    }
    for (int i=1;i<=n;i++) 
        if (!vis[i]) dfs(i,n);
    Top(n);
    return 0;
}