#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; const double EPS=1e-9; int n; const int N = 10010; int a[N]; int b[N]; int u[N]; 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; REP(k, 0, n) { if (u[k]) { continue; } if (mini == -1 || lcm(a[s], a[mini]) > lcm(a[s], a[k]) || (lcm(a[s], a[mini]) == lcm(a[s], a[k]) && a[mini] > a[k])) { mini = k; } } s = mini; } REP(i, 0, n) { cout << b[i] << (i == n - 1 ? "\n" : " "); } }