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>
#define fi first
#define sc second
#define forn(i,p,k) for(int i=(p);i<=(k);++i)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MM = 1000013;
int T[MM], rev[MM];
bool us[MM];

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    forn(i,1,n) {
        cin>>T[i];
        rev[T[i]] = i;
    }
    long long res = 1;
    int p = rev[n], k = rev[n];
    us[p] = true;
    for(int i=n-1;i;--i) {
        int ind = rev[i];
        p = min(p, ind);
        k = max(k, ind);
        int l = 2 * (n - i);
        if (l > n)  break;
        if (k - p + 1 <= l) {
            int t1 = max(k - l + 1, 1);
            int t2 = min(p + l - 1, n);
            t2 -= l - 1;
            res += t2 - t1 + 1;
        }
        l++;
        if(l > n)   break;
        if (k - p + 1 <= l) {
            int t1 = max(k - l + 1, 1);
            int t2 = min(p + l - 1, n);
            t2 -= l - 1;
            res += t2 - t1 + 1;
        }
    }
    cout<<(2*n+1)<<" "<<res;
    return 0;
}