import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
static LinkedList<Integer> f(int [] nums) {
HashSet<Integer> set = new HashSet<>();
for (int x : nums) {
if (!set.contains(x)) {
while (x != 1) {
if (x % 2 == 0) {
x >>= 1;
} else {
x = (3 * x + 1) >> 1;
}
set.add(x);
}
}
}
LinkedList<Integer> ans = new LinkedList<>();
for (int x : nums) {
if (!set.contains(x))
ans.addFirst(x);
}
return ans;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = scanner.nextInt();
}
f(nums).forEach(x-> System.out.print(x + " "));
System.out.println();
}
}
}