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
#include <bits/stdc++.h>
using namespace std;
const int MAXI = 1e6 + 7;
int tab [MAXI];
int odp = 0;
map<pair<int, int>, bool> vis;
pair <int, int> z;
void rec (int l , int p, float med, int n){
    if (2 * tab[l] < med ){
        z = make_pair (l + 1, p);

        if(vis.find(z) == vis.end() && (l + 1 != p || tab[p] != n)) {
            vis[z] = 1;
            odp++;
            rec(l + 1, p, (med + 1), n);
        }
    }
    else if(2 * tab[l] == med) rec(l + 1, p, med - 1, n);
    if(2 * tab[p] < med){
        z = make_pair (l, p - 1);
        if(vis.find(z) == vis.end()  && (l != p  - 1 || tab[l] != n)) {
            vis[z] = 1;
            odp++;
            rec(l, p - 1, (med + 1), n);
        }
    }
    else if(2 * tab[p] == med) rec(l , p - 1, med - 1, n);

}
int main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> tab[i];
    }
    int med = (n + 1);
    if (n == 1) cout <<  n * 2 + 1 << " " << 1;
    else{
        rec(0, (n - 1), med, n);
        cout << n * 2 + 1<< " " << odp + 2;

    }


    return 0;
}