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