#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n + 1];
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) {
    bool flag[n + 1], brcheck = true;
    memset(flag, false, sizeof(flag));
    flag[i] = true;
    vector<long long> v;
    v.push_back(a[i]);
    for (long long j = 2; j <= n; j++) {
      bool check = false;
      for (long long k = 1; k <= n; k++)
        if (!flag[k] && (v[(long long)v.size() - 1] * 2 == a[k] ||
                         (a[k] * 3 == v[(long long)v.size() - 1]))) {
          flag[k] = true;
          v.push_back(a[k]);
          check = true;
          break;
        }
      if (!check) {
        brcheck = false;
        break;
      }
    }
    if (brcheck) {
      for (auto i : v) cout << i << " ";
      return 0;
    }
  }
}
