#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long num;
  int val;
};
bool mysort(Node n1, Node n2) {
  if (n1.val != n2.val) {
    return n1.val > n2.val;
  } else
    return n1.num < n2.num;
}
int main() {
  int N;
  cin >> N;
  long long ac;
  Node node[N];
  for (int n = 0; n < N; n++) {
    cin >> ac;
    int t = 0;
    node[n].num = ac;
    while (ac > 0 && ac % 3 == 0) {
      t++;
      ac /= 3;
    }
    node[n].val = t;
  }
  sort(node, node + N, mysort);
  for (int n = 0; n < N; n++) cout << node[n].num << ' ';
  return 0;
}
