#include <bits/stdc++.h>
bool debug = true;
using namespace std;
long long pow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res *= a;
    }
    a *= a;
    n >>= 1;
  }
  return res;
}
int main(void) {
  if (0) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  int n, i, j, k;
  scanf("%d", &n);
  vector<long long> a(n);
  for (i = 0; i < n; i++) scanf("%lld", &a[i]);
  long long base = a[0], tmp;
  while ((base % 2) == 0) base >>= 1;
  while ((base % 3) == 0) base /= 3;
  vector<pair<int, int>> b;
  for (i = 0; i < n; i++) {
    tmp = a[i];
    j = k = 0;
    while ((tmp % 2) == 0) {
      tmp >>= 1;
      j++;
    }
    while ((tmp % 3) == 0) {
      tmp /= 3;
      k++;
    }
    b.push_back(make_pair(k, j));
  }
  sort(b.begin(), b.end(), [](pair<int, int> &left, pair<int, int> &right) {
    return ((left.first > right.first) ||
            (left.first == right.first && left.second < right.second));
  });
  long long ans = base;
  ans *= pow((long long)3, (long long)b[0].first);
  ans *= pow((long long)2, (long long)b[0].second);
  printf("%lld ", ans);
  for (i = 1; i < n; i++) {
    if (b[i].first == b[i - 1].first - 1) ans /= 3;
    if (b[i].second == b[i - 1].second + 1) ans <<= 1;
    printf("%lld ", ans);
  }
  printf("\n");
}
