#include <bits/stdc++.h>
using namespace std;
struct NODE {
  long long val, id;
} a[1010];
bool cmp(NODE x, NODE y) {
  if (x.id == y.id) return x.val < y.val;
  return x.id > y.id;
}
long long idd(long long x) {
  long long sum = 0;
  while (x % 3 == 0) sum++, x /= 3;
  return sum;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i].val);
  for (int i = 1; i <= n; i++) a[i].id = idd(a[i].val);
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) printf("%lld ", a[i].val);
  return 0;
}
