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
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> p(n), r(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    --p[i];
    r[p[i]] = i;
  }
  int64_t c = 1;
  int lo = r[n - 1], hi = r[n - 1];
  for (int l = 2; l <= n; ++l) {
    if (l % 2 == 0) {
      lo = min(lo, r[n - (l / 2) - 1]);
      hi = max(hi, r[n - (l / 2) - 1]);
    }
    int min_i = max(0, hi - l + 1);
    int max_i = min(n - l, lo);
    if (min_i <= max_i)
      c += (max_i - min_i + 1);
  }
  cout << 2 * n + 1 << ' ' << c << endl;
}