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

int main ()
{
  int n;
  scanf ("%i", &n);
  int a, I[n/2+1];
  for (int i=0; i<n; i++)
  {
    scanf ("%i", &a);
    if (a>=n/2) I[n-a] = i;
  }
  int p = I[0], q = I[0];
  long long s = 1;
  for (int l=2; l<=n; l++)
  {
    int r = I[l/2];
    p -= (p>r)*(p-r);
    q += (r>q)*(r-q);
    int k = n-(n>p+l)*(n-p-l) - q-(l-1>q)*(l-1-q);
    s += (k>0)*k;
  }
  printf ("%i %lli\n", n+n+1, s);
  return 0;
}