#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
typedef long double ld;
typedef pair<long long, long long> pii;
const long long mod = 1000000007LL;
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < (long long)n; i++) cin >> v[i];
  auto comp = [&](long long a, long long b) {
    long long f3a = 0, f3b = 0;
    long long f2a = 0, f2b = 0;
    long long temp = a;
    while (temp % 2 == 0) {
      temp /= 2;
      f2a++;
    }
    while (temp % 3 == 0) {
      temp /= 3;
      f3a++;
    }
    temp = b;
    while (temp % 2 == 0) {
      temp /= 2;
      f2b++;
    }
    while (temp % 3 == 0) {
      temp /= 3;
      f3b++;
    }
    if (f3a == f3b) return f2a < f2b;
    return f3a > f3b;
  };
  sort((v).begin(), (v).end(), comp);
  for (long long i : v) cout << i << " ";
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
