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
48
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 5e4 + 5;

int a[MAXN];

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
		scanf("%d",&a[i]);
	
	const int lim = 1e9;
	
	int ans = n;
	for(int rn=0; rn<=1; ++rn)
	{
		int lst = lim, cur = 0;
		for(int i=1; i<=n; ++i)
		{
			if(i % 2 == 1)
			{
				if(a[i] < lst)
					lst = a[i];
				else
					lst = -lim, ++cur;
			}
			else
			{
				if(a[i] > lst)
					lst = a[i];
				else
					lst = lim, ++cur;
			}
		}
		
		ans = min(ans, cur);
		
		for(int i=1; i<=n; ++i)
			a[i] *= -1;
	}
	
	printf("%d\n",ans);
	return 0;
}