#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int n = 0,i=0,count =0;
int contrast1[10000] = {1,2}; //如果数组长度小了运行时可能出现错误
cin >> n;
int* num = new int[n];
int* ctrlc = new int[n];
for (int i = 0; i < n; i++) {
cin >> num[i];
ctrlc[i] = num[i];
}
for (int j = 0; j < n; j++) {
while (num[j] != 1) {
if (num[j] % 2 == 1) {
num[j] = (num[j] * 3 + 1) / 2;
}
else {
num[j] = num[j] / 2;
}
contrast1[i++] = num[j];
}
}
int* contrast = new int[i];
for (int j = 0; j < i; j++) {
contrast[j] = contrast1[j];
}
for (int j = 0; j < i; j++) {
for (int z = 0; z < n; z++) {
if (ctrlc[z] == contrast1[j]) {
ctrlc[z] = contrast[j]= 0;
count++;
}
}
}
int* result = new int[n-count];
int m = 0;
for (int i = 0; i < n; i++) {
if (ctrlc[i] != 0) {
result[m++] = ctrlc[i];
}
}
sort(result, result + n-count, greater<int>());//内置类型的由大到小排序
for (int s = 0; s < n - count-1; s++)
cout << result[s] << " ";
cout<<result[n-count-1];
return 0;
}