Hide

Problem B
CHACTL

Seasoned competitive programmers are quite familiar with KACTL, a very good algorithm repository designed for use in the ICPC. The problem setters of Chalmers Challenge 2021 count themselves to this group, but have in preparation for this contest noticed two serious flaws with it.

First, it turns out the K in KACTL stands for KTH! This is clearly unacceptable and needs to be remedied. Second, the $26$-page limit prevents the repository from achieving true greatness. Hence, we introduce CHACTL: Chalmers Competition Template Library with no less than $2^{26}$ pages. This is plenty space for all distributed quadratic SIMD, assault and battery of floating-point numbers and cryptic guides to crossword solving you could ever wish for!

During development, Dragos came up to us and said that our users need a proper navigation system to handle the scale and intensity of CHACTL. He recommended buttons that traverse the pages a power of two at a time. We implemented this, so from page $i$ you can go to page $i + 2^ t$ or $i - 2^ t$ in a single step for any $t$.

Although there are no pages with negative numbers, or with arbitrarily large numbers, the navigation system supports jumping to such pages as it might reduce the number of jumps needed.

We want to test this by looking up algorithms on pages $P_0, P_1, \ldots P_{N-1}$, in that order. CHACTL’s pages are numbered from $0$ to $2^{26} - 1$. Starting from page $0$, what is the smallest number of jumps required to look up all the algorithms?

Input

The first line contains one integer $N$, $1 \le N \le 10^5$. The following $N$ lines each contain one integer. Line $i$ contains $P_ i$, $0 \le P_ i < 2^{26}$.

Output

Output the smallest number of jumps required to look up the algorithms.

Sample Input 1 Sample Output 1
1
63
2
Sample Input 2 Sample Output 2
5
0
1
23
1
7
9
Sample Input 3 Sample Output 3
12
8137
16777170
127
131121
4194378
221
2105
524249
65616
131152
131118
48
46

Please log in to submit a solution to this problem

Log in