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
#include <iostream>
#include <set>

using namespace std;

int n;
int T[1000000];

set<pair<int, int> > S;

void REK(int i, int k, int dM) {
    pair<int, int> el;
    el.first = i;
    el.second = k;
    S.insert(el);
    if (2 * T[i] < dM) {
        el.first = i + 1;
        el.second = k;
        if (S.find(el) == S.end()) REK(i + 1, k, dM + 1);
    }
    if (2 * T[k] < dM) {
        el.first = i;
        el.second = k - 1;
        if (S.find(el) == S.end()) REK(i, k - 1, dM + 1);
    }

    return;
}

int main() {
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> T[i];
        if (T[i] == n) {
            pair<int, int> el;
            el.first = i;
            el.second = i;
            S.insert(el);
        }
    }

    REK(1, n, n + 1);

    cout << 2 * n + 1 << " " << S.size() << endl;
    return 0;
}