#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const long long N = 1e5 + 10;
const long long mod = 1e9 + 7;
long long cnt(long long n) {
  long long c = 0;
  while (n % 3 == 0) c++, n /= 3;
  return c;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a(n);
  for (long long i = 0; i < n; ++i) cin >> a[i].second;
  sort(a.begin(), a.end());
  for (auto &i : a) {
    i.first = -cnt(i.second);
  }
  sort(a.begin(), a.end());
  for (auto i : a) cout << i.second << " ";
  return 0;
}
