#include <bits/stdc++.h>
long long n, s;
struct temp {
  long long v;
  int counta, countb;
  temp(long long a = 0) : v(a) {
    s = a;
    counta = countb = 0;
    while (s && s % 2 == 0) {
      counta++;
      s /= 2;
    }
    while (a && a % 3 == 0) {
      countb++;
      a /= 3;
    }
  }
  bool operator<(const temp &a) const {
    return countb == a.countb ? counta < a.counta : countb > a.countb;
  }
} a[110];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  long long t;
  for (int i = 0; i < n; i++) {
    std::cin >> t;
    a[i] = temp(t);
  }
  std::sort(a, a + n);
  for (int i = 0; i < n; i++) std::cout << a[i].v << " ";
  std::cout << std::endl;
  return 0;
}
