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

const int MAX = 1000009;
int A[MAX];
int P[MAX];

bool add(int& l, int& r, int v) {
  if (v >= l && v <= r) return false;
  l = std::min(l, v);
  r = std::max(r, v);
  return true;
}

int main() {
  std::ios_base::sync_with_stdio(0);
  int n;
  std::cin >> n;
  for (int i=0;i<n;++i) {
    std::cin >> A[i];
    P[A[i]] = i;
  }
  long sum = 1;
  int l,r;
  l = r = P[n];
  add(l, r, P[n-1]);
  if (r-l+1 == 2) ++sum;
  int k = 2;
  for (int len=3;len<=n;++len) {
    int slen = len/2+1;
    int mlen = len - slen;
    if (slen > k) {
      add(l, r, P[n-k]);
      ++k;
    }
    int rlen = r-l+1;
    int miss = len - rlen;
    if (miss < 0) continue;
    int ll = std::min(miss, l);
    int rr = std::min(miss, n-r-1);
    sum += ll+rr-miss + 1;
  }
  std::cout << 2*n+1 << " " << sum << std::endl;
  return 0;
}