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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <bits/stdc++.h>

using namespace std;

vector<long long > tab;

map<long long , long long > mp;

set<long long > prze;

int  main()
{
    long long  n;
    cin >> n;
    for (long long  i = 0; i < n; ++i)
    {
        long long  pom;
        cin >> pom;
        tab.push_back(pom);
        mp[pom] = i;
    }
    long long  l = mp[n], r = mp[n];
    long long  maxl = n;
    long long  w = 0;

    long long  j = 1;
    while (j <= n)
    {
        long long  dl = (j / 2) + 1;
        long long  now = mp[n - dl+1];

        if (now < l)
        {
            l = now;
        }

        if (now > r)
        {
            r = now;
        }

        if (r-l +1 <= j)
        {
           long long  luz = j-(r-l+1);//moze dodac n-j
           if (luz == 0)
           {
               w++;
           }
           else
           {
               int ll = max(l-luz,(long long)0);
               int pp = min(r+luz,n-1);

               w+=pp-ll-(j-2);
               //w+=min(min(luz ,l),n-r);
               //w+=min(min(luz,n-r-1),l+1);
           }
           //cout << luz; 
        }

        

        j++;
    }

    cout << (n * 2) + 1 << " " << w << endl;
}

/*


5
1 4 3 5 2

5
1 2 3 5 4

7
3 1 2 4 5 7 6 

7
3 1 7 5 6 2 4 


7
4 6 7 5 1 3 2 
*/