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
#include <iostream>
#include <vector>

using namespace std;

bool debug = false;


void printHurray(int a[], int l, int r) {
    cout << "!! hurray: ";
    for (int i = l+1; i < r; i++) { 
        cout << a[i] << " ";
    }
    cout << endl;
}

int main()
{
    int n;
    cin >> n;

    int *abcd = new int[n];

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

    int ways = 0;

    int median2 = n + 1;
    int goal = median2 + n;
    int mutableMedian2 = median2;

    for (int l = -1; l < n; l++)
    {
                    // if (debug)
                    //     cout << "l: " << l << endl;
        if (l != -1 && abcd[l] * 2 >= mutableMedian2)
        {
            // if (debug)
            //     cout << "l: abcd[" << l << "] is more than " << mutableMedian2 / 2.0 << ", breaking" << endl;
            break;
        }
        else
        {
            if (l != -1)
                mutableMedian2+=1;
            for (int r = n; r > l + 2; r--)
            {
                    // if (debug)
                    //     cout << "l: " << l << ", r: " << r << endl;
                if (r != n && abcd[r] * 2 >= mutableMedian2)
                {
                    // if (debug)
                    //     cout << "r: abcd[" << r - 1 << "] is more than " << mutableMedian2 / 2.0 << ", breaking" << endl;
                    mutableMedian2-=(n-r-1);
                    break;
                }
                else
                {
                    if (r != n)
                        mutableMedian2+=1;
                    int length = r - l - 1;
                    // if (debug)
                    //     cout << "[" << l << "," << r << "] length: " << length << ", mutableMedian2: " << mutableMedian2 << endl;
                    if (mutableMedian2 + length == goal)
                    {
                        // if (debug) printHurray(abcd, l, r);
                        ways++;
                    }
                }
            }
        }
    }

    cout << goal << " " << ways + 1;

}