1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;
int solve(vector<int>a)
{
	int r=0;
	for (int i=1; i<(int)a.size(); i++)
	{
		if ((i&1) && a[i]<=a[i-1]) a[i]=1e9, r++;
		else if (!(i&1) && a[i]>=a[i-1]) a[i]=-1e9, r++;
	}
	return r;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin>>n;
	vector<int>a(n);
	for (auto &i : a) cin>>i;
	int ans=solve(a);
	a.insert(a.begin(), -1e9);
	ans=min(ans, solve(a));
	cout<<ans<<"\n";
}