#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
const long double pi = acos(-1.0);
const int_fast64_t mod = 1e9 + 7;
struct pr {
  int_fast64_t x = 0;
  int_fast64_t y = 0;
  int_fast64_t dst = 0;
  pr() {}
  pr(int_fast64_t x, int_fast64_t y, int_fast64_t dst) : x(x), y(y), dst(dst) {}
  inline bool operator<(const pr& cmp2) const {
    if (dst != cmp2.dst) return dst < cmp2.dst;
    if (x != cmp2.x) return x < cmp2.x;
    return y < cmp2.y;
  }
  inline bool operator==(const pr& cmp2) const {
    return (cmp2.dst == dst) && (cmp2.x == x) && (cmp2.y == y);
  }
  inline bool operator>(const pr& cmp2) const {
    if (dst != cmp2.dst) return dst > cmp2.dst;
    if (x != cmp2.x) return x > cmp2.x;
    return y > cmp2.y;
  }
};
struct point {
  int_fast64_t x = 0;
  int_fast64_t y = 0;
  point() {}
  point(int_fast64_t x, int_fast64_t y) : x(x), y(y) {}
  inline bool operator<(const point& cmp2) const {
    if (cmp2.x != x) return cmp2.x < x;
    return cmp2.y < y;
  }
  inline bool operator==(const point& cmp2) const {
    return (cmp2.x == x) && (cmp2.y == y);
  }
  inline bool operator>(const point& cmp2) const {
    if (cmp2.x != x) return cmp2.x > x;
    return cmp2.y > y;
  }
};
namespace std {
template <typename T>
struct hash<vector<T> > {
  size_t operator()(const vector<T>& k) const {
    size_t ret = 0xf3ee477d;
    for (size_t i = 0; i != k.size(); ++i) ret ^= hash(hash(k[i]) + i);
    return ret;
  }
};
template <>
struct hash<pr> {
  size_t operator()(const pr& cmp1) const {
    return (hash<int_fast64_t>()(cmp1.x)) ^ (hash<int_fast64_t>()(cmp1.y)) ^
           (hash<int_fast64_t>()(cmp1.dst));
  }
};
template <>
struct hash<point> {
  size_t operator()(const point& cmp1) const {
    return (hash<int_fast64_t>()(cmp1.x)) ^ (hash<int_fast64_t>()(cmp1.y));
  }
};
}  // namespace std
inline bool spoint(const point& cmp1, const point& cmp2) {
  if (cmp1.x != cmp2.x) return cmp1.x < cmp2.x;
  return cmp1.y < cmp2.y;
}
inline bool spr(const pr& cmp1, const pr& cmp2) {
  if (cmp1.dst != cmp2.dst) return cmp1.dst < cmp2.dst;
  if (cmp1.x != cmp2.x) return cmp1.x < cmp2.x;
  return cmp1.y < cmp2.y;
}
void sub() {}
int_fast64_t vis[105];
void solve() {
  int_fast64_t n;
  cin >> n;
  vector<int_fast64_t> arr(n);
  for (int_fast32_t i = (int_fast32_t)0; i < (int_fast32_t)n; ++i)
    cin >> arr[i];
  for (int_fast32_t start = (int_fast32_t)0; start < (int_fast32_t)n; ++start) {
    vector<int_fast64_t> path;
    memset(vis, 0, sizeof vis);
    vis[start] = 1;
    int_fast64_t cur = arr[start];
    int_fast64_t can = 1;
    for (int_fast32_t ii = (int_fast32_t)0; ii < (int_fast32_t)n - 1; ++ii) {
      path.push_back(cur);
      if (cur > 1500000000000000000) {
        if (cur % 3) {
          can = 0;
          break;
        }
        int_fast64_t cann = 0;
        for (int_fast32_t i = (int_fast32_t)0; i < (int_fast32_t)n; ++i) {
          if (arr[i] == cur / 3 && vis[i] == 0) {
            vis[i] = 1;
            cann = 1;
            break;
          }
        }
        if (!cann) {
          can = 0;
          break;
        }
        cur /= 3;
        continue;
      }
      int_fast64_t cann = 0;
      for (int_fast32_t i = (int_fast32_t)0; i < (int_fast32_t)n; ++i) {
        if (arr[i] == cur * 2 && vis[i] == 0) {
          vis[i] = 1;
          cann = 1;
          break;
        }
      }
      if (cann) {
        cur *= 2;
        continue;
      }
      if (cur % 3 == 0) {
        int_fast64_t cann = 0;
        for (int_fast32_t i = (int_fast32_t)0; i < (int_fast32_t)n; ++i) {
          if (arr[i] == cur / 3 && vis[i] == 0) {
            vis[i] = 1;
            cann = 1;
            break;
          }
        }
        if (cann) {
          cur /= 3;
          continue;
        }
      }
      can = 0;
      break;
    }
    if (can) {
      for (auto i : path) {
        cout << i << ' ';
      }
      cout << cur << endl;
      return;
    }
  }
}
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
}
int main() {
  init();
  solve();
  return 0;
}
