loj#P3468. 「JOI 2021 Final」有趣的家庭菜园 4

「JOI 2021 Final」有趣的家庭菜园 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.

5
3 2 2 3 1
3
5
9 7 5 3 1
0
2
2021 2021
1
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.