Language: C++

#include <bits/stdc++.h>

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};




int main(){
	llong int n, a[200001];
	int A=0, B=0, C=0, D=0;
	int ia, ib, ic, id;
	cin >> n;
	int maxNum = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		maxNum = max(maxNum, a[i]);
	}
	ia = -maxNum, id = maxNum, ib = 2*maxNum/3-maxNum, ic = 2*maxNum*2/3-maxNum;
	cerr << ia << " " << ib << " " << ic << " " << id << endl;
	for(int i = 1; i <= n; i++){
		A += abs(a[i] - (ia+i));
		B += abs(a[i] - (ib+i));
		C += abs(a[i] - (ic+i));
		D += abs(a[i] - (id+i));
	}
	bool fa, fd;
	while(true){
		fa=false, fd=false;
		cerr << ia << " " << ib << " " << ic << " " << id << endl;
		cerr << A  << " " << B <<  " " << C << " " << D << endl<<endl;
		if(ib == ic && ib-ia == 1 && id-ic == 1) break;
		if(ib>ic)break; 
		if(B<C){
			id = ic;
			D = C;
		}else if(B>C){
			ia = ib;
			A = B;
		}else{
			if(A<D){
				id--;
				D=0;
				fd++;
			}else if(A>D){
				ia++;
				A=0;
				fa++;
			}else{
				if(id-ic>ib-ia){
					id--;
					D=0;
					fd++;
				}else{
					ia++;
					A=0;
					fa++;
				}
			}
		}
		ib = max(ia+1,ia+(id-ia)/3);
		ic = min(id-1, id-(id-ia)/3);
		B = 0;
		C = 0;
		for(int i = 1; i <= n; i++){
			if(fa) A +=abs(a[i] - (i+ia));
			B += abs(a[i] - (i+ib));
			C += abs(a[i] - (i+ic));
			if(fd) D += abs(a[i] - (i+id));
		}
	}

	cout << min(min(A,B),min(C,D)) << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:31:29: error: no matching function for call to 'max(int&, long long int&)'
   31 |                 maxNum = max(maxNum, a[i]);
      |                          ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:31:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   31 |                 maxNum = max(maxNum, a[i]);
      |                          ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:31:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |                 maxNum = max(maxNum, a[i]);
      |                          ~~~^~~~~~~~~~~~~~
a.cc:58:33: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   58 |                                 fd++;
      |                                 ^~
a.cc:62:33: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   62 |                                 fa++;
      |                                 ^~
a.cc:67:41: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   67 |                                         fd++;
      |                                         ^~
a.cc:71:41: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   71 |                                         fa++;
      |                                         ^~