#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef uint64_t ll; ll gcd(ll a, ll b){ if(b==0)return a; else return gcd(b, a%b); } ll lcm(ll a, ll b){ return a / gcd(a,b) * b; } int main() { ll n; cin >> n; ll a[n]; for (int i = 0; i < n; i++) scanf("%llu", &a[i]); sort(a+1, a+n); printf ("%llu ", a[0]); for (int i = 0; i < n-1; i++) { ll mini = 1000000000; int p = 0; for (int j = i+1; j < n; j++) { ll t = lcm(a[i], a[j]); if (mini > t) p = j; mini = min(mini, t); } printf ("%llu ", a[p]); swap(a[p], a[i+1]); } }