#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 1000000007;
int64_t maxm(int64_t a, int64_t b) { return a > b ? a : b; }
int64_t minm(int64_t a, int64_t b) { return a > b ? b : a; }
int64_t a[200], n, j, i, ans[200];
vector<int64_t> v[200];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (i != j) {
        if (a[j] == 2 * a[i] || a[i] == 3 * a[j]) v[i].push_back(j);
      }
    }
  }
  int64_t x, p;
  for (i = 1; i <= n; i++) {
    if (v[i].size() == 0) {
      x = i;
      break;
    }
  }
  ans[n] = x;
  for (i = n - 1; i >= 1; i--) {
    p = ans[i + 1];
    for (j = 1; j <= n; j++) {
      if (v[j].size() > 0 && v[j][0] == p) {
        ans[i] = j;
        break;
      }
    }
  }
  for (i = 1; i <= n; i++) cout << a[ans[i]] << " ";
}
