#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
vector<long long> inp(269);
vector<long long> v[269];
bool vis[269];
long long doof(long long s) {
  vis[s] = 1;
  long long y = 1;
  for (auto i : v[s]) {
    if (vis[i]) continue;
    y += doof(i);
  }
  return y;
}
long long prnt(long long s) {
  vis[s] = 1;
  cout << inp[s] << " ";
  for (auto i : v[s]) {
    if (vis[i]) continue;
    prnt(i);
  }
  return 0;
}
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> inp[i];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < n; j++)
      if ((inp[i] % 3 == 0 && inp[i] / 3 == inp[j]) || inp[i] * 2 == inp[j])
        v[i].push_back(j);
  for (long long i = 0; i < n; i++) {
    memset(vis, 0, sizeof(vis));
    ;
    if (doof(i) == n) {
      memset(vis, 0, sizeof(vis));
      ;
      return prnt(i);
    }
  }
}
