#include <bits/stdc++.h>
using namespace std;
const long long size = 1e6 + 7;
const long long mod = 1e9 + 7;
long long arr[size];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  map<long long, long long> M;
  for (long long i = 0; i < n; i++) cin >> arr[i], M[arr[i]] = (long long)1;
  for (long long i = 0; i < n; i++) {
    vector<long long> vi;
    vi.push_back(arr[i]);
    long long j = 0;
    while (true && j < n) {
      long long x = vi[j];
      if (M.find(2 * x) != M.end())
        vi.push_back(2 * x), j++;
      else if (x % 3 == 0 && M.find(x / 3) != M.end())
        vi.push_back(x / 3), j++;
      else
        break;
    }
    if (vi.size() == n) {
      for (long long i = 0; i < n; i++) cout << vi[i] << " ";
      cout << endl;
      break;
    }
  }
}
