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
#include <iostream>
#include<vector>
#include<tuple>
#include <algorithm>
using namespace std;

int n;
vector<int> a;

void solve() {
    cin >> n;

    int s;

    for (int i = 0; i < n; ++i) {
        cin >> s;
        a.push_back(s);
    }

    int Wynik1 = 0, Wynik2 = 0;

    vector<int> p1, p2;
    p1 = a;
    p2 = a;

    for (int i = 0; i < n - 1; ++i) {
        if (i % 2 == 0 && a[i] - a[i + 1] <= 0) {
            a[i + 1] = -10000000;
            Wynik1++;
        }
        else if (i % 2 != 0 && a[i] - a[i + 1] >= 0) {
            a[i + 1] = 10000000;
            Wynik1++;
        }
    }

    for (int i = 0; i < n - 1; ++i) {
        if (i % 2 == 0 && p1[i] - p1[i + 1] >= 0) {
            p1[i + 1] = 10000000;
            Wynik2++;
        }
        else if (i % 2 != 0 && p1[i] - p1[i + 1] <= 0) {
            p1[i + 1] = -10000000;
            Wynik2++;
        }
    }
    cout << min(Wynik1, Wynik2) << endl;
}

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

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}