#include <bits/stdc++.h>
using namespace std;
class numberOrder {
 public:
  long long number;
  int occurenceDivBy3;
  numberOrder() {
    number = 0;
    occurenceDivBy3 = 0;
  }
};
int factorizeBy3(long long n) {
  int cnt = 0;
  while (n % 3 == 0) {
    cnt++;
    n /= 3;
  }
  return cnt;
}
bool compare(numberOrder a, numberOrder b) {
  if (a.occurenceDivBy3 == b.occurenceDivBy3) return a.number < b.number;
  return a.occurenceDivBy3 > b.occurenceDivBy3;
}
int main() {
  int n;
  scanf("%d", &n);
  numberOrder board[n + 5];
  for (int i = 0; i < n; i++) {
    scanf("%lld", &board[i].number);
    board[i].occurenceDivBy3 = factorizeBy3(board[i].number);
  }
  sort(board, board + n, compare);
  for (int i = 0; i < n; i++) {
    if (i + 1 == n)
      printf("%lld\n", board[i].number);
    else
      printf("%lld ", board[i].number);
  }
  return 0;
}
