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
95
96
#include <iostream>
using namespace std;
int tab[1000005] {};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

long long med,ile=2,med2=0,n;
bool z=1;

cin>>n;

for (int i=0;i<n;i++)
{cin>>tab[i];}

if (n==1) 
{cout<<"3 1";
return 0;}

med=n+1;

for (int i=0;i<n-2;i++)
{
if (tab[i]*2<med)
	{//ile++;
	med++;}
	else if (tab[i]*2>med)
	{med--;}
   if (med+n-i-1==(2*n)+1) {ile++;}
	else {
	if (tab[i]>tab[i+1]) {med++;}
	else {med--;}
	}

}

med=n+1;

for (int i=n-1;i>1;i--)
{
	if (tab[i]*2<med)
	{//ile++;
	med++;}
	else if (tab[i]*2>med)
	{med--;}
	if ((med+i)==(2*n)+1) {ile++;}
else {
	if (tab[i]>tab[i+1]) {med2++;}
	else {med2--;}
	}
	

}
med=n+1;

for (int i=0;i<n-3;i++)
{
	if (tab[i]*2<med)
	{med++;
	med2=med;}
	else if (tab[i]*2>med)
	{med--;
	med2=med;}
	else {
		cout<<tab[i]<<endl;
	if (tab[i]>tab[i+1]) 
	{med2=med;
	med++;}
	else 
	{med2=med;
	med--;}
	}
for (int j=n-1;j>i+2;j--)
{
	
	if (tab[j]*2<med2)
	{
	med2++;}
	else if (tab[j]*2>med2)
	{med2--;}
	else {
	if (tab[j]>tab[j+1]) {med2++;}
	else {med2--;}
	}
	if (med2+j-i-1==(n*2)+1) {ile++;}
}


}

cout<<n+n+1<<" "<<ile;

return 0;
}