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
#include <stdio.h>

#define MAX_VAL 1000000000;

int t1[100000];
int t2[100000];

int calc(int * t, int n, int grad){
	int res = 0;
	for(int i = 1; i < n; ++i){
		if (grad == 1){
			if (t[i - 1] >= t[i]){
				++res;
				t[i] = MAX_VAL;
			}
		} else {
			if (t[i - 1] <= t[i]){
				++res;
				t[i] = -MAX_VAL;
			}
		}
		grad = -grad;
	}
	return res;
}

int min(int a, int b){
	return a > b ? b : a;
}

int main(){
	int n;
	int r1 = 0;
	int r2 = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		scanf("%d", &t1[i]);
		t2[i] = t1[i];
	}
	r1 = calc(t1, n, 1);
	r2 = calc(t2, n, -1);
	printf("%d\n", min(r1,r2));
	return 0;
}