#include <iostream>
#include <set>
#include <stack>
using namespace std;
const int N = 510;
int main() {
int n, a;
while (cin >> n && n) { // 注意 while 处理多个 case
set<int> cover;
stack<int> stk;
while (n --) {
cin >> a;
if (cover.count(a)) continue;
stk.push(a);
while (a != 1) {
if (a & 1) a = a * 3 + 1 >> 1;
else a >>= 1;
cover.insert(a);
}
}
while (stk.size()) {
a = stk.top();
stk.pop();
if (!cover.count(a)) cout << a << " ";
}
puts("");
}
return 0;
}
// 64 位输出请用 printf("%lld")

京公网安备 11010502036488号