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

using namespace std;

int MAXX =  1000000000;
int MINN = -1000000000;

int Test(vector<int>& data, int maxMod2){
    int c = 0;
    int prev = data[0], now;
    if(maxMod2 == 0 && prev == MINN){
        prev = MAXX;
        c++;
    }
    else if(maxMod2 == 1 && prev == MAXX){
        prev = MINN;
        c++;
    }
    for(int i = 1; i < data.size(); i++){
        now = data[i];
        if(i%2 == maxMod2 && now <= prev){
            prev = MAXX;
            c++;
            continue;
        }
        if(i%2 != maxMod2 && now >= prev){
            prev = MINN;
            c++;
            continue;
        }
        prev = now;
    }
    return c;
}

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

    vector<int> data(n);
    for(int i = 0; i <n; i++)   cin>>data[i];
    
    int a = Test(data, 0);
    int b = Test(data, 1);
    //cout<<a<< " " << b<<'\n';
    a = a > b ? b : a;
    cout<<a;
    return 0;
}