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
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector> 
using namespace std;
typedef long long ll;
typedef long double ld;
#define st first
#define nd second

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans1 = 0, ans2 = 0;
    for (int i = 1; i < n; i++) if ((a[i] == a[i-1]) || ((a[i] > a[i-1]) == (i&1)))
    {
        ans1++;
        i++;
    }
    for (int i = 1; i < n; i++) if ((a[i] == a[i-1]) || ((a[i] < a[i-1]) == (i&1)))
    {
        ans2++;
        i++;
    }
    cout << min(ans1, ans2);
}