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
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1000007;

int n;
int t[MAXN];

int solve(int asc) {
	int res = 0;
	
	for (int i=1; i<n; i++) {
		if (t[i] > t[i-1] && (i % 2 == asc))
			continue;
		if (t[i] < t[i-1] && (i % 2 != asc))
			continue;
		
		res++;
		i++;
	}
	
	return res;
}

int main() {
	scanf("%d", &n);
	
	for (int i=0; i<n; i++)
		scanf("%d", &t[i]);
	
	int w1 = solve(0);
	int w2 = solve(1);
	
	printf("%d\n", std::min(w1, w2));
}