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
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    vector<int>pos(n+1);
    for (int i = 0; i < n; i++)
    {
        int x; cin >> x;
        pos[x] = i;
    }
    int l = 1e9, r = 0;
    long long ans = 0;
    for (int i = 1; i <= n; i++)
    {
        l = min(l, pos[n-(i/2)]);
        r = max(r, pos[n-(i/2)]);
        ans += (long long)max(0, min(l, n-i) - max(0, r-i+1) + 1);
    }
    cout << 2*n+1 << ' ' <<  ans;
}