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

using namespace std;

int n, a, mini, maxi, dodod;
vector<pair<int, int> >v;
long long res;

int main () {
	cin >> n;
	for (int i=1; i<=n; i++) {
		cin >> a;
		v.push_back(make_pair(a, i));
	}
	sort(v.begin(), v.end(), greater<pair<int, int> >());
	mini = v[0].second;
	maxi = v[0].second;
	res += 1;
	for (int i=2; i<=n; i++) {
		if (i % 2 == 0) {
			mini = min(mini, v[i/2].second);
			maxi = max(maxi, v[i/2].second);
		}
		dodod = i - (maxi - mini + 1);
//		cout << i << " " << mini << " " << maxi << " " << dodod << endl;
		if (dodod < 0) continue;
		res += min(min(dodod, n - i), min(n - maxi, mini - 1)) + 1;
	}
	cout << 2 * n + 1 << " " << res << endl;
}