#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const int N = 205;
int n;
long long a[N];
map<long long, int> mp;
vector<int> G[N], ans;
bool vis[N];
bool dfs(int u, int step) {
  if (step == n) {
    ans.push_back(u);
    return true;
  }
  vis[u] = true;
  for (int to : G[u])
    if (!vis[to]) {
      if (dfs(to, step + 1)) {
        ans.push_back(u);
        return true;
      }
    }
  vis[u] = false;
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), mp[a[i]] = i;
  for (int i = 1; i <= n; ++i) {
    if (a[i] % 3 == 0) {
      if (mp.find(a[i] / 3) != mp.end()) G[mp[a[i] / 3]].push_back(i);
    }
    if (mp.find(a[i] * 2) != mp.end()) G[mp[a[i] * 2]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    memset(vis, false, sizeof(vis));
    if (dfs(i, 1)) {
      for (int v : ans) printf("%lld ", a[v]);
      break;
    }
  }
  return 0;
}
