#include <bits/stdc++.h>
using namespace std;
inline void Boost() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  Boost();
  int n;
  cin >> n;
  vector<long long int> v(n);
  for (auto &x : v) cin >> x;
  sort(v.begin(), v.end(), [&](long long int a, long long int b) {
    int pa, pb;
    pa = pb = 0;
    while (a % 3 == 0) ++pa, a /= 3;
    while (b % 3 == 0) ++pb, b /= 3;
    if (pa != pb) return pa > pb;
    pa = pb = 0;
    while (a % 2 == 0) ++pa, a /= 2;
    while (b % 2 == 0) ++pb, b /= 2;
    return pa < pb;
  });
  for (auto x : v) cout << x << " ";
  return 0;
}
