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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, n) for(decltype(n) i = (a), i##__ = (n); i <= i##__; i++)
#define REP(i, n) FOR(i, 0, (n)-1)
#define FORD(i, a, n) for(decltype(a) i = (a), i##__ = (n); i >= i##__; i--)
#define REPD(i, n) FORD(i, (n)-1, 0)
#define V vector
#define ST first
#define ND second
#define EB emplace_back
#define RS resize
#define SZ(x) int(x.size())
#define ALL(x) x.begin(), x.end()
#define OS ostream

template<class A, class B> OS& operator<<(OS &os, pair<A, B> p) {
	return os << "(" << p.ST << ", " << p.ND << ")";
}
template<class A> OS& operator<<(OS &os, V<A> v) {
	os << "{ ";
	for(auto e : v) os << e << " ";
	return os << "}";
}
template<class A> OS& operator<<(OS &os, V<V<A>> v) {
	os << "[\n";
	for(auto e : v) os << "  " << e << "\n";
	return os << "]";
}

#ifdef DEBUG
# define D(a...) a
# define _D(a...)
#else
# define D(a...)
# define _D(a...) a
#endif
# define I(a...) #a << ": " << a << "\n"
# define J(a...) #a << ": " << a << "  "

using VI   = V<int>;
using VVI  = V<VI>;
using VVVI = V<VVI>;
using II   = pair<int, int>;
using VII  = V<II>;
using VVII = V<VII>;
using L    = long long;
using VL   = V<L>;
using VVL  = V<VL>;
using LI   = pair<L, int>;
using VB   = V<bool>;
using VVB  = V<VB>;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n; cin >> n;
	VI a(n), rev(n);
	REP(i, n) {
		cin >> a[i];
		a[i]--;
		rev[a[i]] = i;
	}
	D(cerr << I(rev));
	int l = n, r = 0;
	L ans = 0;
	FOR (d, 1, n / 2 + 1) {
		l = min(l, rev[n - d]);
		r = max(r, rev[n - d]);
		D(cerr << "For largest " << d << " elements we have " << II(l, r) << "\n");
		int len = r - l + 1;
		int cel = 2 * d - 2;
		if (len <= cel) {
			int delta = cel - len;
			int r1 = min(n - 1, r + delta);
			int l1 = max(0, l - delta);
			D(cerr << I(len) << I(cel) << I(l1) << I(r1) << I(r1 - l1 - len + 2));
			ans += (r1 - l1 - cel + 2);
			D(cerr << "Length " << 2*d - 2 << " works for " << II(r1, l1) << "\n");
		}
		cel = 2 * d - 1;
		if (len <= cel) {
			int	delta = cel - len;
			int r1 = min(n - 1, r + delta);
			int l1 = max(0, l - delta);
			ans += (r1 - l1 - cel + 2);
			D(cerr << "Length " << 2*d - 1 << " works for " << II(r1, l1) << "\n");
		}
	}
	cout << 2 * n + 1 << " " << ans << "\n";
}