#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long minf = -(1e18);
pair<long long, long long> arr[101];
bool compare(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first == b.first) {
    return a.second < b.second;
  } else {
    return a.first > b.first;
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i].second;
    long long temp = arr[i].second;
    while (temp % 3 == 0 && temp > 0) {
      arr[i].first++;
      temp = temp / 3;
    }
  }
  sort(arr + 1, arr + n + 1, compare);
  for (int i = 1; i <= n; i++) {
    cout << arr[i].second << " ";
  }
  return 0;
}
