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

int size;
int* numbers;

int check(bool shouldIncrease) {

    int changes = 0;
    int current = numbers[0];
    for (int i = 1; i < size; ++i) {
        if ((shouldIncrease && current < numbers[i]) || (!shouldIncrease && current > numbers[i])) {
            current = numbers[i];
        } else {
            changes++;
            current = shouldIncrease ? 1000000000 : -1000000000;
        }
        shouldIncrease = !shouldIncrease;
    }
    return changes;
}

int main() {
    std::cin >> size;
    numbers = new int[size];
    for (int i = 0; i < size; ++i) {
        std::cin >> numbers[i];
    }

    std::cout << std::min(check(true), check(false)) << std::endl;
    return 0;
}