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
#include <bits/stdc++.h>
using namespace std;

#define st first
#define nd second
#define int long long
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin>>n;
	vector<int> v(n);
	vector<int> gdz(n+1);
	for(int i=0; i<n; i++)
	{
		cin>>v[i];
		gdz[v[i]]=i;
	}
	
	int i=gdz[n],j=gdz[n];
		
	int roz=1;
	int ile=1;
	if(i>0 && v[i-1]==n-1){
	i--; ile++;}
	else if(j<n-1 && v[j+1]==n-1){
	j++; ile++;}
	for(int k=roz; k<n; k++)
	{
		if(k==1 || k%2==0)
		{
			while(i>gdz[n-roz])
				i--;
			while(j<gdz[n-roz])
				j++;
			roz++;
		}
		
		if(k%2==0)
		{
			int wide=roz+roz-2;
			if(j-i+1<=wide)
			{
				int p=max(1LL*0, j-wide+1);
				int k=min(n-1, i+wide-1);
				int zak=p+wide-1;
				ile+=max(1LL*0,k-zak+1);
				//`cout<<p<<" "<<k<<" za"<<zak<<" ";
			}
			//cout<<i<<" "<<j<<"  o "<<wide<<" "<<ile<<endl;
		}
		else
		{
			int wide=roz+roz-1;
			if(j-i+1<=wide)
			{
				int p=max(1LL*0, j-wide+1);
				int k=min(n-1, i+wide-1);
				int zak=p+wide-1;
				ile+=max(1LL*0,k-zak+1);
				//cout<<p<<" "<<k<<" za"<<zak<<" ";
			}
		//cout<<i<<" "<<j<<"   t "<<wide<<" "<<ile<<endl;
		}
	}
	
	
	
	cout<<n*2+1<<" "<<ile;
	
	
}