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
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<pll> vll;
typedef vector<pii> vii;
typedef double db;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define st first
#define nd second
#define FOR(i,s,k) for(auto i=s; i<k; i++)
#define ROF(i,s,k) for(auto i=k-1; i>=s; i--)
constexpr ll inf = 1e9+1;
constexpr ll MAXN = 1e6+5;
constexpr ll LOGN = 18;

int main()
{
	BOOST;
	int n;
	cin>>n;
	vi V(n);
	FOR(i,0,n) cin>>V[i];
	bool r = false;
	int cnt = 0;
	int ans = inf;
	FOR(i,1,n)
	{
		if((r && (V[i] <= V[i-1])) || (!r && (V[i] >= V[i-1])))
		{
			cnt++;//ustawiam V[i] na 1e9
			i++;
		}
		else 
			r = !r;
	}
	ans = min(ans, cnt);
	r = true; cnt = 0;
	FOR(i,1,n)
	{
		if((r && (V[i] <= V[i-1])) || (!r && (V[i] >= V[i-1])))
		{
			cnt++;//ustawiam V[i] na 1e9
			i++;
		}
		else 
			r = !r;
	}
	ans = min(ans,cnt);
	cout<<ans;
}