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
#include <iostream>
using namespace std;
int tony[50001];
int ciag[50001];
int n,ile=0;
int main(){
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> tony[i];
    }
    for(int i = 0;i < n-1;i++){
        if(tony[i] > tony[i+1]){
            ciag[i] = 1;
            ciag[i+1] = 0;
        }
        else if(tony[i] < tony[i+1]){
            ciag[i] = 0;
            ciag[i+1] = 1;
        }
        else{
            ciag[i+1] = ciag[i];
        }
    }
    for(int i = 0;i < n-1;i++){
        if(ciag[i]==ciag[i+1]){
            ile++;
            ciag[i+1] = (ciag[i]+1)%2;
            if(tony[i]==tony[i+1])ciag[i+2]=ciag[i];

        }
    }
    cout << ile;
}