#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first < b.first;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> vec(n);
  unordered_map<long long, long long> mymap, tempmap;
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    mymap[vec[i]]++;
  }
  long long last;
  for (int i = 0; i < n; i++) {
    if (mymap.find(vec[i] * 2) == mymap.end() &&
        (vec[i] % 3 != 0 || mymap.find(vec[i] / 3) == mymap.end())) {
      last = vec[i];
      break;
    }
  }
  stack<long long> myst;
  myst.push(last);
  while (myst.size() != n) {
    long long val = myst.top();
    if (mymap.find(val * 3) != mymap.end() && mymap[val * 3] != 0) {
      mymap[val * 3]--;
      myst.push(val * 3);
    } else {
      mymap[val / 2]--;
      myst.push(val / 2);
    }
  }
  while (!myst.empty()) {
    cout << myst.top() << " ";
    myst.pop();
  }
  return 0;
}
