#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793116;
vector<long long> f[1001];
long long a[1001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long long ndem = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    long long tmp = a[i];
    long long dem = 0;
    while (tmp % 3 == 0) {
      dem++;
      tmp /= 3;
    }
    ndem = max(ndem, dem);
    f[dem].push_back(a[i]);
  }
  for (int i = 0; i <= ndem; i++) sort(f[i].begin(), f[i].end());
  for (int i = ndem; i >= 0; i--) {
    for (int j = 0; j < f[i].size(); j++) cout << f[i][j] << " ";
  }
  return 0;
}
