#include <bits/stdc++.h>
using namespace std;
struct mazan {
  long long x;
  int doi, trei;
} v[101];
bool cmp(mazan a, mazan b) {
  if (a.doi < b.doi) return 1;
  if (a.doi > b.doi) return 0;
  if (a.trei > b.trei) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, i;
  long long l;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> v[i].x;
    l = v[i].x;
    while (l % 2 == 0) {
      l /= 2;
      v[i].doi++;
    }
    while (l % 3 == 0) {
      l /= 3;
      v[i].trei++;
    }
  }
  sort(v + 1, v + n + 1, cmp);
  for (i = 1; i <= n; i++) cout << v[i].x << " ";
  return 0;
}
