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
#include <iostream>
#include <algorithm>

using namespace std;

#define N 1000005

int n;
int a[N];
int pos[N];

int expected;
pair<int, int> range;
long long ans;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	cin >> n;

	for(int i=0;i<n;i++){
		cin >> a[i];
		pos[a[i]] = i;
	}

	expected = 2*n + 1;
	range = {pos[n], pos[n]};

	for(int i=1;i<=n;i++){
		if(i%2 == 0){
			range.first = min(range.first, pos[n-i/2]);
			range.second = max(range.second, pos[n-i/2]);
		}

		ans += max(0, min(n-i, range.first) - max(0, range.second - i + 1) + 1);
		//cout << range.first << " " << range.second << " " << min(n-i, range.first) - max(0, range.second - i + 1) << " " << ans << "\n";
	}

	cout << expected << " " << ans;

	return 0;
}

/*
5
1 4 3 5 2
*/