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

typedef long long ll;

ll getPossible(int start, int end, int n, int size) {
	int left_over = size - (end - start + 1);
	if (left_over < 0) return 0;
	int max_left = start;
	int max_right = (n - 1) - end;
	int total_available = max_left + max_right - left_over;
	if (total_available < 0) return 0;

	left_over = std::min(max_left, left_over);
	left_over = std::min(max_right, left_over);
	left_over = std::min(total_available, left_over);
	return static_cast<ll>(left_over) + 1;
}

int main() {
	int n;
	std::cin >> n;
	std::vector<int> reviews;
	int max_med = n;
	int min_med = (n + 1) / 2;
	for (int i = 0; i < n; ++i) {
		int review;
		std::cin >> review;
		reviews.push_back(review);
	}

	int start = 0;
	int end = n - 1;

	ll total = 0;
	while (min_med <= max_med) {
		while (reviews[start] < min_med) ++start;
		while (reviews[end] < min_med) --end;

		int size = 2 * (max_med - min_med);
		total += getPossible(start, end, n, size);
		++size;
		total += getPossible(start, end, n, size);

		++min_med;
	}

	std::cout << 1+2*n << " " << total << std::endl;
	return 0;
}