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>

#define maxn 1000010
#define mod 1000000007

using namespace std;

long long licz (int x, int a, int b) {
    int mini = max(x-b,0);
    return min(a,x)-mini+1;
}

int tab[maxn], gdzie[maxn];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> tab[i];
        gdzie[tab[i]] = i;
    }
    int mini, maxi;
    long long ile = 0;
    mini = maxi = gdzie[n];
    for (int i = 1; i <= n; ++i) {
        mini = min(mini, gdzie[(2*n+1-i)/2]);
        maxi = max(maxi, gdzie[(2*n+1-i)/2]);
        //cout << maxi << " " << mini << endl;
        if (maxi - mini + 1 <= i) {
            ile += licz(i - (maxi-mini+1), mini, n-maxi-1);
            //cout << licz(i - (maxi-mini+1), mini, n-maxi-1) << endl;
        }
    }
    cout << 2 * n + 1 << " " << ile << endl;
    
}