#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> ar(n);
  map<long long, bool> m;
  for (int i = 0; i < n; ++i) {
    cin >> ar[i];
    m[ar[i]] = true;
  }
  long long start;
  for (int i = 0; i < n; ++i) {
    if (!(ar[i] % 2 == 0 && m[ar[i] / 2] || m[ar[i] * 3])) {
      start = ar[i];
      break;
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << start << " ";
    if (m[start * 2])
      start *= 2;
    else
      start /= 3;
  }
  return 0;
}
