#include <bits/stdc++.h>
using namespace std;
int main() {
  int no_of_elements;
  scanf("%d", &no_of_elements);
  map<unsigned long long, int> present;
  vector<unsigned long long> A(no_of_elements + 1);
  for (int i = 1; i <= no_of_elements; i++) {
    scanf("%I64u", &A[i]);
    present[A[i]] = true;
  }
  unsigned long long first_element;
  for (int i = 1; i <= no_of_elements; i++) {
    if ((A[i] % 2 != 0 || (A[i] % 2 == 0 && !present[A[i] / 2])) &&
        ((A[i] > 1e18) || (A[i] <= 1e18 && !present[3 * A[i]]))) {
      first_element = A[i];
    }
  }
  vector<unsigned long long> solution;
  solution.push_back(first_element);
  while (solution.size() < no_of_elements) {
    unsigned long long last_element = solution.back();
    if (last_element % 3 == 0 && present[last_element / 3]) {
      solution.push_back(last_element / 3);
    } else {
      solution.push_back(2 * last_element);
    }
  }
  for (int i = 0; i < no_of_elements; i++) printf("%I64u ", solution[i]);
  return 0;
}
