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
#include <cstdio>
#include <algorithm>
#include <vector>
#include <time.h>
#define MAX_N 1000010
using namespace std;

int n;
int p[MAX_N], pos[MAX_N];

long long ile(int wyb, int lp, int rp) {
    //printf("- %d %d %d\n", wyb, lp, rp);
    if (wyb < 0) {
        return 0;
    }

    if (wyb == 0) {
        return 1;
    }

    return max(0, min(min(lp + 1, rp + 1), min(lp + rp - wyb + 1, wyb + 1)));
}

int main() {
    scanf("%d", &n);

    for (int i = 1; i <= n; i++) {
        scanf("%d", &p[i]);
        pos[p[i]] = i;
    }

    int wyn = n * 2 + 1;
    long long sp = 1;

    int l = pos[n], r = pos[n];

    for (int i = 2; i <= n / 2 + 1; i++) {
        //printf("\n\n%d:\n", i);

        int a = n - i + 1;
        //printf("A = %d\n", a);
        l = min(l, pos[a]);
        r = max(r, pos[a]);
        //printf("(%d-%d)\n", l, r);

        int inside = (r - l + 1) - i;

        // pomiedzy n-i+2 a n-i+1
        sp += ile(i - 2 - inside, l - 1, n - r);
        //printf("Pom: %lld\n", ile(i - 2 - inside, l - 1, n - r));

        // na n-i+1
        sp += ile(i - 1 - inside, l - 1, n - r);
        //printf("Na: %lld\n", ile(i - 1 - inside, l - 1, n - r));
    }

    printf("%d %lld\n", wyn, sp);
}