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
#include <iostream>
using namespace std;

const int N = 50001;
int n, a[N], pom[N], ans1, ans2;
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>a[i];
		pom[i] = a[i];
	}
	
	for (int i=1; i<n; i++){
		if (i&1){
			if (pom[i]>=pom[i-1]){
				pom[i] = (int)(-1e9);
				ans1++;
			}
		}
		else{
			if (pom[i]<=pom[i-1]){
				pom[i] = (int)(1e9);
				ans1++;
			}
		}
	}
	
	for (int i=1; i<n; i++){
		if (i&1){
			if (a[i]<=a[i-1]){
				a[i] = (int)(1e9);
				ans2++;
			}
		}
		else{
			if (a[i]>=a[i-1]){
				a[i] = (int)(-1e9);
				ans2++;
			}
		}
	}
	cout<<min(ans1, ans2);
}