1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<cstdio>
#include<vector>
int main(){

int n, act, prev;
int eq=0;
int max_p = 1000001;
int min_p = -1000001;
int dec = 0;
int inc = 0;

scanf("%d", &n);
scanf("%d", &prev);
int prev_inc = prev;
int prev_dec = prev; 
for(int i=0; i<n-1; i++){
    scanf("%d", &act);
    if ( i % 2 == 0){
        if(act <= prev_inc){
             prev_inc = max_p;
             inc++;
         }
         else
             prev_inc = act;
             
        if(act >= prev_dec){
             prev_dec = min_p;
             dec++;
         }
         else
             prev_dec = act;             
    }
    else{
	if(act >= prev_inc){
	     prev_inc = min_p;
	     inc++;
	 }
	 else
	     prev_inc = act;
	if(act <= prev_dec){
	     prev_dec = max_p;
	     dec++;
	 }
	 else
	     prev_dec = act;
    }
        
}
if ( inc > dec)
    printf("%d", dec);
else
    printf("%d", inc);
return 0;
}