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
#include <cstdio>

int n,i,j,l,r,npos,lmax,lcnt, rmax, rcnt, ward;
int t[1000005];
long long w;


int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&t[i]);
		if(t[i]==n)npos=i;
	}	
	l=1;
	r=n;
	w=0;
	lcnt=0;
	for(i=0;i<npos;i++){
		if(i==0){
			lmax=0;
		}else{
			lmax = lmax < t[i] ? t[i] : lmax;
			lcnt++;
		}
		ward = lmax;
		rcnt=0;
		for(j = n+1; j>npos; j--){
			if(j==n+1){
				rmax=0;
			}else{
				rmax = rmax < t[j] ? t[j] : rmax;
				rcnt++;
			}
			if(rmax>ward)ward=rmax;
			if(n+ lcnt + rcnt > ward*2)
				w++;
		}
	}
	printf("%d %lld",n*2+1,w);
	return 0;
}