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
57
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long

void solve(){
	ll n;
	cin >> n;
	vector<ll> temp(n, 0), lista(n-1, 0);
	for(auto &el: temp) cin >> el;
	for(ll i = 0; i < n-1; i++){
		if(temp[i] < temp[i+1]){
			lista[i] = 1;
		}
		else if(temp[i] > temp[i+1]){
			lista[i] = -1;
		}
	}
	ll jeden=0,dwa=0;
	ll indeks=-2,suma=0;
	for(int i = 0; i < n-1; i++){
		if((!(i&1) && lista[i] != -1) || (i&1 && lista[i] != 1)){
			if(indeks+1 == i && suma < 2){
				indeks = i;
				suma++;
			}
			else{
				jeden++;
				suma = 1;
				indeks = i;
			}
		}
	}
	for(int i = 0; i < n-1; i++){
		if((!(i&1) && lista[i] != 1) || (i&1 && lista[i] != -1)){
			if(indeks+1 == i && suma < 2){
				indeks = i;
				suma++;
			}
			else{
				dwa++;
				suma = 1;
				indeks = i;
			}
		}
	}
	cout << min(jeden,dwa) << endl;

}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
	
}