#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair i_ll; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int gcd(int a, int b, vector< vector >& memo) { if (b == 0) return a; else if (memo[a][b]) return memo[a][b]; else return memo[a][b] = gcd(b, a % b, memo); } int main() { vector< vector > memo(10001, vector(10001)); int N; cin >> N; vector a(N); for (int i = 0; i < N; i++) cin >> a[i]; for (int i = 0; i + 1 < N; i++) { int _j, _d = INT_MAX, _x = INT_MAX; for (int j = i + 1; j < N; j++) { int d = gcd(a[i], a[j], memo), x = a[j] / d; if (x < _x || (x == _x && a[j] < a[_j])) { _j = j; _d = d; _x = x; } } swap(a[i + 1], a[_j]); } for (int i = 0; i < N; i++) cout << a[i] << (i + 1 < N ? ' ' : '\n'); }