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
#include <iostream>
#include <algorithm>


static const int MAX_TONE =  1000000000;
static const int MIN_TONE = -1000000000;


static int iCnt;

static int a[50002];
static int b[50002];


static int Count(int * p, bool fIncrease)
{
    int iRes = 0;

    for (int i = 1; i < iCnt; ++i, fIncrease = !fIncrease)
    {
        if (fIncrease)
        {
            if (p[i] > p[i - 1])
                continue;

            p[i] = MAX_TONE;
            iRes++;
        }
        else
        {
            if (p[i] < p[i - 1])
                continue;

            p[i] = MIN_TONE;
            iRes++;
        }
    }

    return iRes;
}


int main()
{
    std::cin >> iCnt;

    for (int i = 0; i < iCnt; ++i)
    {
        int x;

        std::cin >> x;

        a[i] = x;
        b[i] = x;
    }

    int m = Count(a, true);
    int n = Count(b, false);

    int iResult = std::min(m, n);

    std::cout << iResult;
}