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
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;

int tab[1000009], per[1000009];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long n, a, b, c, wyn = 1, l, r;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>tab[i];
		per[tab[i]] = i;
		if(tab[i] == n) a = i;
	}
	l = r = a;
	for(int k=2; k<=n; k++)
	{
		a = per[n - (k/2)];
		if(l > a) l = a;
		if(r < a) r = a;
		if(r - l + 1 == k) wyn++;
		if(r - l + 1 < k)
		{
			a = max(r - k + 1, 1LL * 1);
			b = min(l + k - 1, n);
			c = b - a + 1 - k + 1;
			wyn += c;
		}
	}
	cout<<2*n+1<<" "<<wyn;
	return 0;
}