#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i += 6) {
    if ((n % i == 0) || (n % (i + 2) == 0)) return false;
  }
  return true;
}
map<long long, long long> mp;
set<long long> s;
long long dfs(long long i, long long cnt) {
  long long x = 0;
  if (i % 3 == 0 && s.find(i / 3) != s.end()) {
    x += dfs(i / 3, cnt + 1);
  }
  if (s.find(2 * i) != s.end()) {
    x += dfs(2 * i, cnt + 1);
  }
  return x + 1;
}
int32_t main() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    s.insert(a[i]);
  }
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < n; i++) {
    mp.clear();
    long long x = dfs(a[i], 0);
    v.push_back({x, a[i]});
  }
  sort(v.begin(), v.end());
  for (long long i = n - 1; i >= 0; i--) cout << v[i].second << " ";
}
