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

using namespace std;

const int N = 1'000'009;

int n, p[N];

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

    cin >> n;
    for(int a, i = 1; i <= n; i++) {
        cin >> a;
        p[a] = i;
    }

    long long ans = 0;

    int l = p[n], r = p[n];
    
    for(int i = 2 * n; i > n; i--) {

        l = min(l, p[i >> 1]);
        r = max(r, p[i >> 1]);

        int x = 2 * n + 1 - i;
        int d = r - l + 1;

        ans += max(min(n - x + 1, l) - max(1, l - (x - d)) + 1, 0);
    
    }

    cout << 2 * n + 1 << ' ' << ans << '\n';
 
}