#include <bits/stdc++.h>
using namespace std;
long long m[1000001], cd, kq[100000];
map<long long, long long> ruler;
int main() {
  cin >> cd;
  for (long long i = 1; i <= cd; i++) {
    cin >> m[i];
    ruler[m[i]] = 1;
  }
  for (long long i = 1; i <= cd; i++) {
    long long e = 1;
    kq[e] = m[i];
    long long t = m[i];
    while (e <= cd) {
      if (ruler[t * 2] == 1) {
        kq[e + 1] = t * 2;
        t = t * 2;
      } else if (t % 3 == 0 && ruler[t / 3] == 1) {
        kq[e + 1] = t / 3;
        t = t / 3;
      } else
        break;
      e++;
      if (e == cd) {
        for (long long k = 1; k <= cd; k++) cout << kq[k] << " ";
        exit(0);
      }
    }
  }
}
