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

using namespace std;

main (){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int N;
  cin>>N;
  vector<int> nagr(N);
  for (int i=0; i<N; i++){
    cin>>nagr[i];
  }
  int tend =0;
  int ile = 0;
  bool zm = false;
  for (int i=0; i<N-1; i++){
    if (zm) {
      zm = false;
    } else {
      if (tend ==0) {
        if (nagr[i+1]>nagr[i]) {
          tend =1;
        } else if (nagr[i+1]<nagr[i]) {
          tend = -1;
        } else {
          ile +=1;
          zm = true;
        }
      } else {
        if ((tend<0 && nagr[i+1]>=nagr[i]) || (tend>0 && nagr[i+1]<=nagr[i])) {
          ile +=1;
          zm = true;
        }
      }
    }

    tend *= (-1);
  }
 cout<<ile;
return 0;
}