#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%lld", &n);
  long long arr[n], st;
  map<long long, int> mp;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    mp[arr[i]] = 1;
  }
  for (int i = 0; i < n; i++)
    if (!mp[arr[i] * 3] && ((!(arr[i] % 2) && !mp[arr[i] / 2]) || arr[i] % 2)) {
      st = arr[i];
      break;
    }
  while (n--) {
    printf("%lld ", st);
    !(st % 3) && mp[st / 3] != 0 ? st /= 3 : st *= 2;
  }
}
