#include <bits/stdc++.h>
using namespace std;
int n;
long long a[105];
long long ans[105];
int k;
int flag;
map<long long, int> mapp;
void dfs(long long x) {
  if (k == n) {
    flag = 1;
    return;
  }
  if (mapp[x * 2]) {
    ans[k++] = x * 2;
    mapp[x * 2]--;
    dfs(x * 2);
    mapp[x * 2]++;
  }
  if (x % 3 == 0 && mapp[x / 3]) {
    ans[k++] = x / 3;
    mapp[x / 3]--;
    dfs(x / 3);
    mapp[x / 3]++;
  }
  if (flag) return;
}
int main() {
  while (cin >> n) {
    mapp.clear();
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i < n; ++i) {
      scanf("%I64d", &a[i]);
      mapp[a[i]]++;
    }
    flag = 0;
    for (int i = 0; i < n; ++i) {
      k = 0;
      mapp[a[i]]--;
      ans[k++] = a[i];
      dfs(a[i]);
      mapp[a[i]]++;
      if (flag) break;
    }
    for (int i = 0; i < n; ++i) cout << ans[i] << " ";
    cout << endl;
  }
}
