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
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <string>
#include <algorithm>
#define MAX 10000009

using namespace std;

// int result[MAX];
// int 
int grades[MAX], valPos[MAX];    
    
int main()
{
    // int n, m, q;
    // cin >> n >> m >> q;

    // string rules[n][m];
    // int repr[n+1][m+1];
    
    // for (int i=0; i<n; i++) {
    //     for (int j=0; j<m; j++) {
    //         cin >> rules[i][j];
    //     }
    // }
    
    
    // for (int i=0; i<=n; i++) {
    //     for (int j=0; j<=m; j++) {
    //         repr[i][j] = i * n + j;
    //         result[i][j] = 0;
    //     }
    // }
    
    // int round = 0;
    
    int n;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> grades[i];
        valPos[grades[i]] = i + 1;
    }
    
    int median = (n + 1) / 2;
    
    int count = 1, left = 0, right = n + 1, maxValPos = valPos[n], old;
    bool underMedianOnly = true;
    for (int i=1; i<n; i++) {
        // cout << i << " " << valPos[i] << "\n";
        if (valPos[i] < maxValPos) {
            old = left;
            left = max(left, valPos[i]);
            for (int k=old; k<left; k++) if (grades[k] >= median) {
                // cout << k << " " << grades[k] << " WTF\n";
                underMedianOnly = false;
            }
            // cout << "set left " << left << "\n";
        } else {
            old = right;
            right = min(right, valPos[i]);
            for (int k=old; k>=right; k--) if (grades[k] >= median) underMedianOnly = false;
            // cout << "set right " << right << "\n";
        }
        
        // cout << underMedianOnly << " <- underMedianOnly \n";
        
        if (left + (n + 1 - right) == i || underMedianOnly) {
            count++;
            if (underMedianOnly) count = (left + 1) * (n + 2 - right);
            // cout << "we got him! " << count << "\n";
        }
    }
    
    cout << 2 * n + 1 << " " << count;
}