int main() { ll n;cin>>n; ll a[n]; for(int i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n,greater()); vector v; for(ll i=0;i<n;i++) { int flag = 0; v.PB(a[i]); for(ll j=0;j<n;j++) {
ll check = v.back(); if( check%3==0 && binary_search(a,a+n,check/3)==true) v.PB(check/3); else if(binary_search(a,a+n,check*2)) v.PB(check*2); else {v.clear(); break;} if(v.size()==n){flag =1; break;} } if(flag==1) break;
} for(auto x:v) { cout<<x<<" "; } return 0; }