#include #include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) using namespace std; template T gcd(T a, T b) { while (a) { b %= a; swap(a, b); } return b; } template T lcm(T a, T b) { return (a * b) / gcd(a,b); } int main() { int n; cin >> n; vector a(n); repeat (i,n) cin >> a[i]; repeat (i,n-1) { auto it = min_element(a.begin() + i+1, a.end(), [&](int b, int c) { return make_pair(lcm(a[i], b), b) < make_pair(lcm(a[i], c), c); }); swap(a[i+1], *it); } repeat (i,n) cout << (i ? " " : "") << a[i]; cout << endl; return 0; }