#include #include #include #include #include using namespace std; int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } long lcm(int a, int b) { return (long) a * b / gcd(a, b); } int main() { int n; cin >> n; vector< pair > a(n); int input; for (int i = 0; i < n; i++) { cin >> input; a[i] = make_pair(0, input); } for (int i = 0; i < n - 1; i++) { int start = a[i].second; for (int j = i + 1; j < n; j++) { a[j].first = lcm(start, a[j].second); } sort(a.begin() + i + 1, a.end()); } for (int i = 0; i < n; i++) { printf("%d%c", a[i].second, i != n - 1 ? ' ' : '\n'); } return 0; }