#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100 + 10];
long long ans[100 + 10];
deque<long long> kolejka;
bool find(long long x) {
  for (int i = 0; i < n; i++)
    if (a[i] == x) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long x;
  for (int i = 0; i < n; i++) {
    x = a[i];
    if ((find(x / 2) == 0 || x % 2 == 1) && find(x * 3) == 0) {
      if (find(x * 2) == 1)
        ans[0] = x;
      else
        ans[0] = x;
      break;
    }
  }
  for (int i = 0; i + 1 < n; i++)
    if (find(ans[i] * 2) == 1)
      ans[i + 1] = ans[i] * 2;
    else
      ans[i + 1] = ans[i] / 3;
  for (int i = 0; i < n; i++) cout << ans[i] << ' ';
  return 0;
}
