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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
#include <iostream>

int n;
int* tab;

int c_wm = 0;
int c_mw = 0;
bool d_c_wm = 0;
bool d_c_mw = 0;

int main() {

	std::cin >> n;

	if (n < 3 || n > 50000)
		return -1;

	tab = new int[n];

	for (size_t i = 0; i < n; i++) {
		std::cin >> tab[i];
		if (tab[i] < -1000000 || tab[i] > 1000000)
			return -1;
	}

	for (size_t i = 1; i < n; i ++) {
		if (i % 2) {
			if (tab[i - 1] < tab[i]) {
				if (d_c_mw) {
					d_c_mw = 0;
				}
				else {
					d_c_mw = 1;
					c_mw++;
				}
				d_c_wm = 0;
			}
			else if (tab[i - 1] > tab[i]) {
				if (d_c_wm) {
					d_c_wm = 0;
				}
				else {
					d_c_wm = 1;
					c_wm++;
				}
				d_c_mw = 0;
			}
			else {
				if (d_c_mw) {
					d_c_mw = 0;
				}
				else if (d_c_wm) {
					d_c_wm = 0;
				}
				else {
					c_wm++;
					c_mw++;
					d_c_wm = 1;
				}
			}
		}
		else if (!(i % 2)) {
			if (tab[i - 1] > tab[i]) {
				if (d_c_mw) {
					d_c_mw = 0;
				}
				else {
					d_c_mw = 1;
					c_mw++;
				}
				d_c_wm = 0;
			}
			else if (tab[i - 1] < tab[i]) {
				if (d_c_wm) {
					d_c_wm = 0;
				}
				else {
					d_c_wm = 1;
					c_wm++;
				}
				d_c_mw = 0;
			}
			else {
				if (d_c_mw) {
					d_c_mw = 0;
				}
				else if (d_c_wm) {
					d_c_wm = 0;
				}
				else {
					c_wm++;
					c_mw++;
					d_c_wm = 1;
				}
			}
		}
	}
	
	if(c_wm < c_mw)
		std::cout << c_wm;
	else
		std::cout << c_mw;
	

	return 0;
}