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

using namespace std;

const int MAX_N = 50007;
int pliszka_up[MAX_N], pliszka_down[MAX_N];
int beg=0, res_up=0, res_down=0;
int n;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=0; i<n; ++i){
		int tmp;
		cin>>tmp;
		pliszka_down[i] = tmp;
		pliszka_up[i] = tmp;
	}
	beg = pliszka_down[0];
	for(int i=1; i<n; ++i){
		if(i%2==1){
			if(pliszka_up[i]<=pliszka_up[i-1]){
				pliszka_up[i] = 500000000;
				++res_up;
			}
			if(pliszka_down[i]>=pliszka_down[i-1]){
				pliszka_down[i] = -500000000;
				++res_down;
			}
		}
		else {
			if(pliszka_up[i]>=pliszka_up[i-1]){
				pliszka_up[i] = -500000000;
				++res_up;
			}
			if(pliszka_down[i]<=pliszka_down[i-1]){
				pliszka_down[i] = 500000000;
				++res_down;
			}
		}
	}
	cout<<min(res_down,res_up)<<'\n';
	return 0;
}