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

using namespace std;
using LL = long long;

int main()
{
	int n, a;

	cin >> n;

	vector<int> pos(n + 1);

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

	int res = 2 * n + 1;
	LL cnt = 0;
	int mn = 10000000;
	int mx = -1;

	for (int i = 1; i <= n; ++i)
	{
		int m = n - i / 2;

		mn = min(mn, pos[m]);
		mx = max(mx, pos[m]);

		if (mx - mn < i)
		{
			int beg = max(0, mx - i + 1);
			int end = min(n - 1, mn + i - 1);

			cnt += end - beg + 1 - i + 1;
		}
	}

	cout << res << " " << cnt << endl;

	return 0;
}