#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) using namespace std; typedef long long int ll; typedef vector VI; typedef pair PI; int n; const int N = 10010; int a[N]; int b[N]; int u[N]; const int K = 1000; int memo[K][K]; int gcd(int x, int y) { if (y == 0) return x; if (x < K && y < K && memo[x][y] > 0) { return memo[x][y]; } int r = x % y; int ans = gcd(y, r); if (x < K && y < K) memo[x][y] = ans; return ans; } int lcm(int x, int y) { return x / gcd(x, y) * y; } int main(void){ cin >> n; REP(i, 0, n) { cin >> a[i]; u[i] = 0; } int s = 0; REP(i, 0, n) { b[i] = a[s]; u[s] = 1; int mini = -1; int minl = 0; REP(k, 0, n) { if (u[k]) { continue; } int l = lcm(a[s], a[k]); if (mini == -1 || minl > l || (minl == l && a[mini] > a[k])) { mini = k; minl = l; } } s = mini; } REP(i, 0, n) { cout << b[i] << (i == n - 1 ? "\n" : " "); } }