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
#include<cstdio>
#include<vector>

#define FOR(i,n) for(int i = 0; i < (n); i++)

using namespace std;

std::vector<int> v;
int sign(int x) {
    if ( x> 0){
        return 1;
    }
    if (x < 0) {
        return -1 ;
    }
    return 0;
}

int main() {
    int n;
    scanf("%d", &n);
    FOR(i,n) {
        int d;
        scanf("%d", &d);
        v.push_back(d);
    }
    int r = n;
    FOR(i,2) {
        int start = 2*i - 1;
        int count = 0;
        int last = 0;
        FOR(j, n-1) {
            if (last) {
                last = 0;
                start *= -1;
                continue;
            }
            if (sign(v[j+1] - v[j]) * start != 1) {
                count++;
                last = 1;
            }
            start *= -1;
        }
        r = min(r, count);
    }
    printf("%d\n", r);
}