#include <bits/stdc++.h>
using namespace std;
bool cmp(long long int& a, long long int& b) {
  long long int na = 0, nb = 0;
  long long int div = 3;
  while (a % div == 0) {
    na++;
    div *= 3;
  }
  div = 3;
  while (b % div == 0) {
    nb++;
    div *= 3;
  }
  if (na == nb) {
    return a < b;
  } else {
    return na > nb;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n, cmp);
  for (int i = 0; i < n; i++) {
    cout << arr[i] << " ";
  }
  cout << endl;
  return 0;
}
