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
#include <bits/stdc++.h>
using namespace std;
long long n, a, t[1000001];

long long sum(long long n) {
  return n * (n + 1) / 2;
}

int main()
{
  ios_base::sync_with_stdio(0);

  cin >> n;

  for (long long i = 0; i < n; i++) {
    cin >> a;
    t[a] = i;
  }

  long long res = 0;
  long long l = t[n];
  long long r = t[n];

  for (long long dl = 1; dl <= n; dl++) {
    if (dl % 2 == 0) {
      long long i = n - (dl / 2);
      l = min(t[i], l);
      r = max(t[i], r);
    }

    long long najw = max(0LL, r - dl + 1);
    long long najp = min(l, n - dl);
    res += max(0LL, najp - najw + 1);
  }

  cout << n * 2 + 1 << " " << res << endl;

  return 0;
}