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

void update_vis(bool *vis, int &it) {
	while (vis[it])
		--it;
	return;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);

	int n;
	std::cin >> n;

	auto *tab = new int [n + 1];
	for (int i = 0; i < n; ++i) {
		int input;
		std::cin >> input;
		tab[input] = i;
	}

	int l = tab[n], r = tab[n];

	long long score = 1;
	for (int len = 2; len <= n; ++len) {
		l = std::min(l, tab[n - (len / 2)]);
		r = std::max(r, tab[n - (len / 2)]);
		if (r - l + 1 > len) continue;

		long long sub_r = std::min(l + len - 1, n - 1);
		long long sub_l = std::max(r - len + 1, 0);

		score += sub_r - sub_l - len + 2;
	}

	std::cout << 2 * n + 1 << " " << score;
	delete [] tab;
	return 0;
}