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
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
namespace wzor
{
}
pair<i64, i64> solve_wzor(int n, int *input)
{
	using namespace wzor;
	vector<int> pos(n + 1);
	input -= 1;
	for(int i = 1; i <= n; ++i)
	{
		pos[input[i]] = i;
	}
	int min_pos = pos[n];
	int max_pos = pos[n];
	int64_t ans = 0;
	for(int i = 1; i <= n; ++i)
	{
		if(i % 2 == 0)
		{
			min_pos = min(min_pos, pos[n - i / 2]);
			max_pos = max(max_pos, pos[n - i / 2]);
		}
		int length = max_pos - min_pos + 1;
		if(length > i) continue;
		int length_left = i - length;
		int beginning = max(1, min_pos - length_left);
		int end = min(n, max_pos + length_left);
		int possible_intervals = end - beginning - i + 2;
		ans += possible_intervals;
	}
	

	i64 ans_simple = (2 * n + 1);
	return {ans_simple, ans};
}
#include <bits/stdc++.h>
using namespace std;

int input[1000100];
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i)
	{
		cin >> input[i];
	}
	auto c = solve_wzor(n, input);
	cout << c.first << ' ' << c.second << '\n';
}