atcoder#ARC152C. [ARC152C] Pivot

[ARC152C] Pivot

Score : 600600 points

Problem Statement

We have a sequence of NN terms: a1,a2,,aNa_1,a_2,\ldots,a_N. You can perform the following operation on this sequence any number of times (possibly zero).

  • Choose a term of the sequence at that point, and let ss be its value. Then, for every 1iN1\leq i\leq N, replace aia_i with 2sai2s-a_i. However, this operation may not be performed in a way that produces a term with a negative value.

You want to make the greatest value among the terms of the sequence as small as possible. What will this value be after an optimal sequence of operations for this objective?

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1a1<a2<<aN1091 \leq a_1 < a_2 < \ldots < a_N \leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

a1a_1 a2a_2 \ldots aNa_N

Output

Print the answer.

3
1 3 6
5

If you perform the operation with s=3s=3, the sequence becomes (5,3,0)(5,3,0). The greatest value here is 55. Under the condition that there may not be a term with a negative value, the greatest value among the terms of the sequence cannot be made smaller, so you should print 55.

5
400 500 600 700 800
400

To obtain this result, perform the operation once with s=400s=400, or perform it with s=500s=500 and then with s=300s=300, for instance.