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
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=1e6+5;
int a[MAX];
int pos[MAX];

int solve(int s1,int s2,int wloz){
	int potrzebuje=max(0LL,wloz-s2);
	//cout<<"BEFORE "<<s1<<" "<<s2<<" "<<wloz<<"\n";
	s1-=potrzebuje;
	wloz-=potrzebuje;
	int ip=0,ik=s1+1;
	while (ip+1<ik){
		int mid=(ip+ik)>>1;
		int biore2=wloz-mid;
		if (biore2>=0)ip=mid;
		else ik=mid;
	}
	//cout<<"AFTER "<<ip<<"\n";
	return ip+1;
}
int32_t main(){
  BOOST;
  int n;
  cin>>n;
  for (int i=1;i<=n;i++)cin>>a[i],pos[a[i]]=i;
  int ans1=2LL*n+1,ans2=0;
  int mini=-1,maxi=-1;
  int wsk=n;
  for (int i=n;i>=1;i--){
		int median=(i+n)/2;
		while (wsk>=median){
			if (mini==-1)mini=pos[wsk],maxi=pos[wsk];
			else mini=min(mini,pos[wsk]),maxi=max(maxi,pos[wsk]);
			wsk--;
		}
	//	cout<<"TERAZ "<<i<<" "<<median<<" "<<mini<<" "<<maxi<<"\n";
    int len=n-i+1;
    if (maxi-mini+1>len)continue;
    int slots=len-(maxi-mini+1);
    ans2+=solve(mini-1,n-maxi,slots);
  }	
  cout<<ans1<<" "<<ans2;
  return 0; 
}