#include <bits/stdc++.h>
long long divby3[1000];
long long mult2[1000];
long long B[3000];
long long power(long long a, long long b) {
  long long temp = a;
  while (b != 0) {
    temp *= 3;
    b--;
  }
  return temp;
}
void merge(long long arr[], long long b[], long long l, long long m,
           long long r) {
  long long i, j, k;
  long long n1 = m - l + 1;
  long long n2 = r - m;
  long long LA[n1], LB[n1], RA[n2], RB[n2];
  for (i = 0; i < n1; i++) {
    LA[i] = arr[l + i];
    LB[i] = b[l + i];
  }
  for (j = 0; j < n2; j++) {
    RB[j] = b[m + 1 + j];
    RA[j] = arr[m + 1 + j];
  }
  i = 0;
  j = 0;
  k = l;
  while (i < n1 && j < n2) {
    if (LA[i] <= RA[j]) {
      b[k] = LB[i];
      arr[k] = LA[i];
      i++;
    } else {
      b[k] = RB[j];
      arr[k] = RA[j];
      j++;
    }
    k++;
  }
  while (i < n1) {
    b[k] = LB[i];
    arr[k] = LA[i];
    i++;
    k++;
  }
  while (j < n2) {
    b[k] = RB[j];
    arr[k] = RA[j];
    j++;
    k++;
  }
}
void mergeSort(long long arr[], long long b[], long long l, long long r) {
  if (l < r) {
    long long m = l + (r - l) / 2;
    mergeSort(arr, b, l, m);
    mergeSort(arr, b, m + 1, r);
    merge(arr, b, l, m, r);
  }
}
int main(void) {
  int N;
  scanf("%d", &N);
  long long Array[N];
  for (int i = 0; i < N; i++) {
    scanf("%lld", &Array[i]);
  }
  for (int i = 0; i < N; i++) {
    if (Array[i] % 3 == 0) {
      while (Array[i] % 3 == 0) {
        B[i]++;
        Array[i] = Array[i] / 3;
      }
    }
  }
  mergeSort(Array, B, 0, N - 1);
  int start = 0;
  int end = 0;
  int flag = 0;
  for (int i = 1; i < N; i++) {
    if (Array[i] == Array[i - 1]) {
      end++;
    } else {
      mergeSort(B, Array, start, end);
      start = i;
      end = i;
    }
  }
  mergeSort(B, Array, start, end);
  int f = 0;
  int br = 0;
  for (int h = 1; h < N; h++) {
    if (Array[h] == Array[h - 1]) {
      br++;
      continue;
    } else {
      for (int g = br; g >= f; g--) {
        printf("%lld ", power(Array[g], B[g]));
      }
      f = h;
      br = h;
    }
  }
  for (int d = N - 1; d >= f; d--) {
    printf("%lld ", power(Array[d], B[d]));
  }
  printf("\n");
  return 0;
}
