Language: C++

using namespace std;

long    Cal(vector<long> &A, long b) {
        long S=0;
        for (int i=1; i<A.size(); i++) {
                S += abs(A.at(i)-(b+i));
        }
        return S;
}

int     main() {
        int N;
        cin >>N;
        vector<long> A(N+1, 0);
        for (int i=1; i<=N; i++) {
                cin >>A.at(i);
        }
        vector<long> B;
        B=A;
        sort(B.begin(), B.end());
        long b1=B.at(N/2);
        while (true) {
                long b0=b1-1;
                long b2=b1+1;
                long S0=Cal(A, b0);
                long S1=Cal(A, b1);
                long S2=Cal(A, b2);
                if (S1==min(S0, min(S1, S2))) break;
                if (S2<S1) b1=b2;
                else b1=b0;
        }
        cout <<Cal(A, b1) <<endl;
        return 0;
};

Compiler output:
a.cc:3:13: error: 'vector' was not declared in this scope
    3 | long    Cal(vector<long> &A, long b) {
      |             ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:3:20: error: expected primary-expression before 'long'
    3 | long    Cal(vector<long> &A, long b) {
      |                    ^~~~
a.cc:3:30: error: expected primary-expression before 'long'
    3 | long    Cal(vector<long> &A, long b) {
      |                              ^~~~
a.cc:3:36: error: expression list treated as compound expression in initializer [-fpermissive]
    3 | long    Cal(vector<long> &A, long b) {
      |                                    ^
a.cc: In function 'int main()':
a.cc:13:9: error: 'cin' was not declared in this scope
   13 |         cin >>N;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:14:9: error: 'vector' was not declared in this scope
   14 |         vector<long> A(N+1, 0);
      |         ^~~~~~
a.cc:14:9: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:14:16: error: expected primary-expression before 'long'
   14 |         vector<long> A(N+1, 0);
      |                ^~~~
a.cc:16:23: error: 'A' was not declared in this scope
   16 |                 cin >>A.at(i);
      |                       ^
a.cc:18:16: error: expected primary-expression before 'long'
   18 |         vector<long> B;
      |                ^~~~
a.cc:19:9: error: 'B' was not declared in this scope
   19 |         B=A;
      |         ^
a.cc:19:11: error: 'A' was not declared in this scope
   19 |         B=A;
      |           ^
a.cc:20:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   20 |         sort(B.begin(), B.end());
      |         ^~~~
      |         short
a.cc:25:28: error: 'Cal' cannot be used as a function
   25 |                 long S0=Cal(A, b0);
      |                         ~~~^~~~~~~
a.cc:26:28: error: 'Cal' cannot be used as a function
   26 |                 long S1=Cal(A, b1);
      |                         ~~~^~~~~~~
a.cc:27:28: error: 'Cal' cannot be used as a function
   27 |                 long S2=Cal(A, b2);
      |                         ~~~^~~~~~~
a.cc:28:33: error: 'min' was not declared in this scope; did you mean 'main'?
   28 |                 if (S1==min(S0, min(S1, S2))) break;
      |                                 ^~~
      |                                 main
a.cc:28:25: error: 'min' was not declared in this scope; did you mean 'main'?
   28 |                 if (S1==min(S0, min(S1, S2))) break;
      |                         ^~~
      |                         main
a.cc:32:9: error: 'cout' was not declared in this scope
   32 |         cout <<Cal(A, b1) <<endl;
      |         ^~~~
a.cc:32:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:32:19: error: 'Cal' cannot be used as a function
   32 |         cout <<Cal(A, b1) <<endl;
      |                ~~~^~~~~~~
a.cc:32:29: error: 'endl' was not declared in this scope
   32 |         cout <<Cal(A, b1) <<endl;
      |                             ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;