#include <bits/stdc++.h>
using namespace std;
struct debugger {
  static void call(string::iterator it, string::iterator ed) {}
  template <typename T, typename... aT>
  static void call(string::iterator it, string::iterator ed, T a, aT... rest) {
    string b;
    for (; *it != ','; ++it)
      if (*it != ' ') b += *it;
    cerr << b << " = " << a << " ";
    call(++it, ed, rest...);
  }
};
int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
int knight_x[] = {2, 2, -2, -2, 1, 1, -1, -1};
int knight_y[] = {1, -1, 1, -1, 2, -2, 2, -2};
const double PI = 2.0 * acos(0.0);
const double GOLD = (1.0 + sqrt(5.0)) / 2.0;
const double eps = 1e-9;
long long int ar[1000];
int child[1000];
int deg[1000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  memset(child, -1, sizeof(child));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (ar[i] * 2 == ar[j]) {
        child[i] = j;
        deg[j] = 1;
        break;
      }
      if (ar[i] % 3 == 0 && ar[i] / 3 == ar[j]) {
        child[i] = j;
        deg[j] = 1;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (deg[i] == 0) {
      cout << ar[i] << " ";
      while (child[i] != -1) {
        cout << ar[child[i]] << " ";
        i = child[i];
      }
      break;
    }
  }
}
