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

// copy vector
uint32_t sol(std::vector<int32_t> tab, bool x) {
    uint32_t sum = 0;
    for (size_t i = tab.size()-1; i > 0; --i) {
        if ((i+x) % 2) {
            if (tab[i-1] >= tab[i]) {
                // printf("%d -> %d\n", tab[i-1], std::numeric_limits<int32_t>::min());
                tab[i-1] = std::numeric_limits<int32_t>::min();
                ++sum;
            } 
        } else {
            if (tab[i-1] <= tab[i]) {
                // printf("%d -> %d\n", tab[i-1], std::numeric_limits<int32_t>::max());
                tab[i-1] = std::numeric_limits<int32_t>::max();
                ++sum;
            }
        }
    }
    return sum;
}

int main() {

    size_t n;
    scanf("%zu", &n);

    std::vector<int32_t> tab(n);
    for (size_t i = 0; i < n; ++i)
        scanf("%d", &tab[i]);

    uint32_t s1 = sol(tab, false);
    // printf("s1: %u\n" , s1);
    uint32_t s2 = sol(tab, true);
    // printf("s2: %u\n" , s2);

    printf("%u\n", std::min(s1, s2)); 

    return 0;
}