#include <bits/stdc++.h>
using namespace std;
int count3(long long x) {
  int ret = 0;
  while (x % 3 == 0) {
    x /= 3;
    ret++;
  }
  return ret;
}
int n;
vector<pair<int, long long>> v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].second;
    v[i].first = -count3(v[i].second);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    printf("%lld%c", v[i].second, " \n"[i + 1 == n]);
  }
  return 0;
}
