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

int main()
{
    int n; std::cin >> n;
    int A[n];

    for (int i = 0; i < n; i++) std::cin >> A[i];

    int result1 = 0, result2 = 0;
    bool up = true;
    for (int i = 1; i < n; i++)
    {
        if ((up && A[i] <= A[i - 1]) || (!up && A[i] >= A[i - 1]))
        {
            result1++; i++; continue;
        }

        up = !up;
    }
    up = false;
    for (int i = 1; i < n; i++)
    {
        if ((up && A[i] <= A[i - 1]) || (!up && A[i] >= A[i - 1]))
        {
            result2++; i++; continue;
        }

        up = !up;
    }
    std::cout << std::min(result1, result2);
    
    return 0;
}