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