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

using namespace std;

int count(vector<int> &A){
    int n=A.size();
    int rez = 0;
    for(int i=0;i<n-1;i++){
        // for(int j=0;j<n;j++)cout << A[j] << ' ';
        // cout << '\n';
        if(i%2){
            if(A[i]<=A[i+1]){
                A[i+1] = (1e9)*-1;
                rez++;
                //cout << "1\n";
            }
        }
        else{
            if(A[i]>=A[i+1]){
                A[i+1] = (1e9);
                rez++;
                //cout << "2\n";
            }
        }
    }
    //cout << rez << '\n';
    return rez;
}

int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> A(n), B(n+1, (1e9 + 1)*-1);
    for(int i=0;i<n;i++){
        cin >> A[i];
        B[i+1] = A[i];
    }
    cout << min(count(A), count(B)) << '\n';
}