#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int main(int argc, char const *argv[]) {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> s(n);
  map<long long, int> freq;
  map<long long, long long> next;
  map<long long, long long> prev;
  vector<long long> ret(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    freq[s[i]]++;
  }
  for (int i = 0; i < n; i++) {
    if (freq[s[i] * 2]) {
      next[s[i]] = s[i] * 2;
    } else if (!(s[i] % 3) && freq[s[i] / 3]) {
      next[s[i]] = s[i] / 3;
    } else {
    }
    if (freq[s[i] * 3]) {
      prev[s[i]] = s[i] * 3;
    } else if (!(s[i] % 2) && freq[s[i] / 2]) {
      prev[s[i]] = s[i] / 2;
    } else {
      prev[s[i]] = s[i];
      ret[0] = s[i];
    }
  }
  for (int i = 1; i < n; i++) {
    ret[i] = next[ret[i - 1]];
  }
  for (auto x : ret) {
    cout << x << " ";
  }
  return 0;
}
