Language: C++

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  int n;
  cin >> n;
  vector<int>v(n);
  rep(i,n)cin >> v[i];
  sort(all(v));
  deque<int>d;
  rep(i,n){
    d.push_back(v[i]);
  }
  deque<int>check;
  check.push_back(d.front());
  d.pop_front;
  rep(i,n-1){
    if(i % 2 == 0){
      check.push_front(d.back());
      d.pop_back();
      if(i == n - 2)break;
      check.push_back(d.back());
      d.pop_back();
    }
    else{
      check.push_front(d.front());
      d.pop_front();
      if(i == n - 2)break;
      check.push_back(d.front());
      d.pop_front();
    }
  }
  ll ans = 0;
  int tmp = -1;
  for(auto i : check){
    if(tmp == -1)tmp = i;
    else{
      ans += abs(i - tmp);
      tmp = i;
    }
  }
  d.clear();
  check.clear;
  rep(i,n){
    d.push_back(v[i]);
  }
  check.push_back(d.back());
  d.pop_back;
  rep(i,n-1){
    if(i % 2 == 0){
      check.push_front(d.front());
      d.pop_front();
      if(i == n - 2)break;
      check.push_back(d.front());
      d.pop_front();
    }
    else{
      check.push_front(d.back());
      d.pop_back();
      if(i == n - 2)break;
      check.push_back(d.back());
      d.pop_back();
    }
  }
  ll anss = 0;
  tmp = -1;
  for(auto i : check){
    if(tmp == -1)tmp = i;
    else{
      anss += abs(i - tmp);
      tmp = i;
    }
  }
  cout << max(anss,ans) << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

Compiler output:
a.cc: In function 'int solve()':
a.cc:28:5: error: invalid use of non-static member function 'void std::deque<_Tp, _Alloc>::pop_front() [with _Tp = int; _Alloc = std::allocator<int>]'
   28 |   d.pop_front;
      |   ~~^~~~~~~~~
In file included from /usr/include/c++/14/deque:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:139,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_deque.h:1574:7: note: declared here
 1574 |       pop_front() _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~
a.cc:55:9: error: invalid use of non-static member function 'void std::deque<_Tp, _Alloc>::clear() [with _Tp = int; _Alloc = std::allocator<int>]'
   55 |   check.clear;
      |   ~~~~~~^~~~~
/usr/include/c++/14/bits/stl_deque.h:1835:7: note: declared here
 1835 |       clear() _GLIBCXX_NOEXCEPT
      |       ^~~~~
a.cc:60:5: error: invalid use of non-static member function 'void std::deque<_Tp, _Alloc>::pop_back() [with _Tp = int; _Alloc = std::allocator<int>]'
   60 |   d.pop_back;
      |   ~~^~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:1597:7: note: declared here
 1597 |       pop_back() _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~