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

// high low high low high low ...
// or
// low high low high low high ...
int prev[2];
int res[2];
int curr;
int length;

int main(void)
{
    scanf("%d %d", &length, &prev[0]);
    prev[1] = prev[0];
    for(int l = 1; l < length; ++l)
    {
        scanf("%d", &curr);
        if(prev[l & 1] <= curr)
        {
            ++res[l & 1];
            prev[l & 1] = -1000000;
        }
        else
            prev[l & 1] = curr;

        if(prev[!(l & 1)] >= curr)
        {
            ++res[!(l & 1)];
            prev[!(l & 1)] = 1000000;
        }
        else
            prev[!(l & 1)] = curr;
    }

    printf("%d\n", res[0] < res[1] ? res[0] : res[1]);
    return 0;
}