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
#include <bits/stdc++.h>

using namespace std;

int main()
{
  std::ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> A(n);
  for (auto &a : A)
    cin >> a;

  int startH = 0, startLow = 0;

  bool isNextH = false;
  for (int i = 1; i < n; ++i)
  {
    if ((isNextH && A[i - 1] >= A[i]) || (!isNextH && A[i - 1] <= A[i]))
    {
      ++startLow;
      ++i; // skip one
      continue;
    }

    isNextH = !isNextH;
  }

  isNextH = true;
  for (int i = 1; i < n; ++i)
  {
    if ((isNextH && A[i - 1] >= A[i]) || (!isNextH && A[i - 1] <= A[i]))
    {
      ++startH;
      ++i; // skip one
      continue;
    }

    isNextH = !isNextH;
  }
  cout << (startH < startLow ? startH : startLow) << endl;
  return 0;
}