#include <bits/stdc++.h>
using ll = long long;
using I64d = long double;
const int mod = 1e9 + 7;
const int N = 1e7, M = 1e6 + 6, OO = 0x3f3f3f3f;
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
ll solve(ll n) {
  ll ret = 0;
  while (!(n % 3)) {
    ret++;
    n /= 3;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  ll arr[n];
  for (auto &i : arr) cin >> i;
  vector<pair<int, ll> > vp;
  for (int i = 0; i < n; ++i) {
    ll x = -solve(arr[i]);
    vp.push_back({x, arr[i]});
  }
  sort(vp.begin(), vp.end());
  for (auto i : vp) cout << i.second << " ";
}
