Language: C++

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  long long a, b;
  a = b = 0;
  long long f, g;
  f = g = 0;
  vector<int> c(n), d, e;
  for(int i = 0; i < n; i++)
    cin >> c[i];
  sort(c.begin(), c.end);
  if(n % 2 == 0){
    for(int i = 0; i < n; i++){
      if(i * 2 < n)
        d.push_back(c[i]);
      else
        e.push_back(c[i]);
    }
    for(int i = 0; i < n / 2; i++){
      a += e[i];
      b += d[i];
      if(i != 0)
        a += e[i];
      if(i != n / 2 - 1)
        b += d[i];
    }
    cout << a - b << endl;
    return 0;
  }
  for(int i = 0; i < n; i++){
    if(i < n / 2){
      a += c[i] * 2;
      b += c[i] * 2;
    }
    else{
      f += c[i] * 2;
      g += c[i] * 2;
    }
  }
  f -= c[n / 2];
  f -= c[n / 2 + 1];
  b -= c[n / 2 - 1];
  b += c[n / 2];
  g -= c[n / 2] * 2;
  cout << max(a - f, b - g) << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:7: error: no matching function for call to 'sort(std::vector<int>::iterator, <unresolved overloaded function type>)'
   14 |   sort(c.begin(), c.end);
      |   ~~~~^~~~~~~~~~~~~~~~~~
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:4762:5: note: candidate: 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4762:63: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >'
 4762 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |                                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note: candidate: 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
 4793 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:4793:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare)'
  292 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:292:1: note:   candidate expects 4 arguments, 2 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note: candidate: 'template<class _ExecutionPolicy, class _RandomAccessIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::sort(_ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator)'
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:296:1: note:   candidate expects 3 arguments, 2 provided