#include <bits/stdc++.h>
using namespace std;
void customrun() {}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long powerwithmod(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool comp(const pair<int, pair<long long, long long> > &a,
          const pair<int, pair<long long, long long> > &b) {
  if (a.second.first == b.second.first)
    return a.second.second < b.second.second;
  return a.second.first > b.second.first;
}
void solve();
int main() {
  clock_t begin = clock();
  fast();
  customrun();
  long long t = 1;
  for (long long i = (1); i < (t + 1); i += (1)) {
    solve();
  }
  clock_t end = clock();
  double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  return 0;
}
void solve() {
  int n;
  cin >> (n);
  long long arr[n];
  for (long long i = 0; i < n; i++) cin >> (arr[i]);
  vector<pair<int, pair<long long, long long> > > v(n);
  for (long long i = 0; i < n; i++) {
    long long val = arr[i];
    v[i].first = i;
    while (val > 0 and val % 2 == 0) {
      val /= 2;
      v[i].second.second++;
    }
    while (val > 0 and val % 3 == 0) {
      val /= 3;
      v[i].second.first++;
    }
  }
  sort(v.begin(), v.end(), comp);
  for (long long i = 0; i < n; i++) cout << arr[v[i].first] << " ";
}
