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

using namespace std;

typedef long long ll;

int ile(int x, int d, int p, int n) {
    if(x < d || x > n)
        return 0;
    int r = min(p,n-x);
    int l = max(0,p+d-x);
    return r-l+1;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int tab[n];
    int index[n+1];
    for(int i=0;i<n;i++) {
        cin>>tab[i];
        index[tab[i]] = i;
    }
    int l = index[n], r = index[n];
    ll wyn = 1;
    for(int i=n-1;i>=(n+1)/2;i--) {
        int akt = index[i];
        if(akt < l) {
            l=akt;
        }
        else if(akt > r) {
            r=akt;
        }
        //cout<<"i: "<<i<<" l: "<<l<<" r: "<<r<<" wyn: ";
        //wyn += (3*n-2*i-2)-2*(r-l);
        //wyn += max(0,())
        int x = 2*(n-i), y = 2*(n-i) + 1;
        wyn += ile(x,r-l+1,l,n);
        //cout<<wyn<<' ';
        wyn += ile(y,r-l+1,l,n);
        //wyn += max(0,x-(r-l));
        //wyn += max(0,y-(r-l));

        //cout<<wyn<<'\n';
    }
    cout<<2*n+1<<' '<<wyn<<'\n';
}