#include #define rep(i,a,b) for(int i=a;i> N; rep(i, 0, N) cin >> A[i]; A[N] = 1; rep(i, 0, N) { if (0 < i) printf(" "); printf("%d", A[i]); int mi = i + 1, lc = lcm(A[i], A[i + 1]); rep(j, i + 2, N) { int x = lcm(A[i], A[j]); if (x < lc) { mi = j, lc = x; } else if (x == lc && A[j] < A[mi]) { mi = j, lc = x; } } swap(A[i + 1], A[mi]); } printf("\n"); }