#include <bits/stdc++.h>
using namespace std;
long long div3(long long x) {
  long long aux = 0;
  while (x % 3 == 0) {
    aux++;
    x /= 3;
  }
  return aux;
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second == b.second) return a.first < b.first;
  return a.second > b.second;
}
int main() {
  long long n;
  pair<long long, long long> a[10000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = div3(a[i].first);
  }
  sort(a, a + n, comp);
  cout << a[0].first;
  for (int i = 1; i < n; i++) {
    cout << ' ' << a[i].first;
  }
  cout << endl;
  return 0;
}
