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

const int MAX_N = 1e6 + 10;

int64_t get_result(const vector<int> &marks) {
	int n = marks.size();
	
	int j = n;
	int64_t ans = 0;
	int maks = 0;
	
	for (int i = 0; i < n-1; i++) {
		maks = max(maks, marks[i]);
		
		if (j-1 == i) j++;
		while(j - 1 > i+1 && marks[j - 1] < maks) j--;
		
		if (2 * maks < i + n + 1)
			ans += n - j + 1;
		else if (2 * maks < i + (n - j) + n + 1)
			ans += (i + (n - j) + n + 1 - 2 * maks);
	}
	
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n;
	cin >> n;
	
	vector<int> marks(n);
	for (int &i : marks) cin >> i;
	
	int64_t ans = 1;
	
	ans += get_result(marks);
	reverse(marks.begin(), marks.end());
	ans += get_result(marks);
	
	cout << 2 * n + 1 << " " << ans << endl;
	
	return 0;
}