#include <bits/stdc++.h>
using namespace std;
int powerOf3(long long int n) {
  int c = 0;
  while (n % 3 == 0) {
    c++;
    n /= 3;
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<pair<long long int, long long int> > v;
  v.resize(n);
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    v[i].second = x;
    int y = -powerOf3(x);
    v[i].first = y;
  }
  sort(v.begin(), v.end());
  for (long long int i = 0; i < n; i++) {
    cout << v[i].second << " ";
  }
  return 0;
}
