#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; struct Node { int v; int cnt; Node(int v = -1, int cnt = -1) { this->v = v; this->cnt = cnt; } bool operator>(const Node &n) const { return cnt < n.cnt; } }; int main() { int N; cin >> N; vector A; vector counter(10010, 0); set memo[10010]; for (int i = 0; i < N; ++i) { int a; cin >> a; counter[a]++; A.push_back(a); for (int j = a; j <= 10000; j += a) { memo[j].insert(a); } } int cur = A[0]; counter[cur]--; vector ans; ans.push_back(cur); for (int i = 0; i < N - 1; ++i) { bool ok = true; for (int j = cur; j <= 10000 && ok; j += cur) { if (memo[j].empty()) continue; for (int v : memo[j]) { if (counter[v] == 0) continue; ans.push_back(v); counter[v]--; cur = v; ok = false; break; } } } for (int i = 0; i < N; ++i) { cout << ans[i]; if (i + 1 < N) cout << " "; } cout << endl; return 0; }