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
#include <bits/stdc++.h>
#define gc getchar
#define gcu getchar_unlocked
#define fi first
#define se second
#define pb push_back
#define mod ((ll)1e9 + 7)
typedef long long ll;
using namespace std;
//=============================================

int n, mini, maxi;
ll ans = 1;
int a[1000009];

//=============================================
int main()
{
	scanf("%d", &n);
	for (int i = 0, temp; i < n; i++)
		scanf("%d", &temp), a[temp] = i;
	mini = maxi = a[n];
	for (int i = 2; i <= n; i++)
		ans += max(min((mini = min(mini, a[n - i / 2])) + i - 1, n - 1) - max((maxi = max(maxi, a[n - i / 2])) - i + 1, 0) - i + 2, 0);
	printf("%d %lld\n", 2 * n + 1, ans);
}
//=============================================