#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long mod = 1e9 + 7;
void solve();
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long tests = 1;
  while (tests--) solve();
  return 0;
}
void solve() {
  long long n;
  cin >> n;
  pair<long long, long long> a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i].second;
    long long x = a[i].second;
    long long cnt = 0;
    while (x % 3 == 0) {
      x = x / 3;
      ++cnt;
    }
    a[i].first = -cnt;
  }
  sort(a, a + n);
  for (long long i = 0; i < n; i++) {
    cout << a[i].second << " ";
  }
  cout << endl;
}
