#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) { if (b == 0) return abs(a); else return gcd(b, a % b); } int main() { 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]), 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'); }