#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long> plis;
bool dfs(vector<unsigned long long> a) {
  if (plis.empty()) return false;
  if (plis.size() == a.size()) return true;
  unsigned long long s = plis.back();
  if (binary_search(a.begin(), a.end(), s * 2)) {
    plis.push_back(s * 2);
    return dfs(a);
  }
  if (s % 3 == 0 && binary_search(a.begin(), a.end(), s / 3)) {
    plis.push_back(s / 3);
    return dfs(a);
  }
  plis.pop_back();
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<unsigned long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<unsigned long long> ans;
  for (int i = 0; i < n; i++) {
    plis.clear();
    plis.push_back(a[i]);
    if (dfs(a)) {
      ans = plis;
      break;
    }
  }
  for (unsigned long long x : ans) cout << x << " ";
  return 0;
}
