#include <bits/stdc++.h>
using namespace std;
long long _gcd(long long m, long long n) {
  if (m % n == 0) return n;
  return _gcd(n, m % n);
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first < b.first)
    return true;
  else if (a.first == b.first && a.second > b.second)
    return true;
  return false;
}
int main() {
  long long n;
  cin >> n;
  vector<long long> v(n, 0);
  for (long long i = 0; i < n; i++) cin >> v[i];
  long long gcd = v[0];
  for (long long i = 1; i < n; i++) gcd = _gcd(gcd, v[i]);
  vector<pair<long long, long long> > D;
  for (long long i = 0; i < n; i++) {
    pair<long long, long long> p;
    p.first = 0;
    p.second = 0;
    long long t = v[i] / gcd;
    while (t % 2 == 0) {
      p.first++;
      t /= 2;
    }
    while (t % 3 == 0) {
      p.second++;
      t /= 3;
    }
    D.push_back(p);
  }
  sort(D.begin(), D.end(), cmp);
  for (long long i = 0; i < n; i++) {
    long long r = gcd;
    while (D[i].first) {
      D[i].first--;
      r *= 2;
    }
    while (D[i].second) {
      D[i].second--;
      r *= 3;
    }
    cout << r << " ";
  }
  return 0;
}
