1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n = *istream_iterator<int>(cin), score = 0;
    vector <int> tab(n);
    for(int& x:tab)cin>>x;
    bool state = tab[0]>tab[1];
    int llast=state?INT_MAX:INT_MIN, last=state?INT_MIN:INT_MAX;
    for(int& x:tab)
    {
        if(!((llast<last&&last>x)||(llast>last&&last<x)))
        {
            score++;
            x=(llast<last)?INT_MIN:INT_MAX;
        }
        llast=last;
        last=x;
    }
    cout<<score;
    return 0;
}