#include <bits/stdc++.h>
using namespace std;
using str = string;
void read(long long& x) { cin >> x; }
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
long long n, m;
long long temp;
long long cnt;
long long ans;
long long a[(long long)1e6 + 6];
bool static comp(vector<long long> a, vector<long long> b) {
  if (a[0] < b[0]) {
    return 1;
  } else if (a[0] == b[0]) {
    return a[1] > b[1];
  } else {
    return 0;
  }
}
void test_case() {
  long long n;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<vector<long long>> brr;
  for (long long i = 0; i < n; i++) {
    long long val = arr[i];
    long long cnt3 = 0;
    while (val % 3 == 0) {
      cnt3++;
      val = val / 3;
    }
    val = arr[i];
    long long cnt2 = 0;
    while (val % 2 == 0) {
      cnt2++;
      val = val / 2;
    }
    brr.push_back({cnt3, cnt2, arr[i]});
  }
  sort(brr.begin(), brr.end(), comp);
  reverse(brr.begin(), brr.end());
  for (auto it : brr) {
    cout << it[2] << " ";
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  long long t = 1;
  while (t--) {
    test_case();
  }
}
