#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n;
  cin >> n;
  unsigned long long a[100];
  for (int i = 0; i < n; cin >> a[i++])
    ;
  auto b = a + n;
  sort(a, b);
  unsigned long long q, r, s, t, x;
  map<unsigned long long, unsigned long long> next;
  for (int i = 0; i < n; i++)
    if ((r = (x = a[i]) % 3) == 0 && binary_search(a, b, q = x / 3))
      next[q] = x;
    else if (binary_search(a, b, s = x * 2))
      next[s] = x;
    else
      t = x;
  for (int i = n; i > 0; a[--i] = t, t = next[t])
    ;
  for (int i = 0; i < n; cout << a[i++] << ' ')
    ;
}
