#include <bits/stdc++.h>
using namespace std;
long long pow3(long long a) {
  long long ans = 0;
  while (a % 3 == 0) {
    a /= 3;
    ans++;
  }
  return ans;
}
void solve() {
  int n;
  cin >> n;
  vector<pair<long long, long long> > v;
  long long x;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    v.push_back({-pow3(x), x});
  }
  sort((v).begin(), (v).end());
  for (long long i = 0; i < n; i++) {
    cout << v[i].second << " ";
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}
