#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long> ans;
bool dfs(unsigned long long source, unordered_map<unsigned long long, int>& m,
         set<unsigned long long> s) {
  if (m.find(source) == m.end()) return 0;
  if (m[source] == 0) return 0;
  m[source]--;
  ans.push_back(source);
  if (m[source] == 0) s.erase(source);
  if (s.size() == 0) return 1;
  if (source % 3 == 0 && m.find(source / 3) != m.end() && m[source / 3] > 0) {
    if (dfs(source / 3, m, s)) return 1;
  }
  if (source <= ULLONG_MAX / 2 && m.find(2 * source) != m.end() &&
      m[2 * source] > 0) {
    if (dfs(2 * source, m, s)) return 1;
  }
  ans.pop_back();
  m[source]++;
  s.insert(source);
  return 0;
}
int main() {
  int n;
  cin >> n;
  int i;
  unordered_map<unsigned long long, int> m;
  vector<unsigned long long> v;
  set<unsigned long long> s;
  for (i = 0; i < n; i++) {
    unsigned long long temp;
    cin >> temp;
    s.insert(temp);
    if (m.find(temp) == m.end())
      m.insert(make_pair(temp, 1));
    else
      m[temp]++;
    v.push_back(temp);
  }
  vector<unsigned long long> a;
  for (i = 0; i < v.size(); i++) {
    if (dfs(v[i], m, s)) {
      a = ans;
      break;
    } else
      ans.clear();
  }
  for (i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  return 0;
}
