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

int n,tab[1000007],poz[1000007],wynik=1;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> tab[i];
		poz[tab[i]]=i;
	}
	cout << (2*n+1) << " ";
	if(n<=2) {cout << n;return 0;}
	int p=poz[n],l=poz[n];
	for(int i=2;i<=n;i+=2)
	{
		int k=(i/2)+1;
		if(poz[n+1-k]> l && poz[n+1-k]<p) continue;
		if(poz[n+1-k]<l)
		{
			if(abs(poz[n+1-k]-p)==i+1) {wynik++;continue;}
			if(abs(poz[n+1-k]-p)<i+1)
			{
				wynik+=min(min(n-p+1,l-1+1),abs(i-poz[n+1-k]-l));
			}
		}
		else
		{
			if(abs(poz[n+1-k]-l)==i+1) {wynik++;continue;}
			if(abs(poz[n+1-k]-l)<i+1)
			{
				wynik+=min(min(n-p+1,l-1+1),i-abs(poz[n+1-k]-l));
			}
		}
	}
	cout << ++wynik;
	return(0);
}