#include <bits/stdc++.h>
using namespace std;
const int N = 105;
long long a[N];
int count3(long long x) {
  int ret = 0;
  while (x % 3 == 0) {
    ++ret;
    x /= 3;
  }
  return ret;
}
bool cmp(long long a, long long b) {
  int aa = count3(a), bb = count3(b);
  if (aa == bb) return a < b;
  return aa > bb;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; ++i) cout << a[i] << ' ';
  return 0;
}
