#include #include #include #include using namespace std; int main() { int32_t N; cin >> N; int32_t a[N]; for(int32_t i = 0; i < N; i++) cin >> a[i]; for(int32_t i = 0; i < N - 1; i++) { int32_t m = numeric_limits::max(), m2 = numeric_limits::max(), t = -1; for(int j = i + 1; j < N; j++) { int32_t lcm = a[i] * a[j] / __gcd(a[i], a[j]); if(lcm < m) { m = lcm; m2 = a[j]; t = j; }else if(lcm == m && m2 > a[j]) { m2 = a[j]; t = j; } } swap(a[i + 1], a[t]); } for(int i = 0; i < N; i++) { if(i) cout << " "; cout << a[i]; } cout << endl; }