Tetris Remastered

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Mila likes to play Tetris. Today she learnt about a new game that is similar to Tetris. The new game has an infinite rectangular field with the bottom and width equal to nn, divided into cells of size 1×11 \times 1. Unlike real Tetris in this game horizontal pieces with height 11 and width xx consisting of xx cells --- of size 1×x1 \times x, are used. Before the next piece starts to fall, a player can choose it's size xx as any integer between 11 and nn, inclusive. Pieces can't be rotated, but they can be moved left or right. A piece falls until it reaches an occupied cell under it or the bottom of the field.

Mile doesn't like to leave empty cells under the pieces. Her goal is to fill lower rows of the field in the way that all occupied cells form a rectangle of width nn.

You are given a field state: a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n, where a_ia\_i --- the number of occupied cells in the ii-th column of the field. In the given field no empty cell is under the occupied one. For example, if sequence aa is 3,2,4,2,2,43, 2, 4, 2, 2, 4, the field looks like this:

Find the minimum number of pieces Mila needs to play to occupy the lower rows of the field forming a rectangle of width nn.

입력

The first line contains a single integer nn --- the width of the field (1n21051 \le n \le 2 \cdot 10^5).

The second line contains nn integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n --- the number of occupied cells in each column of the field (0a_i1090 \le a\_i \le 10^9).

At least on of the a_ia\_i is strictly greater than 00.

출력

Print a single integer: the minimum number of pieces Mila will need to build a rectangle of width nn.

힌트

In the example Mile can use the following four pieces: