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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dlg (r-l+1)

// struct hash_pair {
//   int operator() (const pair<int, int> &p) const{
//     auto h1 = hash<int>{}(p.first);
//     auto h2 = hash<int>{}(p.second);
//     return h1 ^ h2;
//   }
// };

int n, spos;
vector<int> a, med;
set<pair<int, int>> s;

bool e(int x){
  return (x >= 1 && x <= n);
}

void foo(int l, int r, bool parz, int med, int mx_excl){
  if(s.count({l, r}))
    return;
  s.insert({l, r});

  if(mx_excl < med){
    spos++;
    // cout << spos << ": " << l << " " << r << "\n";
  }

  if(a[r] < med && e(l-1) && (a[l-1] < med || (a[l-1] == med && mx_excl == med)) && ((a[l-1] == med && mx_excl == med) || (mx_excl < med))){
    foo(l-1, r-1, parz, med, med-1);
    // cout << spos << ": " << l-1 << " " << r-1 << "\n";
  }
  if(a[l] < med && e(r+1) && (a[r+1] < med || (a[r+1] == med && mx_excl == med)) && ((a[r+1] == med && mx_excl == med) || (mx_excl < med))){
    foo(l+1, r+1, parz, med, med-1);
    // cout << spos << ": " << l+1 << " " << r+1 << "\n";
  }
  if(l == r)
    return;

  if(parz)
    med++;
  if(a[l] < med){
    foo(l+1, r, !parz, med, max(mx_excl, a[l]));
  }
  if(a[r] < med){
    foo(l, r-1, !parz, med, max(mx_excl, a[r]));
  }

  if(a[r] >= med && a[l] >= med){
    if(a[l] > a[r])
      foo(l, r-1, !parz, med, max(mx_excl, a[r]));
    else
      foo(l+1, r, !parz, med, max(mx_excl, a[l]));
  }
    

}

int main(){
  fastio;
  cin >> n;
  a.resize(n+1);
  med.resize(n+1);

  int m = n;
  for(int i = 1; i <= n; i++){
    med[i] = m;
    if(i % 2 == 1)
      m--;
  }

  for(int i = 1; i <= n; i++)
    cin >> a[i];

  spos = 0;
  foo(1, n, !(n&1), n/2 + n%2, 0);

  cout << 2*n+1 << " " << spos << "\n";
}