PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000192. Cộng theo lũy thừa hai (Powered Addition)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Cộng theo lũy thừa hai (Powered Addition)

Powered Addition

Source: Codeforces

Version: Phuoc Hung OJ (single-case adaptation where applicable)

Problem Statement

Given integers a1,…,ana_1,\ldots,a_n, at second x≥1x\ge1 you may choose any set of indices and add exactly 2x−12^{x-1} to each selected value; choosing no indices is allowed. Find the minimum number of seconds required to make the array nondecreasing.

Input

The first line contains nn. The second contains nn integers aia_i (possibly negative).

Output

Print the minimum number of seconds.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le 15; −100≤ai≤100-100\le a_i\le 100 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000; −1000000≤ai≤1000000-1000000\le a_i\le 1000000 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; −1000000000≤ai≤1000000000-1000000000\le a_i\le 1000000000 for every 1≤i≤n1\le i\le n.

Examples

Example 1

Input

4
1 7 6 5

Output

2

Explanation

After the prefix maximum 7, the last two positions need increases of at least 1 and 2. Two seconds allow any increase from 0 to 3.

Example 2

Input

2
0 -4

Output

3

Explanation

The second element needs an increase of 4. Two seconds provide at most 1+2=3, but three seconds permit an increase of 4.