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
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;

int pos[1000005];

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        pos[a]=i;
    }

    long long res=1;
    int l=pos[n], r=pos[n];
    for(int i=2;i<=n;i++)
    {
        if(i%2==0)l=min(l,pos[n-i/2]), r=max(r,pos[n-i/2]);
        int k=i-(r-l+1);
        res+=max(0, min(l,k+1)-max(0,r+k-n));
       // cout<<k<<" "<<l<<" "<<r<<" "<<res<<endl;
    }
    cout<<2*n+1<<" "<<res<<endl;
}