#include <bits/stdc++.h>
using namespace std;
int n;
long long a[101];
long long out[101];
long long in[101];
int check[101];
pair<int, int> deg[101];
vector<int> G[105];
vector<int> path;
int flag = 0;
void go(int v, int step) {
  check[v] = 1;
  path.push_back(v);
  if (step == n) {
    for (int i = path.size() - 1; i >= 0; i--) cout << a[path[i]] << " ";
    cout << endl;
    flag = 1;
    path.pop_back();
    return;
  }
  for (int j = 0; j < G[v].size(); j++) {
    int nxt = G[v][j];
    if (check[nxt] == 0 && flag == 0) {
      go(nxt, step + 1);
    }
  }
  check[v] = 0;
  path.pop_back();
  return;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i != j) {
        if (a[i] * 2 == a[j]) G[j].push_back(i);
        if (a[i] % 3 == 0 && a[i] / 3 == a[j]) G[j].push_back(i);
      }
    }
  }
  for (int i = 1; i <= n; i++) deg[i] = make_pair(G[i].size(), i);
  sort(deg + 1, deg + 1 + n);
  memset(check, 0, sizeof(check));
  for (int i = 1; i <= n; i++) {
    int node = deg[i].second;
    if (flag == 0) go(node, 1);
  }
  return 0;
}
