#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i)) #define REPS(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i)) #if defined(_MSC_VER)||__cplusplus > 199711L #define AUTO(r,v) auto r = (v) #else #define AUTO(r,v) typeof(v) r = (v) #endif #define ALL(c) (c).begin() , (c).end() #define EACH(it,c) for(AUTO(it,(c).begin());it != (c).end();) #define LL long long #define int LL #define inf ((int)1 << 54) #define mod 1000000007 #define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0); #define lowb lower_bound #define upb upper_bound #define ZERO(c,n) memset(&c[0],0,sizeof(int)*n) #define ZERO2(c,n) memset(&c[0][0],0,sizeof(int)*n) #define debug_input fstream cin("input.txt");ofstream cout("output.txt"); #define pb(a) push_back(a) templatevoid scan(vector& a, int n, istream& cin) { T c; REP(i, n) { cin >> c; a.push_back(c); } } using vs = vector; using vi = vector; using pii = pair; using psi = pair; using vvi = vector; templatebool valid(T x, T w) { return 0 <= x&&x < w; } int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 }; //----------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a%b); } signed main() { QUICK_CIN; //debug_input; vi a; int n; cin >> n; scan(a, n, cin); int now = a[0]; cout << now << " "; REPS(1, i, n) { int min = inf; int min_i = i; REPS(i, j, n) { auto k = a[j] * now / gcd(now, a[j]); if (k > min) { continue; } if (k == min && a[j] >= a[min_i]) { continue; } min_i = j; min = k; } swap(a[i], a[min_i]); cout << a[i] << " "; now = a[i]; } cout << endl; }