#include <bits/stdc++.h>
using namespace std;
long long a[100005], ans[100005];
int main() {
  int n;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long s;
  for (int i = 1; i <= n; i++) {
    bool flag = true;
    if (i == n) ans[1] = a[n];
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (a[i] / 2 == a[j] || a[i] * 3 == a[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans[1] = a[i];
      break;
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (ans[i - 1] == a[j]) continue;
      if ((ans[i - 1] % 3 == 0 && ans[i - 1] / 3 == a[j]) ||
          ans[i - 1] * 2 == a[j]) {
        ans[i] = a[j];
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
}
