#include <bits/stdc++.h>
using namespace std;
const int MAX = 200;
vector<int> v[MAX];
bool visit[MAX];
int n, st;
long long arr[MAX];
map<long long, int> mp;
void dfs(int node) {
  printf("%lld ", arr[node - 1]);
  if (v[node].size() > 0) dfs(v[node][0]);
}
int main() {
  scanf("%lld", &n);
  memset(visit, 1, sizeof visit);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    mp[arr[i]] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    if (!(arr[i] % 3) && mp[arr[i] / 3] > 0) {
      v[i + 1].push_back(mp[arr[i] / 3]);
      visit[mp[arr[i] / 3]] = 0;
    } else if (mp[arr[i] * 2] > 0) {
      v[i + 1].push_back(mp[arr[i] * 2]);
      visit[mp[arr[i] * 2]] = 0;
    }
  }
  for (int i = 1; i <= n; i++)
    if (visit[i]) {
      st = i;
      break;
    }
  dfs(st);
}
