Language: C++

#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long A[100001],B[100001],C[100001],S,T;

int main(){
  int i,N;
  cin >> N;
  for (i=0;i<N;++i) {
    cin >> A[i];
  }
  sort(A, A+N);
  for (i=0;i<N/2;++i) {
    B[2*i+1]=A[i];
  }
  B[0]=A[N/2];
  if (N%2==1) {
    B[N-1]=A[N/2 +1];
  } else {
    B[N-2]=A[N/2 +1];
  }
  for (i=1;N/2 + i+1 < N;++i) {
    B[2*i]=A[N/2 + i+1];
  }

  for (i=0;i<N/2;++i) {
    C[2*i+1]=A[N-1-i];
  }
  C[0]=A[N-1-N/2];
  if (N%2==1) {
    C[N-1]=A[N-1-(N/2 +1)];
  } else {
    C[N-2]=A[N-1-(N/2 +1)];
  }
  for (i=1;N/2 + i+1 < N;++i) {
    C[2*i]=A[N-1-(N/2 + i+1)];
  }
  S=0;
  T=0;
  for (i=0;i<N-1;++i) {
    S+=abs(B[i+1] - B[i]);
    T+=abs(C[i+1] - C[i]);
  }
  cout << max(S,T) << endl; 
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:11: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
   43 |     S+=abs(B[i+1] - B[i]);
      |        ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/ext/string_conversions.h:43,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:44:11: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
   44 |     T+=abs(C[i+1] - C[i]);
      |        ~~~^~~~~~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~