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
//Mateusz Piórkowski
#include <iostream>
#include <vector>
#include <algorithm>

int get_median2x(std::vector<int> oceny){
	std::sort(oceny.begin(), oceny.end());
	int max_index = oceny.size()-1;
	int mid_value = oceny[max_index/2];
	if(max_index%2==0){
		return mid_value*2;
	}else{
		return mid_value+oceny[max_index/2+1];
	}
}

/*int get_median2x(std::vector<int> oceny, int i, int j){
	std::sort(oceny.begin()+i, oceny.begin()+j+1);
	int size=j-i+1;
	//int max_index = oceny.size()-1;
	int mid_value = oceny[(size-1)/2+i];
	//std::cout << "mid value: " << mid_value<<"\n";
	//std::cout << "mid value index: " << (size-1)/2+i << "\n";
	if((size-1)%2==0){ //has middle value
		//std::cout << "mid val\n";
		return mid_value*2;
	}else{
		//std::cout << "no mid val\n";
		return mid_value+oceny[(size-1)/2+1+i];
	}
}*/
int get_median2x(std::vector<int>& oceny, int a1, int a2){
	std::vector<int> oceny_sub;
	for(int i=a1; i<=a2; i++){
		oceny_sub.push_back(oceny[i]);
	}
	int med = get_median2x(oceny_sub);
	return med;
}
int get_target(std::vector<int>& oceny, int a1, int a2){
	std::vector<int> oceny_sub;
	for(int i=a1; i<=a2; i++){
		oceny_sub.push_back(oceny[i]);
	}
	int med = get_median2x(oceny_sub);
	return med+oceny_sub.size();
}

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

	int n;
	std::cin >> n;
	std::vector<int> oceny;
	int posmax=0;
	for(int i=0; i<n; i++){
		int ocena;
		std::cin >> ocena;
		if(ocena==n) posmax=i;
		oceny.push_back(ocena);
	}

	int max_target = get_target(oceny,0,oceny.size()-1);
	//std::cout << "max: " << max_target << "\n";
	//std::cout << median2x << "\n";
	
	//solve
	int output=0;
	for(int i=0; i!=posmax+1; i++){
		for(int j=n-1; j!=posmax-1; j--){
			int target = get_target(oceny,i,j);
			if(target>max_target){
				//std::cout << "wtf?!?! i=" << i << " j=" << j << "\n";
				exit(1);
			}
			if(target==max_target){
				output++;
			}
			//std::cout << i << "," << j << " = m:" << get_median2x(oceny,i,j) << " t:" << target <<"\n";
			//std::cout << "i:"<<i<<" j:" << j;
			/*if(median2x_needed[i]<=median2x_raised[j] && median2x_needed[j]<=median2x_raised[i]){
				output++;
				//std::cout << " +";
			}*/
			//std::cout << "\n";
		}
	}
	//std::cout << median2x+n << " " << output << "\n";
	std::cout << max_target << " " << output << "\n";
}