atcoder#AGC029C. [AGC029C] Lexicographic constraints

[AGC029C] Lexicographic constraints

Score : 700700 points

Problem Statement

There are NN strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S1holdslexicographically,whereS_1 holds lexicographically, where S_iisthe is the i$-th string from the left.

At least how many different characters are contained in S1,S2,...,SNS_1,S_2,...,S_N, if the length of SiS_i is known to be AiA_i?

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • AiA_i is an integer.

Note

The strings do not necessarily consist of English alphabet; there can be arbitrarily many different characters (and the lexicographic order is defined for those characters).

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 ...... ANA_N

Output

Print the minimum possible number of different characters contained in the strings.

3
3 2 1
2

The number of different characters contained in S1,S2,...,SNS_1,S_2,...,S_N would be 33 when, for example, S1=S_1=abc, S2=S_2=bb and S3=S_3=c.

However, if we choose the strings properly, the number of different characters can be 22.

5
2 3 2 1 2
2