#include <bits/stdc++.h>
struct opo {
  long long data;
  struct opo *next;
};
int main() {
  struct opo *head, *p, *q, *a[105];
  int t, i, k = 0, b[105] = {0};
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    long long n;
    scanf("%lld", &n);
    p = (struct opo *)malloc(sizeof(opo));
    p->data = n;
    p->next = NULL;
    a[k] = p;
    int o2 = 1, o3 = 1;
    for (int j = 0; j < k; j++) {
      if (o2 == 0 && o3 == 0) break;
      if (a[j]->data * 3 == p->data) {
        p->next = a[j];
        b[j] = 1;
        o3 = 0;
      } else if (p->data * 3 == a[j]->data) {
        a[j]->next = p;
        b[k] = 1;
        o3 = 0;
      }
      if (a[j]->data * 2 == p->data) {
        a[j]->next = p;
        b[k] = 1;
        o2 = 0;
      } else if (p->data * 2 == a[j]->data) {
        p->next = a[j];
        b[j] = 1;
        o2 = 0;
      }
    }
    k++;
  }
  for (i = 0; i < k; i++) {
    if (b[i] == 0) {
      p = a[i];
      while (p != NULL) {
        if (p != a[i]) printf(" ");
        printf("%lld", p->data);
        p = p->next;
      }
      break;
    }
  }
  return 0;
}
