#include <bits/stdc++.h>
using namespace std;
map<long long, int> mp;
map<long long, int> mpa;
int n;
long long p, t;
int main() {
  while (~scanf("%d", &n)) {
    mp.clear();
    mpa.clear();
    for (int i = 0; i < n; i++) {
      scanf("%lld", &p);
      mp[p]++;
    }
    map<long long, int>::iterator it;
    for (it = mp.begin(); it != mp.end(); it++) {
      t = it->first;
      mpa[t]++;
      if (mp.count(t * 3)) {
        mpa[t]++;
      }
      if (t % 2 == 0) {
        if (mp.count(t / 2)) {
          mpa[t]++;
        }
      }
    }
    for (it = mpa.begin(); it != mpa.end(); it++) {
      if (it->second == 1) {
        t = it->first;
        mpa[t]--;
        printf("%lld", t);
      }
    }
    n -= 1;
    while (n--) {
      if (t % 3 == 0) {
        if (mpa.count(t * 2)) mpa[t * 2]--;
        if (mpa.count(t / 3)) mpa[t / 3]--;
        if (mpa.count(t * 2) && (mpa[t * 2] == 1)) {
          printf(" %lld", t * 2);
          t = t * 2;
        } else {
          mpa[t / 3]--;
          printf(" %lld", t / 3);
          t = t / 3;
        }
      } else {
        mpa[t * 2]--;
        printf(" %lld", t * 2);
        t *= 2;
      }
    }
    puts("");
  }
  return 0;
}
