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 <algorithm>
#include <cstdio>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define INT(x) int x; scanf("%d", &x)

int a[50000];

int main() {
	INT(n);
	REP(i,n) scanf("%d", &a[i]);
	int res = n;
	REP(p,2) {
		bool up = p;
		int x = a[0], r = 0;
		FOR(i,1,n) {
			if (up ? a[i] > x : a[i] < x) x = a[i];
			else {
				x = up ? 1000000000 : -1000000000;
				++r;
			}
			up = !up;
		}
		res = min(res, r);
	}
	printf("%d\n", res);
}