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
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define p_b push_back
#define m_p make_pair
#define fi first
#define se second
 
ll inf = 8000000000000000000;
ll mod = 1000000007;
const int maxn = 300003;


int main(){
    ios_base::sync_with_stdio(0);
    int n; cin>>n;
    vector<pair<ll, ll>> t;
    for(int i = 0; i<n; i++){
        int a; cin>>a;
        t.p_b({a, i});
    }

    sort(t.begin(), t.end(), greater<pair<ll, ll>>());
    ll res = 1, p = t[0].se, k = t[0].se;
    int j = -1;
    for(int i = 2; i<=n; i++){
        while(j+1<n && j+2<=i/2+1){
            j++;
            p = min(p, t[j].se);
            k = max(k, t[j].se);
        }
        
        int r = k-p+1;
        if(i<r) continue;
        int w1 = max((ll)0, -(n-p-i)), w2 = max((ll)0, -k+i-1);
        res += i-r+1-w1-w2;
    }

    cout<<2*n+1<<" "<<res;
}