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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	vector<bool> v1, v2;
	v1.resize(n-1);
	v2.resize(n-1);
	int a0, a1;
	cin>>a0;
	for(int i=0; i<n-2; i+=2)
	{
		cin>>a1;
		v1[i] = (a1>a0);
		v2[i] = (a1<a0);
		cin>>a0;
		v1[i+1] = (a1>a0);
		v2[i+1] = (a1<a0);
	}
	if(n%2==0)
	{
		cin>>a1;
		v1[n-2] = (a1>a0);
		v2[n-2] = (a1<a0);
	}
	int sol1 = 0, sol2 = 0;
	for(int i=0; i<n-2; i++)
	{
		v1[i+1] = v1[i+1] || !v1[i];
		sol1 += !v1[i];
		v2[i+1] = v2[i+1] || !v2[i];
		sol2 += !v2[i];
	}
	sol1 += !v1[n-2];
	sol2 += !v2[n-2];
	cout<<(sol1<sol2?sol1:sol2);
	return 0;
}