#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<long long int, long long int>& a,
         const pair<long long int, long long int>& b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}
long long int count3(long long int x) {
  long long int cnt = 0;
  while (x % 3 == 0) {
    cnt++;
    x /= 3;
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<long long int, long long int>> v(n);
  for (int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    v[i].first = count3(x);
    v[i].second = x;
  }
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < n; i++) cout << v[i].second << " ";
  cout << endl;
  return 0;
}
