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

int main(){
	int n, a, b, er1 = 0, er2 = 0;
	bool fl1 = true, fl2 = true, ofl1, ofl2;
	std::cin >> n >> a;
	for(int i = 1; i < n; i++){
		std::cin >> b;
		ofl1 = fl1;
		ofl2 = fl2;
		if(b >= a){
			if( i % 2 == 1 && fl1 ){
				er1++;
				fl1 = false;
			}else if( i % 2 == 0 && fl2 ){
				er2++;
				fl2 = false;
			}
		}
		if(a >= b){
			if( i % 2 == 0 && fl1 ){
				er1++;
				fl1 = false;
			}else if( i % 2 == 1 && fl2 ){
				er2++;
				fl2 = false;
			}
		}
		if(!ofl1) fl1 = true;
		if(!ofl2) fl2 = true;
		a = b;
	}
	std::cout << (er1 < er2 ? er1 : er2) << "\n";
	return 0;
}