#include #include #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 pair Pii; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++) template void checkmin(T &a, T b) { if (b < a) a = b; } template void checkmax(T &a, T b) { if (b > a) a = b; } int N; int A[10000]; int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); } int LCM(int a, int b) { return a / GCD(a, b) * b; } void solve() { rep(i, N - 1) { int bestLcm = INT_MAX, bestVal = INT_MAX, bestIndex = -1; FOR(j, i + 1, N - 1) { int lcm = LCM(A[i], A[j]); if (lcm < bestLcm || lcm == bestLcm && A[j] < bestVal) { bestLcm = lcm; bestVal = A[j]; bestIndex = j; } } swap(A[i + 1], A[bestIndex]); } rep(i, N) { if (i > 0) printf(" "); printf("%d", A[i]); } } int main() { scanf("%d", &N); rep(i, N) scanf("%d", &A[i]); solve(); return 0; }