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
//  Created by Michal Kowalski on 09/12/2021.
//

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

int N;
int T[1000001];

long long countF = 0;
int maxF = 0;

void check(std::vector<int> & v) {
    int vsize = v.size();
    double median = 0.0;
    if (vsize % 2 == 0) {
        int i = vsize/2;
        median = (v[i-1] + v[i])/2.0;
    } else {
        int i = vsize/2;
        median =  v[i];
    }
    int f = vsize + (int)(2.0*median);
    if (maxF == f) {
        ++countF;
    }
}

int main() {
    scanf("%d",&N);
    int maxPos = -1;
    for (int i=0;i<N;++i) {
        scanf("%d",&T[i]);
        if (T[i] == N) maxPos = i;
    }
    maxF = 1+2*N;
    for (int l=0;l<=maxPos;++l) {
        std::vector<int> v;
        v.insert(v.end(), &T[l], &T[maxPos+1]);
        std::sort(v.begin(), v.end());
        check(v);
        for (int i=1;maxPos+i<N;++i) {
            int val = T[maxPos+i];
            std::vector<int>::iterator it = std::lower_bound(v.begin(), v.end(), val);
            v.insert(it, val);
            check(v);
        }
    }
    printf("%d %lld\n",maxF, countF);
    return 0;
}