#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
bool vis[105];
map<long long, int> mop;
map<int, long long> pom;
vector<int> adj[105];
vector<int> topsort;
void dfs(int node) {
  vis[node] = 1;
  for (auto v : adj[node]) {
    if (!vis[v]) dfs(v);
  }
  topsort.push_back(node);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    mop[arr[i]] = i + 1;
    pom[i + 1] = arr[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (arr[i] * 2 == arr[j]) adj[mop[arr[i]]].push_back(mop[arr[j]]);
      if (arr[i] % 3 == 0 && arr[i] / 3 == arr[j])
        adj[mop[arr[i]]].push_back(mop[arr[j]]);
    }
  }
  for (int i = 0; i < n; i++) {
    if (!vis[i + 1]) dfs(i + 1);
  }
  reverse(topsort.begin(), topsort.end());
  for (int i = 0; i < topsort.size(); i++) cout << pom[topsort[i]] << " ";
  return 0;
}
