#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define REPR(i, n) for(ll i = n;i >= 0;i--) #define FOR(i, m, n) for(ll i = m;i < n;i++) #define FORR(i, m, n) for(ll i = m;i >= n;i--) #define REPO(i, n) for(ll i = 1;i <= n;i++) #define ll long long #define INF (ll)1 << 60 #define MINF (-1 * INF) #define ALL(n) n.begin(),n.end() #define MOD 1000000007 #define P pair ll n, s[11000]; ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { cin >> n; REP(i, n)cin >> s[i]; REP(i, n - 1) { ll ma = INF, man; FOR(j, i + 1, n) { if (ma > lcm(s[i], s[j]) or (ma == lcm(s[i], s[j]) and s[man] > s[j])) { ma = lcm(s[i], s[j]); man = j; } } swap(s[i + 1], s[man]); } REP(i, n) { if (i != 0)cout << " "; cout << s[i]; } cout << endl; }