Language: C++

#include <utility>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

long shift(const vector<long>& A, long b)
{
  return accumulate(A.begin(), A.end(), 0l, [b](auto v, auto a) {
      return v + labs(a - b);
  });
}

int main()
{
  int N;
  cin >> N;
  vector<long> A(N, 0);
  long sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    A[i] -= i + 1;
    sum += A[i];
  }

  double mean = static_cast<double>(sum) / N;
  long upper = ceil(mean);
  long lower = floor(mean);

  long min_v = -1;
  for (long b = upper - 5; b <= upper + 5; ++b) {
    auto v = shift(A, b);
    if (min_v < 0 or min_v > v) min_v = v;
  }

  cout << min_v << endl;
  // cout << min(shift(A, upper), shift(A, lower)) << endl;
  return 0;
}


Compiler output:
a.cc:9:18: error: 'vector' does not name a type
    9 | long shift(const vector<long>& A, long b)
      |                  ^~~~~~
a.cc:9:24: error: expected ',' or '...' before '<' token
    9 | long shift(const vector<long>& A, long b)
      |                        ^
a.cc: In function 'long int shift(int)':
a.cc:11:21: error: 'A' was not declared in this scope
   11 |   return accumulate(A.begin(), A.end(), 0l, [b](auto v, auto a) {
      |                     ^
a.cc:11:46: error: 'b' was not declared in this scope
   11 |   return accumulate(A.begin(), A.end(), 0l, [b](auto v, auto a) {
      |                                              ^
a.cc: In lambda function:
a.cc:12:27: error: 'b' is not captured
   12 |       return v + labs(a - b);
      |                           ^
a.cc:11:47: note: the lambda has no capture-default
   11 |   return accumulate(A.begin(), A.end(), 0l, [b](auto v, auto a) {
      |                                               ^
a.cc:11:46: note: '<typeprefixerror>b' declared here
   11 |   return accumulate(A.begin(), A.end(), 0l, [b](auto v, auto a) {
      |                                              ^
a.cc: In function 'int main()':
a.cc:19:3: error: 'cin' was not declared in this scope
   19 |   cin >> N;
      |   ^~~
a.cc:6:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    5 | #include <numeric>
  +++ |+#include <iostream>
    6 | 
a.cc:20:3: error: 'vector' was not declared in this scope
   20 |   vector<long> A(N, 0);
      |   ^~~~~~
a.cc:6:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    5 | #include <numeric>
  +++ |+#include <vector>
    6 | 
a.cc:20:10: error: expected primary-expression before 'long'
   20 |   vector<long> A(N, 0);
      |          ^~~~
a.cc:23:12: error: 'A' was not declared in this scope
   23 |     cin >> A[i];
      |            ^
a.cc:34:20: error: 'A' was not declared in this scope
   34 |     auto v = shift(A, b);
      |                    ^
a.cc:38:3: error: 'cout' was not declared in this scope
   38 |   cout << min_v << endl;
      |   ^~~~
a.cc:38:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:38:20: error: 'endl' was not declared in this scope
   38 |   cout << min_v << endl;
      |                    ^~~~
a.cc:6:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    5 | #include <numeric>
  +++ |+#include <ostream>
    6 |