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
45
46
47
48
49
#include <iostream>
using namespace std;

const int LOWEST = -1000000000;
const int HIGHEST = 1000000000;

int main() {
  int n;
  cin >> n;
  int a_prev_up = LOWEST, a_prev_down = HIGHEST, a_akt;
  int sum_up = 0, sum_down = 0;
  for(int i = 0; i < n; i++) {
	  cin >> a_akt;
	  if(i % 2 == 0) {
		  if(a_akt > a_prev_up)
			  a_prev_up = a_akt;
		  else {
			  sum_up++;
			  a_prev_up = HIGHEST;
		  }
		  if(a_akt < a_prev_down)
			  a_prev_down = a_akt;
		  else {
			  sum_down++;
			  a_prev_down = HIGHEST;
		  }
	  } else {
		  if(a_akt < a_prev_up)
			  a_prev_up = a_akt;
		  else {
			  sum_up++;
			  a_prev_up = LOWEST;
		  }
		  if(a_akt > a_prev_down)
			  a_prev_down = a_akt;
		  else {
			  sum_down++;
			  a_prev_down = LOWEST;
		  }
	  }
	  
  }
  if(sum_up < sum_down)
	  cout << sum_up << endl;
  else
	  cout << sum_down << endl;	  
  
  return 0;
}