#include <bits/stdc++.h>
using namespace std;
int cont = 0, N;
long long ver[(112)];
vector<long long> mult[(112)], d[(112)];
deque<long long> res;
int dfs(long long x, int quant) {
  res.push_back(x);
  for (int i = 0; i < N; i++)
    if (x * 2 == ver[i]) return dfs(ver[i], quant + 1);
  for (int i = 0; i < N; i++)
    if (ver[i] * 3 == x) return dfs(ver[i], quant + 1);
  return quant;
}
int main() {
  long long x, y;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%lld", &ver[i]);
  for (int i = 0; i < N; i++) {
    cont = dfs(ver[i], 1);
    if (cont == N) {
      for (int j = 0; j < N; j++) {
        if (!j)
          printf("%lld", res[j]);
        else
          printf(" %lld", res[j]);
      }
      puts("");
      break;
    } else {
      cont = 0;
      res.clear();
    }
  }
  return 0;
}
