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

void solve() {
    int n, k;
    cin >> n;
    vector<int> oceny(n, 0);
    unordered_map<int, int> valtopos;
    for (int i = 0; i < n; i++) {
        cin >> k;
        oceny[i] = k;
        valtopos.insert({k, i});
    }
    long long ways = 0, opt = 2*n + 1;
    int left = valtopos[n], right = valtopos[n], pos, maxlen, diff;
    int sr, er;
    for (int len = 1; len <= n; len++) {
        maxlen = 1 + len / 2;
        pos = valtopos[n-maxlen+1];
        if (pos <= left) {
            left = pos;
        } else if (right <= pos) {
            right = pos;
        }
        if (right - left + 1 < len) {
            diff = len - right + left - 1;
            sr = (left - min(left, diff)) + len - 1;
            er = right + min(diff, n - right -1);
            ways += er - sr + 1;
        } else if (right - left + 1 == len) {
            ways++;
        }
    }
    cout << opt << " " << ways << "\n";
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}