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

int mediana2(vector<int> a,int p,int k) {
	vector<int> b;
	for (int i=p;i<=k;i++) b.push_back(a[i]);
	int n=b.size();
	sort(b.begin(),b.end());
	if (n%2==1)
		return 2*b[n/2];
	else
		return b[n/2-1]+b[n/2];
}

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int> a(n),b(n+1);
	for (int i=0;i<n;i++) {
		cin >> a[i];
		b[a[i]]=i;
	}
	
	long long answer = 1; 
	int l=b[n], r=b[n];
	for (int i=2;i<=n;i++) {
		int v = n-i/2;
		if (b[v]<l) 
			l=b[v];
		else if (b[v]>r)
			r=b[v];
		int d = r-l+1;
		//cout << i << " " << v << " " << d << endl;
		if (d<=i) {
			int lp = max(0,r-i+1);
			int rp = min(n-1,l+i-1);
			//cout << "? " << lp << "," << rp <<endl;
			answer += rp-(lp+i-1)+1;
		}
	}
	cout << 2*n+1 << " " << answer << endl;
	
	/*
	int ans = 0;
	for (int i=0;i<n;i++)
		for(int j=i;j<n;j++) {
			//cout << i+1 << " " << j+1 << "  " << mediana2(a,i,j)+(j-i+1) << endl;
			if (mediana2(a,i,j)+j-i+1 == 2*n+1) ans++;
		}
	cout << 2*n+1 << " " << ans;
	
	*/
	return 0;
}