n = int(input())
numbers = []
numbers_print = []
numbers_input = []
numbers_input[:] = input().split()
numbers_input = numbers_input[: n]
i = 0
for num in numbers_input:
num = int(num)
while num != 1:
if num % 2 == 1:
num = (num * 3 + 1) / 2
else:
num = num / 2
numbers.append(num)
numbers = list(set(numbers))
for num in numbers_input:
num = int(num)
flag = True
for number in numbers:
if num == number:
flag = False
break
if flag:
numbers_print.append(num)
numbers_print = sorted(numbers_print, reverse = True)
i = 0
while i < len(numbers_print):
if i != len(numbers_print) - 1:
print(numbers_print[i], end = ' ' )
else:
print(numbers_print[i])
i = i + 1