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

#define ll long long
#define fors(u, n, s) for(ll u=(s); u < (n); u++)
#define foru(u, n) fors(u, n, 0)
#define ir(a, b, x) (((a) <= (x)) && ((x) <= (b)))

using namespace std;

#define N 50050

int n;
int arr[N];

bool wrong[N];
int get_ans(){
    int ans = 0;
    foru(i, n-1){
        if(i&1) wrong[i] = (arr[i]>=arr[i+1]);
        else wrong[i] = (arr[i]<=arr[i+1]);
    }
    foru(i, n-1){
        if(wrong[i]){
            ans++;
            wrong[i]=false;
            wrong[i+1]=false;
        }
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    foru(i, n) cin >> arr[i];

    int ans1 = get_ans();

    foru(i, n) arr[i]*=-1;

    int ans2 = get_ans();

    cout << min(ans1, ans2);

    return 0;
}