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
#pragma GCC optimize ("O3")

#include <iostream>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, a, apr = 0, apf = n + 1;
    vector<int> oceny;
    cin >> n;
    bool rising = true, falling = true;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (rising && a != apr + 1)
            rising = false;
        if (falling && a != apf - 1)
            falling = false;
        oceny.push_back(a);
        apr = a;
        apf = a;
    }
    int max = 1 + 2 * n;
    volatile float med = (static_cast<float>(n) + 1) / 2;
    int removed_f = 0;
    int removed_e = n - 1;
    volatile int last = 0;
    bool searching = true;
    bool done = true;
    while (searching) {
        if (removed_f == removed_e)
            searching = false;
        if (oceny[removed_f] < med) {
            removed_f += 1;
            last++;
            med += 0.5;
            done = true;
        }
        if (oceny[removed_e] < med) {
            removed_e--;
            last++;
            med += 0.5;
            done = true;
        }
        if (!done)
            searching = false;
        done = false;
    }
    med = (n + 1) / 2;
    searching = true;
    int on_b = 0, on_e = 0;
    for (int i = 0; searching; i++) {
        if (oceny[i] < med) {
            on_b++;
            med += 0.5;
        } else {
            searching = false;
        }
    }
    med = (n + 1) / 2;
    searching = true;
    for (int i = n - 1; searching; i--) {
        if (oceny[i] < med) {
            on_e++;
            med += 0.5;
        } else {
            searching = false;
        }
    }
    cout << max << ' ' << on_b * on_e + last + (rising || falling ? 1 : 2);
}