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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <set>

#define ll long long

using namespace std;
const ll N = 1e6+1;

ll n,r,l,num,ind,len,upperlen;
ll t[N];
ll t2[N];
ll ways = 0;

ll fak;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //cout.tie(0);
    
    cin >> n;
    for(ll i = 1; i <= n; i++)
    {
        cin >> t[i];
        t2[t[i]] = i;
    }

    num = n;
    r = l = t2[num];
    ways++;

    while(true)
    {
        num--;
        upperlen = n - num + 1;
        len = r - l + 1;
  //      //cout << num << ' ';
        if(num < (n+1) / 2)
            break;
 //       //cout << "tak\n";
        ind = t2[num];
        if(ind < l) 
        {
            //cout << "left  " << l << ' ' << ind << endl;
            l = ind;
            fak = true;
        }
        else if(ind > r)
        {
            //cout << "right " << r << ' ' << ind << endl;
            r = ind;
            fak = true;
        }  
        if(fak and upperlen >= (len+1)/2)
        {
            //cout << num << ' ' << l << ' ' << r << ' ' << endl;
            ways+= fak;
            fak = 0;
        }
    }
    //cout << l << ' ' << r << endl;
    //cout <<  (l)*(n-r+1)-1 << endl;
    ways += (l)*(n-r+1)-1;
    cout << 2*n+1 << ' ' << ways;
    

}