#include <bits/stdc++.h>
using namespace std;
const long long MXN = 1e6 + 7;
const long long INF = 2e18 + 7;
inline void Need_for_speed() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long a[MXN];
map<long long, long long> m_odd, m_even;
int main() {
  Need_for_speed();
  vector<long long> node;
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    m_odd[a[i]]++;
    m_even[a[i]]++;
    node.push_back(a[i]);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    vector<long long> ans_odd, ans_even;
    bool ok_odd, ok_even;
    if (m_odd[a[i] * 3] > 0) {
      ok_odd = 1;
      ans_odd.push_back(a[i] * 3);
      ans_odd.push_back(a[i]);
      m_odd[a[i] * 3]--;
      m_odd[a[i]]--;
      if (m_odd[a[i] * 2] > 0) {
        ans_odd.push_back(a[i] * 2);
        m_odd[a[i] * 2]--;
      }
    }
    if (m_even[a[i] * 2] > 0) {
      ok_even = 1;
      ans_even.push_back(a[i]);
      ans_even.push_back(a[i] * 2);
      m_even[a[i]]--;
      m_even[a[i] * 2]--;
    }
    if (ok_odd) {
      for (int j = ans_odd.size() - 1; j < ans_odd.size(); j++) {
        long long num = ans_odd[j];
        if (m_odd[num / 3] > 0) {
          ans_odd.push_back(num / 3);
          m_odd[num / 3]--;
        } else if (m_odd[num * 2] > 0) {
          ans_odd.push_back(num * 2);
          m_odd[num * 2]--;
        }
      }
      if (ans_odd.size() != n) {
        ok_odd = 0;
      }
    }
    if (ok_even) {
      for (int j = ans_even.size() - 1; j < ans_even.size(); j++) {
        long long num = ans_even[j];
        if (m_even[num / 3] > 0) {
          ans_even.push_back(num / 3);
          m_even[num / 3]--;
        } else if (m_even[num * 2] > 0) {
          ans_even.push_back(num * 2);
          m_even[num * 2]--;
        }
      }
      if (ans_even.size() != n) {
        ok_even = 0;
      }
    }
    if (ok_odd) {
      for (long long j : ans_odd) {
        cout << j << ' ';
      }
      return 0;
    }
    if (ok_even) {
      for (long long j : ans_even) {
        cout << j << ' ';
      }
      return 0;
    }
    for (long long j : node) {
      m_odd[j] = 0;
      m_even[j] = 0;
    }
    for (long long j : node) {
      m_odd[j]++;
      m_even[j]++;
    }
  }
  exit(0);
}
