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 <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 5;

#define st first
#define nd second

typedef pair<int,int> pun;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> v;
	vector<int> where;
	where.resize(n+1);
	for (int i = 0; i < n; i ++) {
		int x;
		cin >> x;
		v.push_back(x);
		where[v[i]] = i;
	}
	int ile = n;
	int p = where[n];
	int k = where[n];
	ll res = 0;
	for (int i = 1; i <= n; i ++) {
		int med = 2 * n - i;
		int x = (i+2)/2;
		if (i % 2 == 0) {
			p = min(p, where[n - x + 1]);
			k = max(k, where[n - x + 1]);

//			cerr << "i=" << i << " " << "n-x+1=" << n - x + 1 << " where=" << where[n - x + 1] << "\n"; 
		}
//		cerr <<"i=" << i << "\n";
//		cerr << "p=" << p << " k=" << k << "\n";
		if (k - p + 1 > i) continue;
//		cerr << "add=" << k - p + 1 << "\n";
//		cerr << "to_res=" << min(min(p+1, n - k), i - (k - p + 1) + 1) << "\n";
		res += min(min(n - i + 1, min(p+1, n - k)), i - (k - p + 1) + 1);
	}
	cout << 2 * n + 1 << " " << res;
	
}