#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> v(n);
  map<long long, int> mp1;
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &v[i]);
    mp1[v[i]]++;
  }
  map<long long, int> mp2;
  long long start;
  for (int i = 0; i < n; i++) {
    start = v[i];
    long long x = v[i];
    int c = 0;
    mp2 = mp1;
    while (mp2[x]) {
      mp2[x]--;
      if (x % 3 == 0 && mp2[x / 3])
        x /= 3;
      else if (mp2[x * 2])
        x *= 2;
      else
        break;
      c++;
    }
    if (c == n - 1) break;
  }
  printf("%I64d ", start);
  while (mp1[start]) {
    mp1[start]--;
    if (start % 3 == 0 && mp1[start / 3])
      start /= 3;
    else if (mp1[start * 2])
      start *= 2;
    else
      break;
    printf("%I64d ", start);
  }
}
