First of all, let's carry over all powers of two in the following way: if we have ai = aj</span>, i ≠ j, carry 1 to ai + 1</span>. Now as all of ai</span> are distinct, the answer is max(ai)</span> — cnt(ai)</span> + 1, where max(ai)</span> — maximal value of ai</span>,cnt(ai)</span> — size of a