#P51431. [JOI 2021 Final] Growing Vegetables is Fun 4

[JOI 2021 Final] Growing Vegetables is Fun 4

Description

Bitaro likes gardening. He is now growing plants called Biba-herbs in the garden. There are NN Biba-herbs in the garden, planted in a line from the west to the east. The Biba-herbs are numbered from 11 to NN from the west to the east. Now, the height of the Biba-herb ii (1iN1 \leq i \leq N) is AiA_i.

Due to the breed improvement, if Bitaro waters a Biba-herb once, then its height increases by 11. Since he wants to decorate the garden, he will water the Biba-herbs several times so that the following condition is satisfied.

  • After Bitaro finishes watering, let BiB_i be the height of the Biba-herb ii. Then, there exists an integer kk (1kN1 \leq k \leq N) such that Bj<Bj+1B_j < B_{j+1} holds for every 1jk11 \leq j \leq k − 1, and Bj>Bj+1B_j > B_{j+1} holds for every kjN1k \leq j \leq N − 1.

However, Bitaro is not good at watering. When he waters Biba-herbs, he can only water consecutive Bibaherbs in an interval. In other words, he chooses integers LL and RR (1LRN1 \leq L \leq R \leq N) and waters the Biba-herbs L,L+1,,RL, L + 1, \ldots , R.

Bitaro wants to minimize the number of times of watering.

Write a program which, given the number of Biba-herbs and their current heights, calculates the minimum number of times of watering so that the above condition is satisfied.

Input

Read the following data from the standard input. Given values are all integers.

NN
A1ANA_1 \ldots A_N

Output

Write one line to the standard output. The output should contain the minimum number of times of watering.

Sample 1

5
3 2 2 3 1
3

The condition is satisfied if Bitaro waters the Biba-herbs three times as follows.

  • Let L=2L = 2 and R=5R = 5. Then Bitaro waters the Biba-herbs 2,3,4,52, 3, 4, 5. The heights of the Biba-herbs become 3,3,3,4,23, 3, 3, 4, 2 from the west.
  • Let L=2L = 2 and R=3R = 3. Then Bitaro waters the Biba-herbs 2,32, 3. The heights of the Biba-herbs become 3,4,4,4,23, 4, 4, 4, 2 from the west.
  • Let L=3L = 3 and R=3R = 3. Then Bitaro waters the Biba-herb 33. The heights of the Biba-herbs become 3,4,5,4,23, 4, 5, 4, 2 from the west.

It is impossible to satisfy the condition if Bitaro waters the Biba-herbs less than three times. Hence the minimum number of times of watering is 33.

5
9 7 5 3 1
0

Since the condition is already satisfied, the minimum number of times of watering is 00.

2
2021 2021
1

The condition is satisfied if Bitaro waters the Biba-herb 11 by choosing L=1L = 1 and R=1R = 1, or he waters the Biba-herb 22 by choosing L=2L = 2 and R=2R = 2.

8
12 2 34 85 4 91 29 85
93

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5.
  • 1Ai1091 \leq A_i \leq 10^9 (1iN1 \leq i \leq N).

Subtasks

  1. (4040 points) N2000N \leq 2000.
  2. (6060 points) No additional constraints.