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
64
65
66
67
68
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0), cin.tie(0);
#define ll long long
using namespace std;
const int N = 1e6+69, mini = -1e9, maks = 1e9;
int tab[N], arr[N], bat[N];

void wypisz(int arr[], int n){
    for(int i = 0; i < n; i++){
        cout<<arr[i]<<' ';
    }cout<<'\n';
}

void solve(){
    int n, l=0, p=0, res1=0, res2=0;
    bool fl=1;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>tab[i];
        bat[i]=tab[i];
        arr[i]=tab[i];
    }

    for(int i=0; i<n-1; i++){
        if(fl){
            if(bat[i] <= bat[i+1]){
                bat[i+1]=mini;
                res1++;
            }
            fl=0;
        }
        else{
            if(bat[i] >= bat[i+1]){
                bat[i+1]=maks;
                res1++;
            }
            fl=1;
        }
    }
    fl=1;
    for(int i = 0; i < n-1; i++){
        if(fl){
            if(arr[i] >= arr[i+1]){
                arr[i+1]=maks;
                res2++;
            }
            fl=0;
        }
        else{
            if(arr[i] <= arr[i+1]){
                arr[i+1]=mini;
                res2++;
            }
            fl=1;
        }
    }

    //wypisz(bat, n);
    //wypisz(arr, n);
    cout<<min(res1,res2);
}

int main()
{
    fast;
    solve();
    return 0;
}