#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<unsigned long long int> vec(n);
  unordered_set<unsigned long long int> mp;
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    mp.insert(vec[i]);
  }
  int root = -1;
  for (int i = 0; i < n; i++) {
    unsigned long long int p1 = vec[i] * 3, p2 = -1;
    if (vec[i] % 2 == 0) p2 = vec[i] / 2;
    if (mp.find(p1) == mp.end() && mp.find(p2) == mp.end()) {
      root = i;
      break;
    }
  }
  queue<unsigned long long int> Q;
  Q.push(vec[root]);
  while (!Q.empty()) {
    auto u = Q.front();
    Q.pop();
    unsigned long long int c1 = u * 2;
    if (mp.find(c1) != mp.end()) Q.push(c1);
    if (u % 3 == 0) {
      unsigned long long int c2 = u / 3;
      if (mp.find(c2) != mp.end()) Q.push(c2);
    }
    cout << u << " ";
  }
  return 0;
}
