IOI Zoo is famous for giraffes. There are
Mr. APIO is the curator of IOI Zoo. He is worrying about the ratings of IOI Zoo in reviews. IOI Zoo receives low ratings for the reason that "the visual quality of the giraffes is bad." Precisely, when a visitor takes a picture of giraffes, the visitor chooses integers
- There is a giraffe in the picture which is taller than the giraffes in both ends of the picture. In other words, there is an integer
satisfying . - There is a giraffe in the picture which is shorter than the giraffes in both ends of the picture. In other words, there is an integer
satisfying .
Mr. APIO will arrange the positions of the giraffes so that the visual quality of the giraffes does not become bad for any choice of
Given information of the current positions of the giraffes, write a program which calculates the minimum number of giraffes which are moved. Since Mr. APIO arranged the current positions of the giraffes at random, you may assume that the values
Input Specification
Read the following data from the standard input. Given values are all integers.
Output Specification
Write one line to the standard output. The output should contain the minimum number of giraffes which are moved.
Constraints
. . .- The values
are generated at random (See Generation of Input Data for details).
Subtasks
- (10 points)
. - (22 points)
. - (27 points)
. - (41 points) No additional constraints.
Generation of Input Data
In this task, except for Sample Input, there are
- First, choose
satisfying the constraints of each subtask. - Then, among the
permutations satisfying the constraints, choose one permutation at random with equal probability and generate .
Sample Input 1
6
5 4 6 1 3 2
Sample Output 1
2
Explanation for Sample 1
There are
- The giraffe in the cage
is taller than the leftmost giraffe (= cage ) in the picture and the rightmost giraffe (= cage ) in the picture. - The giraffe in the cage
is shorter than the leftmost giraffe (= cage ) in the picture and the rightmost giraffe (= cage ) in the picture.
If Mr. APIO moves the giraffe
This sample input satisfies the constraints of all the subtasks.
Sample Input 2
4
4 1 3 2
Sample Output 2
0
Explanation for Sample 2
There are
This sample input satisfies the constraints of all the subtasks.
Sample Input 3
7
3 1 6 7 4 2 5
Sample Output 3
2
Explanation for Sample 3
For example, if Mr. APIO moves the giraffes so that the giraffes
This sample input satisfies the constraints of all the subtasks.
Sample Input 4
13
8 5 6 13 4 2 11 3 9 1 10 7 12
Sample Output 4
6
This sample input satisfies the constraints of Subtasks 2, 3, 4.
Comments