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

inline int min(const int a, const int b) {return (a < b ? a : b);}

constexpr int MAX_LENGTH = 50000;

int tab[MAX_LENGTH];

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int length;
	std::cin >> length;

	for(int i = 0; i < length; ++i)
		std::cin >> tab[i];

	int result = 1<<30;
	for(int is_inc = 0, cur_result = 0; is_inc < 2; ++is_inc, result = min(result, cur_result), cur_result = 0)
		for(int i = 1; i < length; ++i)
			if((i^is_inc)&1 ? tab[i-1] >= tab[i] : tab[i-1] <= tab[i])
				++i, ++cur_result;

	std::cout << result << '\n';

	return 0;
}