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
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
// Ornitolog.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> liczby;
vector<int> strzalki;

void Kierunki()
{
    strzalki.resize(0);
    int n = liczby.size();
    for (int i = 1; i < n; i++)
        if (liczby[i] > liczby[i - 1])
            strzalki.push_back(1);
        else if (liczby[i] < liczby[i - 1])
            strzalki.push_back(-1);
        else
            strzalki.push_back(0);
}
int Gorne()
{
    vector<int> t = strzalki;
    int n = liczby.size();
    vector<int> gora;
    int roz = 0;
    for (int i = 1; i < n; i++)
        gora.push_back(-1 + ((i % 2) * (2)));
    int pop = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (gora[i] != t[i])
        {
            if (pop == 1)
                pop--;
            else
            {
                pop++;
                roz++;
            }
            t[i] *= -1;
        }
        else
        {
            pop = 0;
        }
    }
    return roz;
}
int Dolne()
{
    int n = liczby.size();
    vector<int> dol;
    int roz = 0;
    for (int i = 1; i < n; i++)
        dol.push_back(1 + ((i % 2) * (-2)));
    int pop = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (dol[i] != strzalki[i])
        {
            if (pop == 1)
                pop--;
            else
            {
                pop++;
                roz++;
            }
        }
        else
        {
            pop = 0;
        }
    }
    return roz;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        liczby.push_back(x);
    }
    Kierunki();
    int i = 1;
    while (i < n && liczby[i] == liczby[i - 1])
    {
        i++;
    }
    if (i == n)
        cout<< n / 2;
    else
    {
        cout << min(Gorne(), Dolne());
    }
}