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
#include <iostream>
#include <vector>

int maxn = 1e6+5;
int n;

int getResult(std::vector<int> a) {
	int r = 0;
	for (int i = 1 ; i < n ; i++) {
		if (i % 2 == 0 && a[i] >= a[i-1]) {
			a[i] = -maxn;
			r++;
		}
		if (i % 2 == 1 && a[i] <= a[i-1]) {
			a[i] = maxn;
			r++;
		}
	}
	return r;
}

int main() {
	std::cin >> n;
	std::vector<int> a(n);
	for (int i = 0 ; i < n ; i++) {
		std::cin >> a[i];
	}
	int r1 = getResult(a);
	for (int i = 0 ; i < n ; i++) {
		a[i] = -a[i];
	}
	int r2 = getResult(a);
	std::cout << std::min(r1, r2);
}