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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>

#define fi first
#define se second

#define pb push_back

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    std::vector<int> Q(n);

    for (auto &e : Q)
        cin >> e;

    std::vector<int> A = Q, B = Q;

    int wynik1 = 0;

    for (int i = 0; i < A.size() - 1; i++)
    {
        int roznica = A[i + 1] - A[i];
        if (i % 2 == 0 and roznica >= 0)
        {
            wynik1++;
            A[i + 1] = (int)-1e9;
        }
        else if (i % 2 == 1 and roznica <= 0)
        {
            wynik1++;
            A[i + 1] = (int)1e9;
        }
    }

    int wynik2 = 0;

    for (int i = 0; i < B.size(); i++)
    {
        int roznica = B[i + 1] - B[i];
        if (i % 2 == 0 and roznica <= 0)
        {
            wynik2++;
            B[i + 1] = (int)1e9;
        }
        else if (i % 2 == 1 and roznica >= 0)
        {
            wynik2++;
            B[i + 1] = (int)-1e9;
        }
    }

    cout << min(wynik1, wynik2) << '\n';

    return 0;
}