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
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main(){
  fastio;
  int n; cin >> n;
  int sum1 = 0, sum2 = 0;
  int last; cin >> last;
  bool chl1 = false, chl2 = false;

  for(int i = 2; i <= n; i++){
    int a; cin >> a;
    if(i % 2 == 1) swap(sum1, sum2), swap(chl1, chl2);
    
    if(last <= a && !chl1)
      sum1++, chl1 = true;
    else chl1 = false;
    if(last >= a && !chl2)
      sum2++, chl2 = true;
    else chl2 = false;

    if(i % 2 == 1) swap(sum1, sum2), swap(chl1, chl2);
    last = a;
  }

  cout << min(sum1, sum2) << "\n";
}