#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
typedef long long ll;
typedef pair<char, int > PII;
int n;
ll get (ll a, ll b) {
ll res = 0;
while(a % b == 0) res ++, a /= b;
return res;
}
struct Node {
ll x, y, z;
bool operator< (const Node &q) {
if (x != q.x) return x < q.x;
else return y < q.y;
}
}q[N];
void solve() {
cin >> n;
for (int i =1; i<= n; i ++) {
ll t;
cin >> t;
q[i].x = get(t, 2), q[i].y = -get(t, 3), q[i].z = t;
}
sort(q+ 1, q + 1 + n);
for (int i= 1; i<= n; i++) {
cout << q[i].z << " ";
}
puts("");
}
int main () {
int t;
t =1;
while (t --) solve();
return 0;
}
从2,3因子的角度想,对于一个合法的序列 xi < xj huo yi > yj && xi==xj 且是唯一的反证法