#include <bits/stdc++.h>
using namespace std;
void fast_in_out() {
  std::ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
}
void pause() {}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
unsigned long long arr[101], arr2[101];
map<unsigned long long, unsigned long long> mp, mp2;
int n;
bool f;
void solve(int ind, vector<unsigned long long> v,
           map<unsigned long long, unsigned long long> mpp) {
  if (ind == n) {
    if (f) return;
    f = 1;
    for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << '\n';
    return;
  }
  for (int i = 0; i < n; i++) {
    if (mpp[arr[i]]) {
      if (v.size() == 0) {
        v.push_back(arr[i]);
        mpp[arr[i]]--;
        solve(ind + 1, v, mpp);
        v.pop_back();
        mpp[arr[i]]++;
      } else {
        if (v.back() == arr[i] * 3) {
          v.push_back(arr[i]);
          mpp[arr[i]]--;
          solve(ind + 1, v, mpp);
          v.pop_back();
          mpp[arr[i]]++;
        }
        if (v.back() * 2 == arr[i]) {
          v.push_back(arr[i]);
          mpp[arr[i]]--;
          solve(ind + 1, v, mpp);
          v.pop_back();
          mpp[arr[i]]++;
        }
      }
    }
  }
}
int main() {
  fast_in_out();
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr2[i] = arr[i];
    mp[arr[i]]++;
  }
  vector<unsigned long long> ans;
  solve(0, ans, mp);
  pause();
  return 0;
}
