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
55
56
#include <iostream>
#include <vector>
#include <set>
#include <climits>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;	cin >> n;
	int wyn = 0, c1 = 0, c2 = 0;
	vector<int> vi(n);
	for (int i = 0; i < n; i++) {
		cin >> vi[i];
	}
	vector<int> vi2 = vi;
	//ros
	for (int i = 0; i < n - 1; i++) {
		if (i % 2 == 0) {
			if (vi[i + 1] >= vi[i]) {
				vi[i + 1] = -1000001;
				c1++;
			}
		}
		else {
			if (vi[i + 1] <= vi[i]) {
				vi[i + 1] = 1000001;
				c1++;
			}
		}
	}
	vi = vi2;
	//mal
	for (int i = 0; i < n - 1; i++) {
		if (i % 2 == 0) {
			if (vi[i + 1] <= vi[i]) {
				vi[i+1] = 1000001; 
				c2++;
			}
		}
		else {
			if (vi[i + 1] >= vi[i]) {
				vi[i + 1] = -1000001;
				c2++;
			}
		}
	}
	cout << min(c1, c2);

	return 0;
}