Language: C++

using namespace std;

int main(){
  int N; 
  cin >> N;

  vector<int> v(N);
  for(int i = 0; i<N; ++i){
    cin >> v[i];
  }

  vector<int> v2(N);
  for(int i=0; i<N; ++i){
    v2[i] = v[i] - (i+1);
  }

  double ave = accumulate(v2.begin(), v2.end(), 0) / double(N);
//   cout << "ave: " << ave << endl;
  int num_ceil = ceil(ave);
  int num_floor = floor(ave);
 
//   for (int b =-10; b < 10; ++b ){
//   int sum_test = 0;
//   for(int i=0; i < N; ++i){
//     sum_test += abs(v2[i]- b);
//   } 
//   cout << "b: "<< b << "sum: " << sum_test << endl;
//   }
//
  int sum_floor = 0;
  for(int i=0; i < N; ++i){
    sum_floor += abs(v2[i]-num_floor);
  }
  int sum_ceil = 0;
  for(int i=0; i < N; ++i){
    sum_ceil += abs(v2[i]-num_ceil);
  }
//   cout << "ceil, fllor" << num_ceil << " " << num_floor << endl;
//   cout << "sum ceil, sum fllor" << sum_ceil << " " << sum_floor << endl;
  cout << min(sum_ceil, sum_floor) << endl;
return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:5:3: error: 'cin' was not declared in this scope
    5 |   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:7:3: error: 'vector' was not declared in this scope
    7 |   vector<int> v(N);
      |   ^~~~~~
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:7:10: error: expected primary-expression before 'int'
    7 |   vector<int> v(N);
      |          ^~~
a.cc:9:12: error: 'v' was not declared in this scope
    9 |     cin >> v[i];
      |            ^
a.cc:12:10: error: expected primary-expression before 'int'
   12 |   vector<int> v2(N);
      |          ^~~
a.cc:14:5: error: 'v2' was not declared in this scope
   14 |     v2[i] = v[i] - (i+1);
      |     ^~
a.cc:14:13: error: 'v' was not declared in this scope
   14 |     v2[i] = v[i] - (i+1);
      |             ^
a.cc:17:27: error: 'v2' was not declared in this scope
   17 |   double ave = accumulate(v2.begin(), v2.end(), 0) / double(N);
      |                           ^~
a.cc:17:16: error: 'accumulate' was not declared in this scope
   17 |   double ave = accumulate(v2.begin(), v2.end(), 0) / double(N);
      |                ^~~~~~~~~~
a.cc:19:18: error: 'ceil' was not declared in this scope
   19 |   int num_ceil = ceil(ave);
      |                  ^~~~
a.cc:20:19: error: 'floor' was not declared in this scope
   20 |   int num_floor = floor(ave);
      |                   ^~~~~
a.cc:32:18: error: 'abs' was not declared in this scope
   32 |     sum_floor += abs(v2[i]-num_floor);
      |                  ^~~
a.cc:36:17: error: 'abs' was not declared in this scope
   36 |     sum_ceil += abs(v2[i]-num_ceil);
      |                 ^~~
a.cc:40:3: error: 'cout' was not declared in this scope
   40 |   cout << min(sum_ceil, sum_floor) << endl;
      |   ^~~~
a.cc:40:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:40:11: error: 'min' was not declared in this scope; did you mean 'main'?
   40 |   cout << min(sum_ceil, sum_floor) << endl;
      |           ^~~
      |           main
a.cc:40:39: error: 'endl' was not declared in this scope
   40 |   cout << min(sum_ceil, sum_floor) << 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;