#include #include #include #include int main() { using namespace std; int n; cin >> n; vector a(n); for (auto &e : a) { cin >> e; } for (int i = 0; i < n; i++) { sort(a.begin() + i + 1, a.end(), [&](const int x, const int y) { int lx = lcm(x, a[i]), ly = lcm(y, a[i]); if (lx != ly) { return lx < ly; } else { return x < y; } }); } for (auto e : a) { cout << e << " "; } cout << endl; }