Language: C++

#include <deque>
#include <algorithm>
#include <iostream>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int32 N;
vector<int64> A;

int main(void){
	cin >> N;
	A.resize(N);
	REP(i, N) cin >> A[i];
	sort(all(A));
	deque<int64> res;
	int32 l = 0, r = N-1;
	bool isl = 1;
	while(l < r){
		int32& p = isl ? l : r;
		int32& sa = isl ? 1 : -1;
		if(res.size() == 0){
			if(isl) res.push_back(A[l++]);
			else res.push_back(A[r--]);
		}else{
			if(abs(res.front()-A[p]) > abs(res.back()-A[p])){
				res.push_front(A[p]);
				p += sa;
			}else{
				res.push_back(A[p]);
				p += sa;
			}
		}
		isl = !isl;
	}
	int64 ret = 0;
	REP(i, N-1){
		ret += abs(res[i+1]-res[i]);
	}
	cout << ret << endl;
}


Compiler output:
a.cc:14:15: error: 'int_fast32_t' does not name a type
   14 | using int32 = int_fast32_t;
      |               ^~~~~~~~~~~~
a.cc:15:16: error: 'uint_fast32_t' does not name a type
   15 | using uint32 = uint_fast32_t;
      |                ^~~~~~~~~~~~~
a.cc:16:15: error: 'int_fast64_t' does not name a type
   16 | using int64 = int_fast64_t;
      |               ^~~~~~~~~~~~
a.cc:17:16: error: 'uint_fast64_t' does not name a type
   17 | using uint64 = uint_fast64_t;
      |                ^~~~~~~~~~~~~
a.cc:18:18: error: 'int32' was not declared in this scope; did you mean 'int32_t'?
   18 | using PII = pair<int32, int32>;
      |                  ^~~~~
      |                  int32_t
a.cc:18:25: error: 'int32' was not declared in this scope; did you mean 'int32_t'?
   18 | using PII = pair<int32, int32>;
      |                         ^~~~~
      |                         int32_t
a.cc:18:30: error: template argument 1 is invalid
   18 | using PII = pair<int32, int32>;
      |                              ^
a.cc:18:30: error: template argument 2 is invalid
a.cc:19:18: error: 'int64' was not declared in this scope; did you mean 'int64_t'?
   19 | using PLL = pair<int64, int64>;
      |                  ^~~~~
      |                  int64_t
a.cc:19:25: error: 'int64' was not declared in this scope; did you mean 'int64_t'?
   19 | using PLL = pair<int64, int64>;
      |                         ^~~~~
      |                         int64_t
a.cc:19:30: error: template argument 1 is invalid
   19 | using PLL = pair<int64, int64>;
      |                              ^
a.cc:19:30: error: template argument 2 is invalid
a.cc:26:1: error: 'int32' does not name a type; did you mean 'int32_t'?
   26 | int32 N;
      | ^~~~~
      | int32_t
a.cc:27:1: error: 'vector' does not name a type
   27 | vector<int64> A;
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:30:16: error: 'N' was not declared in this scope
   30 |         cin >> N;
      |                ^
a.cc:31:9: error: 'A' was not declared in this scope
   31 |         A.resize(N);
      |         ^
a.cc:8:23: error: 'int64' was not declared in this scope; did you mean 'int64_t'?
    8 | #define REP(i, n) for(int64 i = 0;i < (n);i++)
      |                       ^~~~~
a.cc:32:9: note: in expansion of macro 'REP'
   32 |         REP(i, N) cin >> A[i];
      |         ^~~
a.cc:32:13: error: 'i' was not declared in this scope
   32 |         REP(i, N) cin >> A[i];
      |             ^
a.cc:8:35: note: in definition of macro 'REP'
    8 | #define REP(i, n) for(int64 i = 0;i < (n);i++)
      |                                   ^
a.cc:34:15: error: 'int64' was not declared in this scope; did you mean 'int64_t'?
   34 |         deque<int64> res;
      |               ^~~~~
      |               int64_t
a.cc:34:20: error: template argument 1 is invalid
   34 |         deque<int64> res;
      |                    ^
a.cc:34:20: error: template argument 2 is invalid
a.cc:35:9: error: 'int32' was not declared in this scope; did you mean 'int32_t'?
   35 |         int32 l = 0, r = N-1;
      |         ^~~~~
      |         int32_t
a.cc:37:15: error: 'l' was not declared in this scope
   37 |         while(l < r){
      |               ^
a.cc:37:19: error: 'r' was not declared in this scope
   37 |         while(l < r){
      |                   ^
a.cc:38:24: error: 'p' was not declared in this scope
   38 |                 int32& p = isl ? l : r;
      |                        ^
a.cc:39:24: error: 'sa' was not declared in this scope; did you mean 'sc'?
   39 |                 int32& sa = isl ? 1 : -1;
      |                        ^~
      |                        sc
a.cc:40:24: error: request for member 'size' in 'res', which is of non-class type 'int'
   40 |                 if(res.size() == 0){
      |                        ^~~~
a.cc:41:37: error: request for member 'push_back' in 'res', which is of non-class type 'int'
   41 |                         if(isl) res.push_back(A[l++]);
      |                                     ^~~~~~~~~
a.cc:42:34: error: request for member 'push_back' in 'res', which is of non-class type 'int'
   42 |                         else res.push_back(A[r--]);
      |                                  ^~~~~~~~~
a.cc:44:36: error: request for member 'front' in 'res', which is of non-class type 'int'
   44 |                         if(abs(res.front()-A[p]) > abs(res.back()-A[p])){
      |                                    ^~~~~
a.cc:44:60: error: request for member 'back' in 'res', which is of non-class type 'int'
   44 |                         if(abs(res.front()-A[p]) > abs(res.back()-A[p])){
      |                                                            ^~~~
a.cc:45:37: error: request for member 'push_front' in 'res', which is of non-class type 'int'
   45 |                                 res.push_front(A[p]);
      |                                     ^~~~~~~~~~
a.cc:48:37: error: request for member 'push_back' in 'res', which is of non-class type 'int'
   48 |                                 res.push_back(A[p]);
      |                                     ^~~~~~~~~
a.cc:54:14: error: expected ';' before 'ret'
   54 |         int64 ret = 0;
      |              ^~~~
      |              ;
a.cc:55:13: error: expected ';' before 'i'
   55 |         REP(i, N-1){
      |             ^
a.cc:8:29: note: in definition of macro 'REP'
    8 | #define REP(i, n) for(int64 i = 0;i < (n);i++)
      |                             ^
a.cc:55:13: error: 'i' was not declared in this scope
   55 |         REP(i, N-1){
      |             ^
a.cc:8:35: note: in definition of macro 'REP'
    8 | #define REP(i, n) for(int64 i = 0;i < (n);i++)
      |                                   ^
a.cc:56:17: error: 'ret' was not declared in this scope; did you mean 'res'?
   56 |                 ret += abs(res[i+1]-res[i]);
      |                 ^~~
      |                 res
a.cc:58:17: error: 'ret' was not declared in this scope; did you mean 'res'?
   58 |         cout << ret << endl;
      |                 ^~~
      |                 res