#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f - 1;
template <class T>
void read(T& x) {
  register int c = getchar(), f = 1;
  x = 0;
  while (!isdigit(c)) {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
const int MAXN = 2e3 + 7;
long long a[MAXN], n, k, Ans[MAXN], flag;
bool used[MAXN];
void dfs(int x, int cnt) {
  if (flag) return;
  if (cnt == n) {
    for (int i = 1; i <= n; ++i) printf("%I64d ", Ans[i]);
    flag = 1;
    return;
  }
  int pos = lower_bound(a + 1, a + 1 + n, 2 * Ans[x - 1]) - a;
  int pos1 = lower_bound(a + 1, a + 1 + n, Ans[x - 1] / 3) - a;
  if (pos != n + 1 && !used[pos] &&
      binary_search(a + 1, a + 1 + n, 2 * Ans[x - 1])) {
    used[pos] = 1;
    Ans[x] = 2 * Ans[x - 1];
    dfs(x + 1, cnt + 1);
    used[pos] = 0;
  }
  if (pos1 != n + 1 && !used[pos1] &&
      binary_search(a + 1, a + 1 + n, Ans[x - 1] / 3) && Ans[x - 1] % 3 == 0) {
    used[pos1] = 1;
    Ans[x] = Ans[x - 1] / 3;
    dfs(x + 1, cnt + 1);
    used[pos1] = 0;
  }
}
int main(void) {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; ++i)
    Ans[1] = a[i], used[i] = 1, dfs(2, 1), used[i] = 0;
  return 0;
}
