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

int n;
int* song;
int how_many_errors(int lower_index_reminder) {
    int errors = 0;
    for (int i = 0;i<n-1;) {
        if (i % 2 == lower_index_reminder) 
            if (song[i] >= song[i + 1]) errors++;
            else i -= 1;
        else if (song[i] <= song[i + 1])  errors++;
            else i -= 1;
        i += 2;
    }
    return errors;
}

void solution(std::istream& instream, std::ostream& outstream) {
    instream >> n;
    song = new int[n];
    for (int i = 0; i < n; i++) {
        instream >> song[i];
    }       
    outstream << std::min(how_many_errors(0), how_many_errors(1));
}

int main() {
    solution(std::cin, std::cout);
    return 0;
}