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