#include <bits/stdc++.h>
using namespace std;
int f(long long n) {
  int cnt = 0;
  while (n % 3 == 0) {
    cnt++;
    n /= 3;
  }
  return cnt;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  pair<int, long long> mas[n];
  for (size_t i = 0; i < n; i++) {
    cin >> mas[i].second;
    mas[i].first = -f(mas[i].second);
  }
  sort(mas, mas + n);
  for (int i = 0; i < n; i++) cout << mas[i].second << ' ';
  return 0;
}
