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;
const int N = 1000 * 1000 + 7;
pair<int, int> tab[N];

int F(int a, int b, int s)
{
    a = min(a, s); b = min(b, s);
    int p;
    p = s - b;
    return (a - p + 1);
}

void Solve()
{
    int n, p = N, k = -1, x;
    ll w = 0LL;
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> tab[i].first; tab[i].second = i;
    }
    sort(tab + 1, tab + 1 + n);
    reverse(tab + 1, tab + 1 + n);
    x = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(x < (i + 2) / 2)
        {
            ++x;
            p = min(p, tab[x].second); k = max(k, tab[x].second);
        }
        if(k - p + 1 <= i)
            w += F(p - 1, n - k, i - (k - p + 1));
        //cout << i << " " << w << "\n";
    }
    cout << n + n + 1 << " " << w << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Solve();

    return 0;
}