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

int t[1000009];

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1; i<=n; i++){
		int tmp;
		cin>>tmp;
		t[tmp]=i;
	}
	if(n==1){
		cout<<"3 1\n";
		return 0;
	}
	
	LL sum = 0;
	
	int l=min(t[n], t[n-1]);
	int p=max(t[n], t[n-1]);
	if(l==p-1){
		sum++;
	}
	for(int i=n-2; i>=(n/2 + n%2); i--){
		l = min(l, t[i]);
		p = max(p, t[i]);
		int dl = (n-i)*2;
		int odl = p-l+1;
		if(dl - odl < 0){
			continue;
		}if(dl - odl == 0){
			sum++;
		}else{
			int x = dl - odl;
			int maxl = min(x, l-1);
			int maxp = min(x, n-p);
			sum += (maxp + maxl) - x + 1;
		}
	}
	
	
	l = t[n];
	p = t[n];
	sum++;
	for(int i=n-1; i>=n/2+1; i--){
		l = min(l, t[i]);
		p = max(p, t[i]);
		int dl = (n-i)*2+1;
		int odl = p-l+1;
		if(dl - odl < 0){
			continue;
		}if(dl - odl == 0){
			sum++;
		}else{
			int x = dl - odl;
			int maxl = min(x, l-1);
			int maxp = min(x, n-p);
			sum += (maxp + maxl) - x + 1;
		}
	}
	
	
	
	cout<<n+n+1<<" "<<sum<<"\n";
	return 0;
}