//用一个一维数组去存储输入的数据 然后用这个一维数组映射的二维数组去存储对应位置是否有包含关系 例如第i行所代表的输入数据包含了第i行第j列的元素 将i j 位置置为1 表是第j列所代表的元素已被第i行所代表的元素包含
import java.util.*;
class Main {
public static void main(String []args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[] temp = new int[n];
int[][] arg = new int[n][n];
int[] result = new int[n];
int count = 0;
int num = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
arg[i][j] = 0;
}
}
for(int i = 0; i < n; i++){
temp[i] = scan.nextInt();
}
for(int i = 0; i < n; i++){
int s = temp[i];
while(s != 1){
if(s % 2 == 0){
s /= 2;
}
else{
s = (3*s + 1) / 2;
}
for(int j = 0; j < n; j++){
if(s == temp[j]){
arg[i][j] = 1;
}
}
}
}
for(int j = 0; j < n; j++){
for(int i = 0; i < n; i++){
if(arg[i][j] == 1){
break;
}
if(i == n - 1){
result[num++] = temp[j];
}
}
}
Arrays.sort(result,0,num);
for(int i = num - 1; i >= 0; i--){
if(count != 0){
System.out.print(" ");
}
System.out.print(result[i]);
count++;
}
}
}