#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a, b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<P; typedef pairpll; const int MAX_N = 10005; set

st[MAX_N]; vector > res; vector divisor(ll n) { vector res; for(ll i=1;i*i<=n;i++){ if(n%i==0){ res.pb(i); if(i != n/i){ res.pb(n/i); } } } sort(all(res)); return res; } ll gcd(ll a,ll b) { if(a % b == 0){ return b; }else{ return gcd(b,a%b); } } ll lcm(ll a,ll b) { return a / gcd(a,b) * b; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector vec(n); rep(i,n){ cin >> vec[i]; res.pb(divisor(vec[i])); rep(j,res[i].size()){ st[res[i][j]].insert(P(vec[i],i)); } } vector v; v.pb(vec[0]); int i = 0; rep(id,n-1){ pll ans = pll((1LL << 60),INF); int idx; rep(j,res[i].size()){ st[res[i][j]].erase(P(vec[i],i)); auto it = st[res[i][j]].begin(); if(it != st[res[i][j]].end()){ P p = *it; if(ans > pll(lcm(vec[i],p.fi),vec[i])){ ans = pll(lcm(vec[i],p.fi),vec[i]); idx = p.se; } } } i = idx; v.pb(vec[i]); } rep(i,n-1){ cout << v[i] << " "; } cout << v[n-1] << endl; return 0; }