#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
bool coll(pair<long long, long long> p1, pair<long long, long long> p2,
          pair<long long, long long> p3) {
  if ((p3.second - p2.second) * (p2.first - p1.first) ==
      (p2.second - p1.second) * (p3.first - p2.first))
    return true;
  else
    return false;
}
void pv(vector<long long> v) {
  for (long long i = 0; i < (long long)v.size(); i++) cout << v[i] << " ";
  cout << '\n';
}
void in(vector<long long> v, long long n) {
  v.resize(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
}
void sortv(vector<long long> v) { sort(v.begin(), v.end()); }
int main() {
  long long n;
  cin >> n;
  long long a[n + 1];
  unordered_map<long long, long long> m;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    m[a[i]] = i;
  }
  vector<long long> parent(n + 1, 0);
  vector<long long> child(n + 1, 0);
  for (long long i = 1; i <= n; i++) {
    long long x = a[i];
    long long a1 = x * 2;
    if (m[a1] > 0) {
      child[i] = m[a1];
      parent[m[a1]] = i;
    }
    if (x % 3 == 0) {
      a1 = x / 3;
      if (m[a1] > 0) {
        child[i] = m[a1];
        parent[m[a1]] = i;
      }
    }
  }
  long long ans = -1;
  for (long long i = 1; i <= n; i++) {
    if (parent[i] == 0) {
      ans = i;
      break;
    }
  }
  while (1) {
    cout << a[ans] << " ";
    ans = child[ans];
    if (ans == 0) break;
  }
}
