#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n;
  cin >> n;
  unordered_map<long long, long long> mp;
  unordered_map<long long, vector<long long>> graph;
  unordered_map<long long, long long> indegree;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    mp[x]++;
    v[i] = x;
    indegree[x] = 0;
  }
  for (long long i = 0; i < n; i++) {
    if (v[i] & 1) {
      long long from = 3 * v[i];
      if (mp.count(from)) {
        indegree[v[i]]++;
        graph[from].push_back(v[i]);
      }
    } else {
      if (mp.count(3 * v[i])) {
        indegree[v[i]]++;
        graph[3 * v[i]].push_back(v[i]);
      } else {
        if (mp.count(v[i] / 2)) {
          indegree[v[i]]++;
          graph[v[i] / 2].push_back(v[i]);
        }
      }
    }
  }
  long long first = -1;
  for (auto ele : indegree) {
    if (ele.second == 0) {
      first = ele.first;
      break;
    }
  }
  cout << first << " ";
  while (!graph[first].empty()) {
    cout << graph[first][0] << " ";
    first = graph[first][0];
  }
}
