#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 1; i <= n; i++) {
    vector<long long> ans;
    long long pr = a[i];
    ans.push_back(a[i]);
    for (int j = 1; j <= n; j++) {
      auto x = lower_bound(a.begin(), a.end(), pr * 2);
      if ((*x) == pr * 2) {
        ans.push_back((*x));
        pr *= 2;
        continue;
      }
      if (pr % 3 == 0) {
        auto y = lower_bound(a.begin(), a.end(), pr / 3);
        if (*y == pr / 3) {
          ans.push_back((*y));
          pr /= 3;
        }
      } else {
        break;
      }
    }
    if (ans.size() == n) {
      for (int i = 0; i < n; i++) cout << ans[i] << " ";
      break;
    }
  }
  return 0;
}
