#include <bits/stdc++.h>
using namespace std;
long long log3(long long x) {
  long long ret = 0;
  while (x % 3 == 0) {
    x /= 3;
    ret++;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].second;
    a[i].first = 0 - log3(a[i].second);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    cout << a[i].second << " ";
  }
}
