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

#define MAX_N 1000007
#define HIGH_A 1000001
#define LOW_A -1000001

int n;
vector<int> values(MAX_N);
vector<int> first_up(MAX_N);
vector<int> first_down(MAX_N);
int score_first_up, score_first_down;

int main() {

    ios_base::sync_with_stdio(false);
    cin >> n;
    cin >> values[0];

    for (int i = 1; i < n; i++) {
        cin >> values[i];
    }

    first_up = values;
    first_down = values;

    for (int i = 1; i < n; i++) {
        if (i % 2) {
            if (first_up[i - 1] >= first_up[i]) {
                first_up[i] = HIGH_A;
                score_first_up++;
            }
            if (first_down[i - 1] <= first_down[i]) {
                first_down[i] = LOW_A;
                score_first_down++;
            }
        }
        else {
            if (first_up[i - 1] <= first_up[i]) {
                first_up[i] = LOW_A;
                score_first_up++;
            }
            if (first_down[i - 1] >= first_down[i]) {
                first_down[i] = HIGH_A;
                score_first_down++;
            }
        }
    }

    cout << min(score_first_up, score_first_down) << "\n";
    return 0;
}