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

int main(void)
{
	unsigned n, i, r = 0;
	int x_prev, x;
	int sign_prev, sign = 0;
	int last_fixed = 0;

	scanf("%u", &n);
	for (i = 0; i < n; i++) {
		int fix = 0;

		scanf("%d", &x);

		if (i) {
			sign = x - x_prev;
			if (!sign) {
				if (!last_fixed)
					fix++;
			} else if (sign_prev && ((sign_prev < 0 && sign < 0) || (sign_prev > 0 && sign > 0))) {
				fix++;
			}
		}

		x_prev = x;
		sign_prev = sign;
		last_fixed = fix;
		if (fix) {
			r++;
		}
	}

	printf("%u\n", r);
	return 0;
}