beecrowd | 2243

Isosceles

By Maratona de Programação da SBC 2016 BR Brazil

Timelimit: 1

The brothers Sergio and Luiz were playing with wooden cubes and wanted to build a wall, which ended up being incomplete, with the columns having different heights, as in this figure.

They decided now that the game would remove cubes, always from top to bottom in columns so that the end was left only an isosceles triangle cubes. They can only take small cubes of the wall, without replacing in another column, and the triangles have to be complete. The figure below illustrates the top five isosceles triangles, cubes, the kind they want, with heights 1, 2, 3, 4 and 5 respectively.

Given the sequence of heights of the wall columns, your program should help Sergio Luiz and figure out what is the maximum height that the triangle could be the end. In the first figure wall 30 columns of cubes, the highest triangle can have a height equal to seven.

Input

The first line of input contains an integer N, 1 ≤ N ≤ 50000, representing the number of the wall columns. The second line contains N integers Ai, 1 ≤ AiN, for 1 ≤ iN, indicating the heights of each column.

Output

Your program should produce a single line with an integer M, representing the maximum height that a triangle could be the end.

Input Samples Output Samples

16
5 6 5 8 9 10 5 8 9 5 7 9 9 9 6 3

6

8
5 1 1 1 1 1 1 3

1