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
#include <bits/stdc++.h>
using namespace std;
#pragma GCC maksuje_zadania_na_essie("pot200");

constexpr int MAX_N = 1e6 + 1;
int inp[MAX_N], n;

int try_option(int parity) {

	vector<int> arr(inp, inp+n);
	int res = 0;

	for(int i = 1; i < n; i++) {
		if((i&1) == parity && arr[i] >= arr[i-1]) {
			arr[i] = -1e9;
			res++;
		}
		else if((i&1) != parity && arr[i] <= arr[i-1]) {
			arr[i] = 1e9;
			res++;
		}
	}

	return res;

}

int main() {

    cin.tie(0)->sync_with_stdio(false);
    cin >> n;

	for(int i = 0; i < n; i++) {
		cin >> inp[i];
	}

	int res = min(try_option(1), try_option(0));
	cout << res << '\n';

}