#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> a[200];   int n;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].second;       long long tmp = a[i].second;       while (tmp % 3 == 0) {         a[i].first--;         tmp /= 3;       }     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) cout << a[i].second <<    ;     return 0;   }   