#include <bits/stdc++.h>
using namespace std;
unsigned long long n, a, b, p;
vector<unsigned long long> v[50];
int main() {
  cin >> n;
  while (n--) {
    cin >> a;
    b = a;
    p = 0;
    while (b % 3 == 0) {
      ++p;
      b /= 3;
    }
    v[p].push_back(a);
  }
  for (unsigned long long i = 49; i >= 0; --i) {
    if (v[i].empty()) {
      if (i == 0) break;
      continue;
    }
    sort(v[i].begin(), v[i].end());
    for (auto& e : v[i]) cout << e << ' ';
    if (i == 0) {
      cout << endl;
      return 0;
    }
  }
  return 0;
}
