#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef _MSC_VER #include #endif #define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep(i, n) FOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define REV(v) v.rbegin(), v.rend() #define MEMSET(v, s) memset(v, s, sizeof(v)) #define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end()) #define MP make_pair #define MT make_tuple using namespace std; typedef long long ll; typedef pair P; int gcd(int m, int n){ return n ? gcd(n, m%n) : m; } inline int lcm(int m, int n){ return m / gcd(m, n) * n; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; for (int i = 1; i < n; ++i){ int x = a[i - 1]; P best = MP(lcm(x, a[i]), a[i]); int k = i; for (int j = i + 1; j < n; ++j){ auto cand = MP(lcm(x, a[j]), a[j]); if (cand < best){ best = cand; k = j; } } swap(a[i], a[k]); } rep(i, n) cout << a[i] << (i == n - 1 ? '\n' : ' '); return 0; }