#include <bits/stdc++.h>
using namespace std;
const int N = 200111;
long long n, m, a, b, c, arr[N];
map<long long, int> mp, mpp;
stack<long long> v, ans;
void solve(long long x, int sz) {
  if (sz >= n) {
    ans = v;
    return;
  }
  if (x % 3 == 0 && mpp[x / 3]) {
    mpp[x / 3]--;
    v.push(x / 3);
    solve(x / 3, sz + 1);
    mpp[x / 3]++;
    v.pop();
  }
  if (mpp[x * 2]) {
    mpp[x * 2]--;
    v.push(x * 2);
    solve(x * 2, sz + 1);
    mpp[x * 2]++;
    v.pop();
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]]++;
  }
  for (int i = 0; i < n; i++) {
    mpp = mp;
    v.push(arr[i]);
    solve(arr[i], 1);
    if (ans.size() == n) {
      vector<long long> vc;
      while (ans.size()) {
        a = ans.top();
        vc.push_back(a);
        ans.pop();
      }
      reverse(vc.begin(), vc.end());
      for (auto u : vc) {
        cout << u << " ";
      }
      cout << endl;
      return 0;
    }
    v.pop();
  }
}
