#include <bits/stdc++.h>
using namespace std;
vector<long long int> v, vec;
long long int n;
int visited[105];
void dfs(long long int x) {
  int ck = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == x) {
      ck = 1;
      visited[i] = 1;
    }
  }
  if (ck == 0)
    return;
  else
    vec.push_back(x);
  if (x > 2 && x % 3 == 0) {
    dfs(x * 2);
    dfs(x / 3);
  } else {
    dfs(x * 2);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    int ck = 0;
    dfs(v[i]);
    for (int j = 0; j < n; j++) {
      if (visited[j] == 0) ck = 1;
    }
    if (ck == 0) {
      for (int j = 0; j < vec.size(); j++) {
        cout << vec[j] << " ";
      }
      exit(0);
    }
    memset(visited, 0, sizeof visited);
    vec.clear();
  }
  return 0;
}
