#include #define rep(i, a) rep2 (i, 0, a) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define repr(i, a) repr2 (i, 0, a) #define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define asn(a, b, c) fill_n(&(b), sizeof(a) / sizeof(b), c) using namespace std; typedef long long ll; const ll inf = 1e9; const ll mod = 1e9 + 7; const ll infl = 1e18; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } ostream &operator <<(ostream &os, const vector &v) { rep (i, v.size()) { if (i) cout << " "; cout << v[i]; } return os; } int main() { int N; cin >> N; vector a(N); rep (i, N) cin >> a[i]; rep (i, N - 1) { ll mini = infl; ll minv = infl; rep2 (j, i + 1, N) { ll l = lcm(a[i], a[j]); if (l < minv) { minv = l; mini = j; } else if (l == minv && a[mini] > a[j]) { mini = j; } } swap(a[i + 1], a[mini]); } cout << a << endl; return 0; }