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 <algorithm>
#include <iostream>
using namespace std;

const int MAXN = 1000000;
const int INF = 2000000000;

#define FOR(i, n) for(int i = 0, __n = (n); i < __n; i++)

int t[MAXN];

int pos[MAXN + 1];

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

  int n; cin >> n;
  FOR(i, n) {
    cin >> t[i];
    pos[t[i]] = i;
  }

  int a = pos[n], b = pos[n]+1;
  long long sum = 0;
  for(int k = 1; k<=n; k++) {
    if(k%2 == 0) {
      int p = pos[n-k/2];
      if(p < a) a = p;
      if(p + 1 > b) b = p +1;
    }
    // cerr << k << ") " << a <<"," << b << " " << b-a << endl;
    if(k >= b-a) {
      
      int a1 = max(0, b - k);
      int b1 = min(n, a + k);
      sum += 1 + b1-(a1 + k);
      // cerr << a1 << " " << b1 << " " << sum << endl;
    }
  }
  


  cout << 2*n+1 << " " << sum << endl;
}