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

using namespace std;

typedef long long ll;

const ll INF = 1000000000000000;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    int sigma[n + 1], i[n], j[n];
    int x;
    for (int ind = 1; ind <= n; ind++) {
        cin >> x;
        sigma[x] = ind;
    }

    i[0] = sigma[n];
    j[0] = sigma[n];
    for (int l = 1; l < n; l++) {
        i[l] = min(i[l - 1], sigma[n - l]);
        j[l] = max(j[l - 1], sigma[n - l]);
    }

    int L[n + 1];
    for (int ind = 1; ind <= n; ind++) {
        if (ind % 2 == 0) {
            int l = ind / 2;
            L[ind] = max(0, min(i[l] - 1, n - 2 * l) + 1 - max(j[l] - 2 * l, 0));
        }
        else {
            int l = (ind + 1) / 2;
            L[ind] = max(0, min(i[l - 1] - 1, n - 2 * l + 1) + 1 - max(j[l - 1] - 2 * l + 1, 0));
        }
    }

    ll res = 0;
    for (int ind = 1; ind <= n; ind++) {
        res += L[ind];
    }

    cout << 2 * n + 1 << " " << res << "\n";

    return 0;
}