#P3147. Bessie's Merging Game
Bessie's Merging Game
Bessie's Merging Game
Bessie loves downloading games to play on her cell phone, even though the small touch screen is rather cumbersome for her large hooves. In her current game, she is presented with a sequence of N positive integers. The game rules are as follows:
- The sequence has N numbers, where $$2 \leq N \leq 262144$$.
- Each number is in the range $$1 \ldots 40$$.
- In one move, Bessie can take two adjacent numbers that are equal and replace them with a single number which is one greater. For example, two adjacent 7's can be replaced by a single 8.
The objective is to maximize the value of the largest number present in the sequence after performing a sequence of such moves. Help Bessie achieve the highest possible score!
inputFormat
The first line contains a single integer N, representing the length of the sequence. The second line contains N space-separated integers, each in the range from 1 to 40.
outputFormat
Output a single integer: the maximum number that can appear in the sequence after performing an optimal sequence of moves.
sample
3
1 1 1
2
</p>