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
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using ll=long long;
const int MAXN=(1e6+5);
ll a[MAXN], nr[MAXN];
ll n;

int main()
{_
	cin>>n;
	for(int i=1; i<=n; i++){
		 cin>>a[i]; nr[a[i]]=i;
	 }
	 cout<<2*n+1<<" ";
	 ll wynik=1, pocz=nr[n], kon=nr[n], num=n;
	 while(num>=2){
		 num--;
		 if(n%2!=num%2){
			 pocz=min(pocz, nr[(n+num)/2]);
			 kon=max(kon, nr[(n+num)/2]);
		 }
		 ll diff=kon-pocz;
		 //cout<<num<<" "<<pocz<<" "<<kon<<"\n";
		 if(diff > n - num) continue;
		 wynik+=abs(max(kon-n+num, (ll)1)-min(pocz, num))+1;
	 }
	 cout<<wynik;
}