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
50
51
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>
using namespace std;

#define vi vector<int>
#define f first
#define s second
#define sz(s) (int)s.size()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>

const int N = 1e6 + 7;
int tab[N];
int where[N];

#define ll long long

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

    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> tab[i];
        where[tab[i]] = i;
    }
    
    int l = where[n];
    int r = where[n];
    
    ll ans = 1;

    for(int i = n - 1; i >= (n + 1) / 2; i--){
        l = min(l, where[i]);
        r = max(r, where[i]);

        int lo = -1;
        int hi = n;
        
        int dl = (n - i + 1) * 2 - 2;
        // cout << "i << " << i << ' ' << l << ' ' << r << ' ' << lo << ' ' << hi << "      " << dl << endl;

        ans += max(0, min({dl - (r - l + 1) + 1, (hi - lo - 1) - dl + 1, l - lo, hi - r}));

        // cout << "MALE ANS " << ans << endl;

        if(i == n / 2 and n % 2 == 0)
            break;

        dl++;
        ans += max(0, min({dl - (r - l + 1) + 1, (hi - lo - 1) - dl + 1, l - lo, hi - r}));

        // cout << "ANS " << ans << '\n';        
    }

    cout << n * 2 + 1 << ' ' << ans << '\n';

    return 0;
}