#include <bits/stdc++.h>
using namespace std;
vector<vector<unsigned long long>> g;
vector<bool> visited;
vector<unsigned long long> s;
void dfs(unsigned long long x) {
  visited[x] = 1;
  for (unsigned long long i : g[x])
    if (!visited[i]) dfs(i);
  s.push_back(x);
}
int main() {
  unsigned long long n;
  cin >> n;
  vector<unsigned long long> v(n);
  for (unsigned long long &i : v) cin >> i;
  g.assign(n, vector<unsigned long long>());
  visited.assign(n, 0);
  for (unsigned long long i = 0; i < n; i++) {
    for (unsigned long long j = 0; j < n; j++) {
      if (v[i] * 2 == v[j]) {
        g[i].push_back(j);
      } else if (v[i] * 3 == v[j]) {
        g[j].push_back(i);
      }
    }
  }
  for (unsigned long long i = 0; i < n; i++) {
    if (!visited[i]) dfs(i);
  }
  while (!s.empty()) {
    cout << v[s.back()] << " ";
    s.pop_back();
  }
}
