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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	vector<int> v1;
	int n, tempA;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tempA;
		v1.push_back(tempA);
	}

	//dla pierwszy rosnacy
	bool czyTerazRosnie = true;
	int couter1 = 0;
	vector<int> v2 = v1;
	for (int i = 0; i < v2.size() - 1; i++) {
		if (czyTerazRosnie) {
			if (!(v2[i] < v2[i + 1])) {
				v2[i + 1] = 1000000;
				couter1++;
			}
		}
		else {
			if (!(v2[i] > v2[i + 1])) {
				v2[i + 1] = -1000000;
				couter1++;
			}
		}
		czyTerazRosnie = !czyTerazRosnie;
	}
	//cout << "pierwszy rosnie = " << couter1 << endl;
	//for (auto i : v2) {
	//	cout << i << " ";
	//}
	//cout << endl;


	//dla pierwszy malejacy
	czyTerazRosnie = false;
	int couter2 = 0;
	v2 = v1;
	for (int i = 0; i < v2.size() - 1; i++) {
		if (czyTerazRosnie) {
			if (!(v2[i] < v2[i + 1])) {
				v2[i + 1] = 1000000;
				couter2++;
			}
		}
		else {
			if (!(v2[i] > v2[i + 1])) {
				v2[i + 1] = -1000000;
				couter2++;
			}
		}
		czyTerazRosnie = !czyTerazRosnie;
	}

	
	//cout << "pierwszy maleje = " << couter2 << endl;
	//for (auto i : v2) {
	//	cout << i << " ";
	//}
	//cout << endl;

	if (couter1 < couter2) cout << couter1;
	else cout << couter2;


}