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
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <numeric>
#include <cmath>

std::vector<int> getIndexes(const std::vector<int> &rates) {
  std::vector<int> idx(rates.size());
  std::iota(idx.begin(), idx.end(), 0);
  std::sort(idx.begin(), idx.end(),
       [&rates](int i1, int i2) {return rates[i1] > rates[i2];});

  return idx;
}
int main()
{
    std::ios_base::sync_with_stdio(false);
    int n;
    std::cin>>n;
    std::vector<int> rates(n,0);
    for(int i=0;i<n;++i)
    {
        std::cin>>rates[i];
    }

    const auto indexes = getIndexes(rates);
   // for(const auto& idx:indexes) std::cout<< idx<<" ";
    int minIndex=n, maxIndex=0;
    long long int sum =0;
    for(int i =0 ;i<n;++i)
    {
        int X =i+1, el = std::floor(X*0.5);
        minIndex = std::min(indexes[el], minIndex);
        maxIndex = std::max(indexes[el], maxIndex);
        if(maxIndex-minIndex+1 <= X)
        {
           // std::cout<<std::endl<<"X "<<X<<" minIndex "<<minIndex<<" "<<maxIndex<<std::endl;
            int last =std::min(minIndex, n-X), first = std::max(0,maxIndex-X+1);
           // std::cout<<"TYGRYS"<<first<<last<<std::endl;
            sum +=last-first+1;
            //std::cout<<sum<<std::endl;
        }
    }
    std::cout<<2*n+1<<" "<<sum<<std::endl;


    return 0;
}