Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	long long A[100000];
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	sort(A,A+N);
	long long ans=0;
	if(N%2==1){
		if(N==3){
			cout<<A[1]-A[0]+A[2]-A[0]<<endl;
			return 0;
		}
		long long a=0;
		for(int i=0;i<N/2-1;i++){
			a+=A[i];
		}
		long long b=0;
		for(int i=N/2+1;i<N;i++){
			b+=A[i];
		}
		ans+=2*abs(a-b);
		ans-=(A[N/2-1]+A[N/2]);
		long long sum=0;
		a=0;b=0;
		reverse(A,A+N,A);
		for(int i=0;i<N/2-1;i++){
			a+=A[i];
		}
		for(int i=N/2+1;i<N;i++){
			b+=A[i];
		}
		ans+=2*abs(a-b);
		ans-=(A[N/2-1]+A[N/2]);
		ans=max(ans,sum);
	}else{
		long long B[100000];
		for(int i=0;i<N/2;i++){
			B[(N-1)-(i*2+1)]=A[i];
		}
		for(int i=0;i<N/2;i++){
			B[(N-1)-i*2]=A[i+N/2];
		}
		for(int i=0;i<N-1;i++){
			ans+=abs(B[i]-B[i+1]);
		}
	}
	cout<<abs(ans)<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:24: error: no matching function for call to 'reverse(long long int [100000], long long int*, long long int [100000])'
   29 |                 reverse(A,A+N,A);
      |                 ~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:1083:5: note: candidate: 'template<class _BIter> void std::reverse(_BIter, _BIter)'
 1083 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |     ^~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1083:5: note:   candidate expects 2 arguments, 3 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note: candidate: 'template<class _ExecutionPolicy, class _BidirectionalIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::reverse(_ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator)'
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15:
/usr/include/c++/14/pstl/execution_defs.h: In substitution of 'template<class _ExecPolicy, class _Tp> using __pstl::__internal::__enable_if_execution_policy = typename std::enable_if<__pstl::execution::v1::is_execution_policy<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value, _Tp>::type [with _ExecPolicy = long long int (&)[100000]; _Tp = void]':
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1:   required by substitution of 'template<class _ExecutionPolicy, class _BidirectionalIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::reverse(_ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator) [with _ExecutionPolicy = long long int (&)[100000]; _BidirectionalIterator = long long int*]'
a.cc:29:10:   required from here
   29 |                 reverse(A,A+N,A);
      |                 ~~~~~~~^~~~~~~~~
/usr/include/c++/14/pstl/execution_defs.h:82:7: error: no type named 'type' in 'struct std::enable_if<false, void>'
   82 | using __enable_if_execution_policy =
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~