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
#include <cstdio>

using namespace std;

int findMin(int n, int* w, bool odd)
{
	
	int res = 0, wp = odd ? -10000001 : 10000001;

	for (int i = 1; i <= n; i++)
	{
		if ((odd && w[i] <= wp) || (!odd && w[i] >= wp))
		{
			wp = odd ? 10000001 : -10000001;
			res++;
		}
		else
		{
			wp = w[i];
		}
		odd = !odd;
	}

	return res;
}

int main()
{
	int n;
	int w[50001];

	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &w[i]);
	}

	int res1 = findMin(n, w, true);
	int res2 = findMin(n, w, false);

	printf("%d", (res1 < res2) ? res1 : res2);
	
	return 0;
}