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
#include <bits/stdc++.h>
using namespace std;


int32_t n, a[50000];
int16_t r1, r2;


int main()
{
    scanf("%" SCNd32, &n);
    for (int32_t i = 0; i < n; ++i) scanf("%" SCNd32, a + i);

    bool higher = true;
    int32_t pv = *a;
    for (int32_t i = 1; i < n; ++i) {
        if (higher && a[i] <= pv) {
            ++r1;
            pv = 1000000000;
        }
        else if (!higher && a[i] >= pv) {
            ++r1;
            pv = -1000000000;
        }
        else pv = a[i];
        higher = !higher;
    }

    higher = false;
    pv = *a;
    for (int32_t i = 1; i < n; ++i) {
        if (higher && a[i] <= pv) {
            ++r2;
            pv = 1000000000;
        }
        else if (!higher && a[i] >= pv) {
            ++r2;
            pv = -1000000000;
        }
        else pv = a[i];
        higher = !higher;
    }

    printf("%" PRId32 "\n", min(r1, r2));
}