#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int mod = (int)1e9 + 7;
const long long INF = 1000000000000000000LL;
long long power(long long a, long long b, long long m) {
  long long i = 1;
  while (b) {
    if (b % 2) i = (i * a) % mod;
    b /= 2;
    a = (a * a) % mod;
  }
  return i;
}
map<long long, vector<long long>> m;
vector<long long> vv;
const long long N = 1e5 + 5;
void dfs(long long x) {
  vv.push_back(x);
  for (long long y = 0; y < m[x].size(); y++) {
    long long i = m[x][y];
    dfs(i);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n];
  for (long long x = 0; x < n; x++) cin >> a[x];
  sort(a, a + n);
  for (long long x = 0; x < n; x++) {
    for (long long y = 0; y < n; y++) {
      if (x != y) {
        if (a[x] * 2 == a[y]) m[a[x]].push_back(a[y]);
        if (a[y] * 3 == a[x]) m[a[x]].push_back(a[y]);
      }
    }
  }
  for (long long x = 0; x < n; x++) {
    if (m[a[x]].size() == 1) {
      dfs(a[x]);
      if (vv.size() == n) {
        for (long long y : vv) cout << y << ' ';
        return 0;
      } else
        vv.clear();
    }
  }
  return 0;
}
