#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct N {
  long long val;
  int cnt3;
  int cnt2;
} a[105];
int cmp(N x, N y) {
  if (x.cnt3 == y.cnt3) {
    return x.cnt2 < y.cnt2;
  }
  return x.cnt3 > y.cnt3;
}
int fun3(long long x) {
  long long cnt = 0;
  while (x % 3 == 0) {
    cnt++;
    x /= 3;
  }
  return cnt;
}
int fun2(long long x) {
  long long cnt = 0;
  while (x % 2 == 0) {
    cnt++;
    x /= 2;
  }
  return cnt;
}
int main() {
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      cin >> a[i].val;
      a[i].cnt3 = fun3(a[i].val);
      a[i].cnt2 = fun2(a[i].val);
    }
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 1; i <= n; i++) {
      if (i == 1)
        cout << a[i].val;
      else
        cout << " " << a[i].val;
    }
    cout << endl;
  }
  return 0;
}
