#agc040e. [agc040_e]Prefix Suffix Addition
[agc040_e]Prefix Suffix Addition
Problem Statement
Snuke has a sequence of integers . Initially, all the elements are .
He can do the following two kinds of operations any number of times in any order:
- Operation : choose an integer () and a non-decreasing sequence of non-negative integers . Then, for each (), replace with .
- Operation : choose an integer () and a non-increasing sequence of non-negative integers . Then, for each (), replace with .
His objective is to have for all . Find the minimum number of operations required to achieve it.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum number of operations required to achieve Snuke's objective.
Sample Input 1
5
1 2 1 2 1
Sample Output 1
3
One way to achieve the objective in three operations is shown below. The objective cannot be achieved in less than three operations.
- Do Operation and choose . Now we have .
- Do Operation and choose . Now we have .
- Do Operation and choose . Now we have .
Sample Input 2
5
2 1 2 1 2
Sample Output 2
2
Sample Input 3
15
541962451 761940280 182215520 378290929 211514670 802103642 28942109 641621418 380343684 526398645 81993818 14709769 139483158 444795625 40343083
Sample Output 3
7