import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        // 获取数据
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = br.readLine().charAt(0) - '0';
        String[] strs = br.readLine().split(" ");
        ArrayList<Integer> list = new ArrayList<>();
        ArrayList<Integer> result = new ArrayList<>();

        // 处理数据
        for(int i = 0 ; i < strs.length ; i++) {
            int num = Integer.parseInt(strs[i]);
            if(n == 1) {    // 特殊情况:只有一个数
                System.out.println(num);
                return;
            }
            list.add(1);
            while(num != 1) {
                if(num % 2 == 0) {
                    num /= 2;
                } else {
                    num = (3 * num + 1) / 2;
                }
                list.add(num);
            }
        }
        // 查找list中不曾出现过的数
        for(int i = 0 ; i < strs.length ; i++) {
            int num = Integer.parseInt(strs[i]);
            if(!list.contains(num)) {
                result.add(num);
            }
        }

        // 降序输出
        Collections.sort(result);
        Collections.reverse(result);
        for(int i = 0 ; i < result.size() ; i++) {
            if(i == result.size() - 1) {
                System.out.print(result.get(i));
            } else {
                System.out.print(result.get(i) + " ");
            }
        }
    }
}