#include <bits/stdc++.h>
using namespace std;
int n, flag;
long long a[110], ans[110];
bool vis[110];
void dfs(int step) {
  if (step == n + 1) {
    for (int i = 1; i < n; ++i) printf("%lld ", ans[i]);
    printf("%lld", ans[n]);
    flag = 1;
    return;
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i] &&
        ((ans[step - 1] == a[i] * 3) || (ans[step - 1] * 2 == a[i]))) {
      vis[i] = 1;
      ans[step] = a[i];
      dfs(step + 1);
      if (flag) return;
      vis[i] = 0;
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  for (int i = 1; i <= n; ++i) {
    ans[1] = a[i];
    dfs(2);
    if (flag) return 0;
  }
}
