#include <bits/stdc++.h>
using namespace std;
unsigned long long n, k;
vector<unsigned long long> V;
vector<unsigned long long> Sol;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    unsigned long long x;
    cin >> x;
    V.push_back(x);
  }
  Sol.push_back(V.back());
  V.pop_back();
  while (1) {
    if (V.size() == 0) break;
    bool something = false;
    for (int i = 0; i < Sol.size() && something == false; ++i)
      for (int j = 0; j < V.size() && something == false; ++j)
        if (V[j] % 2 == 0)
          if (V[j] / 2 == Sol[i]) {
            Sol.insert(Sol.begin() + i + 1, V[j]);
            V.erase(V.begin() + j);
            something == true;
          }
    if (something == false) {
      for (int i = 0; i < Sol.size() && something == false; ++i)
        for (int j = 0; j < V.size() && something == false; ++j)
          if (Sol[i] % 3 == 0)
            if (V[j] == Sol[i] / 3) {
              Sol.insert(Sol.begin() + i + 1, V[j]);
              V.erase(V.begin() + j);
              something == true;
            }
    }
    if (something == false) {
      for (int i = 0; i < Sol.size() && something == false; ++i)
        for (int j = 0; j < V.size() && something == false; ++j)
          if (Sol[i] % 2 == 0)
            if (V[j] == Sol[i] / 2) {
              Sol.insert(Sol.begin() + i, V[j]);
              V.erase(V.begin() + j);
              something == true;
            }
    }
    if (something == false) {
      for (int i = 0; i < Sol.size() && something == false; ++i)
        for (int j = 0; j < V.size() && something == false; ++j)
          if (V[j] % 3 == 0)
            if (V[j] / 3 == Sol[i]) {
              Sol.insert(Sol.begin() + i, V[j]);
              V.erase(V.begin() + j);
              something == true;
            }
    }
  }
  for (auto x : Sol) cout << x << " ";
  return 0;
}
