#include <bits/stdc++.h>
using namespace std;
deque<int> d;
long long int ara[10000];
vector<long long int> g[100];
vector<long long int> k[100];
int main() {
  int i, n;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    int a;
    scanf("%lld", &ara[i]);
  }
  int j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (ara[i] * 2 == ara[j]) {
        g[i].push_back(j);
        k[j].push_back(i);
      } else if (ara[i] % 3 == 0 && ara[i] / 3 == ara[j]) {
        g[i].push_back(j);
        k[j].push_back(i);
      }
    }
  }
  long long int nd;
  for (i = 0; i < n; i++) {
    if (k[i].size() == 0) {
      nd = i;
    }
  }
  while (!g[nd].empty()) {
    printf("%lld ", ara[nd]);
    nd = g[nd][0];
  }
  cout << ara[nd] << endl;
  return 0;
}
