#include <bits/stdc++.h>
const int inf = 1e9;
using namespace std;
int get(long long x) {
  long long ans = 0;
  while (x % 3 == 0) {
    ans++;
    x /= 3;
  }
  return ans;
}
bool cmp(long long x, long long y) {
  if (get(x) != get(y)) return get(x) > get(y);
  return x < y;
}
int main() {
  int n;
  long long a[150];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) printf("%I64d ", a[i]);
  printf("\n");
}
