#include <bits/stdc++.h>
using namespace std;
long long n, x, y, z, h[300], a[330], m, t, p = 1000000007;
string s, f;
long long che(long long xx) {
  for (int i = 0; i < n; i++) {
    if (a[i] == xx) return i + 1;
  }
  return 0;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (che(a[i] * 2)) {
      h[che(a[i] * 2) - 1] = i + 1;
    }
    if (a[i] % 3 == 0 && che(a[i] / 3)) {
      h[che(a[i] / 3) - 1] = i + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (h[i] == 0) {
      x = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << a[x] << ' ';
    for (int j = 0; j < n; j++) {
      if (h[j] - 1 == x) {
        x = j;
        break;
      }
    }
  }
  return 0;
}
