#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<unsigned long long int, int> mp;
  deque<unsigned long long int> dq;
  unsigned long long int source;
  bool y = 0;
  for (int i = 0; i < n; i++) {
    unsigned long long int x;
    cin >> x;
    if (y == 0) {
      source = x;
      y = 1;
    }
    mp[x]++;
  }
  dq.push_back(source);
  mp[source]--;
  while (dq.size() != n) {
    unsigned long long int x = dq.back();
    unsigned long long int y = dq.front();
    if (x % 3 == 0 && mp[x / 3] != 0) {
      dq.push_back(x / 3);
      mp[x / 3]--;
    } else if (mp[y * 3] != 0) {
      dq.push_front(y * 3);
      mp[y * 3]--;
    } else if (mp[x * 2] != 0) {
      dq.push_back(x * 2);
      mp[x * 2]--;
    } else if (mp[y / 2] != 0) {
      dq.push_front(y / 2);
      mp[y / 2]--;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << dq.front() << " ";
    dq.pop_front();
  }
  return 0;
}
