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
#include <bits/stdc++.h>

using namespace std;

int n, a, wyn, pom, D, S;
pair <int,int> tab[50007];
bool bigger, smaller;

int main () {

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

cin >> n;

for (int i = 0; i < n; ++i)
{
    cin >> a;
    if (a == 0)
        tab[i] = {tab[i - 1].first, i};
    else if (a < 0)
        tab[i] = {abs(2*a), i};
    else if (a > 0)
        tab[i] = {a, i};
}

sort (tab, tab + n);

for (int i = 0; i < n - 1; ++i)
{
    if (tab[i].first == tab[i + 1].first)
    {
        wyn++;
        if (tab[i].first == tab[i + 2].first)
            i++;
    }

    else
    {
        if (tab[i].second == tab[i + 1].second + 1)
        {
            if (tab[i].first < tab[i + 1].first)
            {
                if (bigger)
                {
                    wyn++;
                    bigger = 0;
                }
                else
                    bigger = 1;
            }
        }

        if (tab[i].second == tab[i + 1].second - 1)
        {
            if (tab[i].first < tab[i + 1].first)
            {
                if (smaller)
                {
                    wyn++;
                    smaller = 0;
                }
                else
                    smaller = 1;
            }
        }
    }
}

cout << wyn;

    return 0;
}