#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; vector factorize(int x){ vector ret; int d, q; while(x>=4 && x%2==0){ret.push_back(2); x/=2;} d = 3; q = x/d; while(q>=d){ if(x%d==0){ ret.push_back(d); x=q; }else{ d+=2; } q=x/d; } ret.push_back(x); sort(ALLOF(ret)); return ret; } struct ST { int a; vector fact; }; bool operator<(const ST& a, const ST& b){ int i=0; while(i b.fact[i]) return false; i++; } return a.fact.size() < b.fact.size(); } int main(){ ios::sync_with_stdio(false); int N, a; vector ret; cin >> N; rep(i,N){ cin >> a; ret.push_back((ST){a,factorize(a)}); } sort(ret.begin()+1, ret.end()); rep(i,ret.size()){ if(i!=0) cout << " "; cout << ret[i].a; } cout << endl; return 0; }