NOIP '04 P3 - Chorus Formation

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type

N students stand in a row, and the music teacher asks N-K students to leave so that the remaining K students form a chorus formation.

The chorus formation refers to such a formation: Suppose the K students left are numbered 1, 2, \dots, K from left to right, and their heights are T_1, T_2, \dots, T_K respectively, then their heights satisfy T_1 < \dots < T_i > T_{i+1} > \dots > T_K (1 \le i \le K).

Your task is, given the heights of all N students, calculate the minimum number of students who need to leave, so that the remaining students can form a chorus formation.

Input Specification

The first line of the input consists of an integer N (2 \le N \le 100) denoting the number of students. The second line consists of n integers separated by a single space denoting the height of the i-th student. The heights satisfy 130 \le T_i \le 230.

Output Specification

Output the minimum number of students that should leave to form a chorus formation.

Sample Input

8
186 186 150 200 160 130 197 220

Sample Output

4

Constraints

For 50\% of test cases, n \le 20.

For all test cases, n \le 100.


Comments

There are no comments at the moment.