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
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <queue>



using namespace std;


int a[1000000+2];

int main(){
	int n;
	cin >> n;
	int x;
	for(int i = 1; i <= n; ++i){
		cin >> x;
		a[x]=i;
	}
	long long int wynik = 1;
	int i = n;
	int start = a[n];
	int stop = a[n];
	int size = 1;
	long long int sum = n;
	long long int med = n;
	long long int war = (n+1)/2 + (n+1)%2;
	while(i >= war){
		//cout << "start: " << start << " stop: " << stop << " i: " << i << " med: " << med << " sum: " << sum << " wynik: " << wynik << "\n";
		int size_prev = size;
		if(a[i] > start && a[i] < stop){
			if(med < i+1){
				wynik++;
			}
		}else{
			if(a[i] < start){
				size += start - a[i];
				start = a[i];			
			}
			if(a[i] > stop){
				size += a[i] - stop; 
				stop = a[i];
			}
			if(size_prev < size){
				sum = (n*(n+1))/2 - ((n-size)*(n-size+1))/2;
				med=sum/size;
				if(med >= i){
					wynik++;
				}
			}
		}
		i--;
	}
	//cout << "start: " << start << " stop: " << stop << " i: " << i << " med: " << med << " sum: " << sum << " wynik: " << wynik << "\n";
	wynik+=start*(n-stop+1)-1;
	
	cout << 2*n+1 << " " << wynik << "\n";
	
	return 0;
}