#include <bits/stdc++.h>
using namespace std;
void topsort(long long int s, vector<vector<long long int>> &graph,
             vector<long long int> &vis, vector<long long int> &ans) {
  vis[s] = 1;
  for (long long int i = 0; i < graph[s].size(); i++) {
    if (vis[graph[s][i]] == 0) topsort(graph[s][i], graph, vis, ans);
  }
  ans.push_back(s);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> v;
  for (long long int i = 0; i < n; i++) {
    long long int num;
    cin >> num;
    v.push_back(num);
  }
  vector<vector<long long int>> graph(n);
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      if ((v[i] % 3 == 0 && v[j] == v[i] / 3) || v[j] == v[i] * 2)
        graph[i].push_back(j);
    }
  }
  vector<long long int> ans;
  vector<long long int> vis(n, 0);
  for (long long int i = 0; i < n; i++) {
    if (vis[i] == 0) topsort(i, graph, vis, ans);
  }
  reverse(ans.begin(), ans.end());
  for (long long int i = 0; i < ans.size(); i++) {
    cout << v[ans[i]] << " ";
  }
  cout << endl;
  return 0;
}
