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
#include <bits/stdc++.h>
using namespace std;

const int inf=1e9;

int n;
vector <int> a[2];

inline int get_ans(bool b, int nr)
{
	int ans=0;
	for(int i=1; i<n; ++i)
	{
		if(b && a[nr][i]<=a[nr][i-1])
		{
			a[nr][i]=inf;
			++ans;
		}
		else if((!b) && a[nr][i]>=a[nr][i-1])
		{
			a[nr][i]=-inf;
			++ans;
		}
		b=!b;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin>>n;
	
	a[0].resize(n);
	a[1].resize(n);
	for(int i=0; i<n; ++i)
	{
		cin>>a[0][i];
		a[1][i]=a[0][i];
	}
	
	cout<<min(get_ans(0, 0), get_ans(1, 1))<<"\n";
	return 0;
}