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

using namespace std;

long long n, minp=INT_MAX, maksp=-1, res;
vector<int>V;

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

    cin>>n;
    V.assign(n+1, -1);

    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        V[x]=i;
    }
    for(int i=1;i<=n;i++)
    {
            if(V[n-(i/2)]>maksp)maksp=V[n-(i/2)];
            if(V[n-(i/2)]<minp)minp=V[n-(i/2)];

            if(maksp-minp+1<=i)
            {
                res+=min(minp, i-(maksp-minp+1))+min(n-maksp-1, i-(maksp-minp+1))-(i-(maksp-minp+1))+1;
            }
            //cout<<minp<<' '<<maksp<<' '<<i<<' '<<res<<endl;
    }

    cout<<2*n+1<<' '<<res;
    return 0;
}