criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>
#include <math.h>


#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 998244353;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector <ll> a(n);
    REP(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    ll res1 = 0;
    ll res2 = 0;
    
    // パターン p1 ≥ p2 ≤ p3 ≥ ...
    ll right = a.size() - 1;
    ll left = 0;
    ll i = 0;
    while(right >= left)
    {
        if(i % 2 == 0)
        {
            //大きいものを2回足す
            res1 += 2 * a[right];
            --right;
        }
        else
        {
            //小さいものを2回ひかれる(0i0)
            res1 -= 2 * a[left];
            ++left;
        }
        ++i;
    }

    //全部2回ずつ足し引きしちゃってるので帳尻合わせ
    ll center = a.size() / 2;
    if(n % 2 == 0)
    {
        res1 -= a[center];//i%2 == 0の方
        res1 += a[center - 1];//i%2 == 1の方
    }
    else
    {
        //
        res1 -= a[center];
        res1 -= a[center + 1];//right側で*2しちゃっている
    }

    //パターンp1 ≤ p2 ≥ p3 ...
    ll right = a.size() - 1;
    ll left = 0;
    ll i = 0;
    while(right >= left)
    {
        if(i % 2 == 0)
        {
            //小さいものを2回ひかれる(0i0)
            res2 -= 2 * a[left];
            ++left;
        }
        else
        {
            //大きいものを2回足す
            res2 += 2 * a[right];
            --right;
        }
        ++i;
    }
    //全部2回ずつ足し引きしちゃってるので帳尻合わせ
    if(n % 2 == 0)
    {
        res2 -= a[center];//i%2 == 1の方
        res2 += a[center - 1];//i%2 == 0の方
    }
    else
    {
        res2 += a[center];
        res2 += a[center - 1];//left側で*2しちゃっている
    }

    cout << max(res1, res2) << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:62:8: error: redeclaration of 'll right'
   62 |     ll right = a.size() - 1;
      |        ^~~~~
a.cc:27:8: note: 'll right' previously declared here
   27 |     ll right = a.size() - 1;
      |        ^~~~~
a.cc:63:8: error: redeclaration of 'll left'
   63 |     ll left = 0;
      |        ^~~~
a.cc:28:8: note: 'll left' previously declared here
   28 |     ll left = 0;
      |        ^~~~
a.cc:64:8: error: redeclaration of 'll i'
   64 |     ll i = 0;
      |        ^
a.cc:29:8: note: 'll i' previously declared here
   29 |     ll i = 0;
      |        ^
Language: C++

#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>
#include <math.h>
#include <bitset/stdc++.h>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 998244353;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector <ll> a(n);
    REP(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    ll res1 = 0;
    ll res2 = 0;
    
    // パターン p1 ≥ p2 ≤ p3 ≥ ...
    ll right = a.size() - 1;
    ll left = 0;
    ll i = 0;
    while(right >= left)
    {
        if(i % 2 == 0)
        {
            //大きいものを2回足す
            res1 += 2 * a[right];
            --right;
        }
        else
        {
            //小さいものを2回ひかれる(0i0)
            res1 -= 2 * a[left];
            ++left;
        }
        ++i;
    }

    //全部2回ずつ足し引きしちゃってるので帳尻合わせ
    ll center = a.size() / 2;
    if(n % 2 == 0)
    {
        res1 -= a[center];//i%2 == 0の方
        res1 += a[center - 1];//i%2 == 1の方
    }
    else
    {
        //
        res1 -= a[center];
        res1 -= a[center + 1];//right側で*2しちゃっている
    }

    //パターンp1 ≤ p2 ≥ p3 ...
    ll right = a.size() - 1;
    ll left = 0;
    ll i = 0;
    while(right >= left)
    {
        if(i % 2 == 0)
        {
            //小さいものを2回ひかれる(0i0)
            res2 -= 2 * a[left];
            ++left;
        }
        else
        {
            //大きいものを2回足す
            res2 += 2 * a[right];
            --right;
        }
        ++i;
    }
    //全部2回ずつ足し引きしちゃってるので帳尻合わせ
    if(n % 2 == 0)
    {
        res2 -= a[center];//i%2 == 1の方
        res2 += a[center - 1];//i%2 == 0の方
    }
    else
    {
        res2 += a[center];
        res2 += a[center - 1];//left側で*2しちゃっている
    }

    cout << max(res1, res2) << endl;

    return 0;
}

Compiler output:
a.cc:8:10: fatal error: bitset/stdc++.h: No such file or directory
    8 | #include <bitset/stdc++.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

signed main() {}

int main(){
    int n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll pat1 = 0, pat2 = 0;
    if(n%2){
        //pattern1
        rep(i,n/2) pat1 += 2*a[n-i-1];
        rep(i,n/2-1) pat1 -= 2*a[i];
        pat1 -= (a[n/2-1]+a[n/2]);

        //pattern2
        rep(i,n/2-1) pat2 += 2*a[n-i-1];
        rep(i,n/2) pat2 -= 2*a[i];
        pat2 += (a[n/2] + a[n/2+1]);
    }else{
        rep(i,n/2-1) pat1 += 2*a[n-i-1];
        pat1 += a[n/2];
        rep(i,n/2-1) pat1 -= 2*a[i];
        pat1 -= a[n/2-1];
        pat2 = pat1;
    }
    cout << max(pat1, pat2) << endl;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
a.cc:25:5: error: redefinition of 'int main()'
   25 | int main(){
      |     ^~~~
a.cc:23:8: note: 'int main()' previously defined here
   23 | signed main() {}
      |        ^~~~
Language: Java

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    Arrays.sort(a);
    long ans = 0;
    if(n % 2 == 0) {
      for(int i = (n - 1); i >= 0; i--) {
        if(i >= (n / 2)) {
          if(i == (n / 2)) {
            ans += a[i];
          } else {
            ans += (2 * a[i]);
          }          
        } else {
          if(i == ((n / 2) - 1)) {
            ans -= a[i];
          } else {
            ans -= (2 * a[i]);
          }
        }
      }
    } else {
      long t = 0;
      for(int i = (n - 1); i >= 0; i--) {
        if(i >= (n - (n / 2))) {
          t += (2 * a[i]);          
        } else {
          if((i == (n - (n / 2) - 1)) || (i == (n - (n / 2) - 2))) {
            t -= a[i];
          } else {
            t -= (2 * a[i]);
          }
        }
      }
      ans = t;
      t = 0;
      for(int i = (n - 1); i >= 0; i--) {
        if(i >= (n - (n / 2) - 1)) {
          if((i == (n - (n / 2) - 1)) || (i == (n - (n / 2)))) {
            t += a[i];
          } else {
            t += (2 * a[i]);
          }          
        } else {
          t -= (2 * a[i]);
        }
      }
      ans = Math.max(ans, t);
    }
    System.out.println(ans);
  }

Compiler output:
Main.java:58: error: reached end of file while parsing
  }
   ^
1 error
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <deque>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long gcd(long long a, long long b){if(b==0)return a;return gcd(b,a%b);}

int main() {
    int n; cin >> n;
    vector<ll> a(n); repp(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end());

    ll res = 0;
    deque<ll> q; q.push_front(a[0]);
    repp(i, 1, n) {
        int i = i % 2 == 0 ? i / 2 : n - (i / 2) - 1;

        if (abs(q.front() - a[i]) >= abs(q.back() - a[i])) {
            res += abs(q.front() - a[i]);
            q.push_front(a[i]);
        } else {
            res += abs(q.back() - a[i]);
            q.push_back(a[i]);
        }
        cout << res << endl;
    }
    cout << res << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:13: error: redeclaration of 'int i'
   29 |         int i = i % 2 == 0 ? i / 2 : n - (i / 2) - 1;
      |             ^
a.cc:28:10: note: 'int i' previously declared here
   28 |     repp(i, 1, n) {
      |          ^
a.cc:12:29: note: in definition of macro 'repp'
   12 | #define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
      |                             ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define nil -1
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);

int main() {
    int n;
    cin>>n;
    ll ans=0;
    vector<int> a(n,0);
    rep(i,n) {
        cin>>a[i];
    }
    SORT(a);
    if(n%2==0){
        for(int i=0;i<n/2-1;i++){
            ans-=2*a[i];
        }
        ans+=a[n/2]-a[n/2-1];
        for(int i=n/2+1;i<n;i++){
            ans+=2*a[i];
        }
    }else{
        ll temp1=0,temp2=0;
        for(int i=0;i<n/2;i++){
            temp1-=2*a[i];
        }
        temp1+=a[n/2]+a[n/2+1];
        for(int i=n/2+2;i<n;i++){
            temp1+=2*a[i];
        }
        for(int i=0;i<n/2-1;i++){
            temp2-=2*a[i];
        }
        temp2-=a[n/2-1]+a[n/2];
        for(int i=n/2+1;i<n;i++){
            temp2+=2*a[i];
        }
        ans=max(temp1,temp2);
    }
    cout<<ans<<endl;
    return 0;
}



Compiler output:
a.cc:17:1: error: 'cout' does not name a type
   17 | cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
      | ^~~~
a.cc:17:31: error: 'cin' does not name a type
   17 | cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
      |                               ^~~
a.cc:17:42: error: specializing member 'std::basic_ios<char>::sync_with_stdio' requires 'template<>' syntax
   17 | cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
      |                                          ^~~
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    int n;cin>>n;
    vector<ll> v(n);
    rep(i,n)cin>>v[i];
    sort(all(v));
    vector<ll> ans(n),ans2(n);
    ans[n/2] = v[0];ans2[n/2]=v[n-1];
    rep(i,(n-1)/2){
        if(i%2==0){
            ans[n/2-i-1] = v[n-1-i/2];
            ans[n/2+i+1] = v[n-1-i/2-1];
            ans2[n/2-i-1] = v[i+1];
            ans2[n/2+i+1] = v[i];
        }else{
            ans[n/2+i+1] = v[i+1];
            ans[n/2-i-1] = v[i];
            ans2[n/2-i-1] = v[n-1-i/2];
            ans2[n/2+i+1] = v[n-1-i/2-1];
        }
    }
    if(n%2==0){
        ans[0] = v[n/2];
        ans2[0] = v[n/2]
    }
    ll Ans =  0,Ans2 = 0;
    rep(i,n-1){
        Ans += abs(ans[i]-ans[i+1]);
        Ans2 += abs(ans2[i]-ans2[i+1]);
    }
    cout << max(Ans,Ans2) << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:66:25: error: expected ';' before '}' token
   66 |         ans2[0] = v[n/2]
      |                         ^
      |                         ;
   67 |     }
      |     ~
Language: C

// clang++ -std=c++14 -stdlib=libc++ -O2 ./*.cpp

#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
// #include <bits/stdc++.h>
using namespace std;

#define size_t int
typedef long long ll;
// #define int long long
typedef vector<int> VI;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define debug(x) cerr << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug1(i, x) cerr << "(" << (i) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
#define debug2(i, j, x) cerr << "(" << (i) << ", " << (j) <<  ") " << #x << " = " << (x) << " (line " << __LINE__ << ")" << endl;
template <typename T> class vec2d : public vector<vector<T>> {
public:
    vec2d(int H, int W): vector<vector<T>> (H, vector<T>(W)) {
    }
};
template <typename T> istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template <typename T> ostream& operator << (ostream& os, vector<T>& vec){
  REP(i, vec.size()) {
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0);
        // cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

signed main(signed argc, char **argv) {
  int N;
  cin >> N;
  VI A(N);
  cin >> A;
  VSORT(A);
  int r = 1;
  int l = 2;
  int ans = abs(A[0] - A[N - r]) + abs(A[0] - A[N - l]);
  int i;
  for (i = 0; i < (N + 1)/2 - 2; i++) {
    if (i % 2) {
      ans += abs(A[r] - A[N - r - 2]) + abs(A[l] - A[N - l - 2]);
      r++;l++;
    } else {
      ans += abs(A[N - r] - A[r]) + abs(A[N - l] - A[l]);
    }
  }
  if (!(N % 2)) {
    if (i % 2) {
      // ans += abs(A[r] - A[N - r - 2]) + abs(A[l] - A[N - l - 2]);
      int x = abs(A[r] - A[N - r - 2]);
      int y = abs(A[l] - A[N - r - 2]);
      // debug(x);
      // debug(y);
      ans += (x < y ? y : x);
    } else {
      // ans += abs(A[N - r] - A[r]) + abs(A[N - l] - A[l]);
      int x = abs(A[N - r] - A[r]);
      int y = abs(A[N - l] - A[r]);
      // debug(x);
      // debug(y);
      ans += (x < y ? y : x);
    }
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
main.c:3:10: fatal error: cstdio: No such file or directory
    3 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.
Language: C++

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

const int INF = 1e9;

int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a, a+n);
  long long b[n];
  int init;
  if(n%2==0){
    init = n/2-1;

  }else{
    init = n/2;
  }
  b[init]=a[0];
  int left=init-1;
  int right=init+1;
  int idx_large=n-1;
  int idx_small=1;
  while(true){
    if(right<n){
      b[right]=a[idx_large];
      ++right;
      --idx_large;
    }
    if(left>-1){
      b[left]=a[idx_large];
      --left;
      --idx_large;
    }
    if(right<n){
      b[right]=a[idx_small];
      ++right;
      ++idx_small;
    }
    if(left>-1){
      b[left]=a[idx_small];
      --left;
      ++idx_small;
    }
    if(right==n && left==-1){
      break;
    }
  }
  logn long ans=0;
  for(int i=0;i<n-1;i++){
    ans+=abs(b[i]-b[i+1]);
  }
  cout<<ans<<endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:3: error: 'logn' was not declared in this scope; did you mean 'long'?
   50 |   logn long ans=0;
      |   ^~~~
      |   long
a.cc:52:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   52 |     ans+=abs(b[i]-b[i+1]);
      |     ^~~
      |     abs
a.cc:54:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   54 |   cout<<ans<<endl;
      |         ^~~
      |         abs
Language: Java

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        c();
    }
    private static void c() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] as = new long[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextLong();
        }

        Arrays.sort(as);

        boolean flag = true;
        long bc = 0;
        while(flag) {
            long fc = bc;

            long hscore = bc;
            int h_i = 0;
            int h_j = 0;
            for (int i = 0; i < n - 1; i++) {
                for(int j = i + 1; j < n; j++) {
                    swap(as, i,j);
                    long nc = score(as);
                    if (nc > hscore) {
                        hscore = nc;
                        h_i = i;
                        h_j = j;
                    }
                    swap(as, i,j);
                }
            }

            swap(as,h_i,h_j);
            long s = score(as);
            if (s == fc) {
                flag = false;
            } else {
                bc = s;
            }
        }

        System.out.println(bc);

    }

    private static long score(long[] as) {
        long c = 0;
        for (int i = 0; i < as.length - 1; i++) {
            c += Math.abs(as[i] - as[i+1]);
        }

        return c;
    }

    private static void swap(long[] as, int i,int j) {
        long wk = as[i];
        as[i] = as[j];
        as[j] = wk;
    }
    }

Compiler output:
Main.java:17: error: cannot find symbol
        Arrays.sort(as);
        ^
  symbol:   variable Arrays
  location: class Main
1 error
Language: C++

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	sort(A.begin(), A.end());
	long long sum = 0;
	for (int i = 0; i < N - 1; ++i) {
		sum += 2 * long long(min(i + 1, N - i - 1)) * (A[i + 1] - A[i]);
	}
	if (N % 2 == 0) {
		sum -= A[N / 2] - A[N / 2 - 1];
	}
	else {
		sum -= min(A[N / 2] - A[N / 2 - 1], A[N / 2 + 1] - A[N / 2]);
	}
	cout << sum << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:28: error: expected primary-expression before 'long'
   13 |                 sum += 2 * long long(min(i + 1, N - i - 1)) * (A[i + 1] - A[i]);
      |                            ^~~~
Language: Java

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

// MainT1P2018C
public class MainT1P2018C {

    private static boolean isOdd(int val) {
        return ((val & 1) != 0);
    }

    public static void main(String[] args) {
        try (
                Scanner in = new Scanner(System.in);
                PrintWriter out = new PrintWriter(System.out))
        {
            final int N = in.nextInt();
            final int[] A = new int[N];
            Arrays.setAll(A, i -> Integer.parseInt(in.next()));

            final int halfN = N / 2;
            long result = 0L;
            Arrays.sort(A);
            if (isOdd(N)) {

                long r1 = 0L;
                r1 -= 2 * Arrays.stream(A, 0, halfN).asLongStream().sum();
                r1 += 2 * Arrays.stream(A, halfN, N).asLongStream().sum();
                r1 -= A[halfN];
                r1 -= A[halfN + 1];

                long r2 = 0L;
                r2 -= 2 * Arrays.stream(A, 0, halfN + 1).asLongStream().sum();
                r2 += 2 * Arrays.stream(A, halfN + 1, N).asLongStream().sum();
                r2 += A[halfN - 1];
                r2 += A[halfN];

                result = Math.max(r1, r2);

            } else {
                result -= 2 * Arrays.stream(A, 0, halfN).asLongStream().sum();
                result += 2 * Arrays.stream(A, halfN, N).asLongStream().sum();
                result += A[halfN - 1];
                result -= A[halfN];
            }
            out.println(result);
        }
    }
}


Compiler output:
Main.java:6: error: class MainT1P2018C is public, should be declared in a file named MainT1P2018C.java
public class MainT1P2018C {
       ^
1 error
Language: C++

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define int long long
using namespace std;
 
signed main(void){
    int n,mone = 0,mtwo = 0;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> aligns(n);
    rep(i,n) {
        cin >> aligns[i];
    }
    sort(aligns.begin(),aligns.end());
    if(aligns.size() == 2) {
        return align[1] - align[0];
    }
    rep(i,n) {
        mone += aligns[n-1-i] - aligns[i];
        mtwo += aligns[n-1-i] - aligns[i];
        if(n-1-i-i == 2) {
            mone += aligns[n-1] - aligns[i+1];
            mtwo += aligns[i+1] - aligns[0];
            break;
        } else if(n-1-i-i == 3) {
            mone += aligns[n-2-i] - aligns[i];
            mtwo += aligns[n-1-i] - aligns[i+1];
            mone += aligns[n-1] - aligns[i+1];
            mtwo += aligns[i+2] - aligns[0];
            break;
        } else {
            mone += aligns[n-2-i] - aligns[i];
            mtwo += aligns[n-1-i] - aligns[i+1]; 
        }
    }
    cout << max(mone,mtwo) << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:16: error: 'align' was not declared in this scope
   29 |         return align[1] - align[0];
      |                ^~~~~
a.cc:14:1: note: 'std::align' is defined in header '<memory>'; this is probably fixable by adding '#include <memory>'
   13 | #include <math.h>
  +++ |+#include <memory>
   14 | #define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
Language: C++

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

   typedef long long ll;

   const double EPS = (1e-7);
   const ll INF =(1e9);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

   int dx[4]={1,0,-1,0};
   int dy[4]={0,1,0,-1};

const ll MAX_N = 1e5;
ll N;
ll A[MAX_N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    REP(i, N){
        cin >> A[i];
    }
    sort(A, A + N);
    vector<ll> P, P1, P2
    

    if (N % 2 == 0){
        REP(i, N / 2 -1) P.pb(-2);
        P.pb(-1); P.pb(1);
        REP(i, N / 2 - 1) P.pb(2);
        
        ll ans = 0;
        REP(i, N){
            ans += P[i] * A[i];
        }
        cout << ans << endl;
    }
    else {
        REP(i, (N -1) /2) P1.pb(-2);
        P1.pb(1); P1.pb(1);
        REP(i, (N - 3) / 2) P1.pb(2);

        REP(i, (N - 3) /2) P2.pb(-2);
        P2.pb(-1); P2.pb(-1);
        REP(i, (N - 1) / 2) P2.pb(2);

        ll ans1 = 0, ans2 = 0;
        REP(i, N){
            ans1 += P1[i] * A[i];
            ans2 += P2[i] * A[i];
            
        }
        cout << max(ans1, ans2) << endl;

    }

}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:5: error: expected initializer before 'if'
   49 |     if (N % 2 == 0){
      |     ^~
a.cc:60:5: error: 'else' without a previous 'if'
   60 |     else {
      |     ^~~~
a.cc:65:28: error: 'P2' was not declared in this scope; did you mean 'P1'?
   65 |         REP(i, (N - 3) /2) P2.pb(-2);
      |                            ^~
      |                            P1
a.cc:66:9: error: 'P2' was not declared in this scope; did you mean 'P1'?
   66 |         P2.pb(-1); P2.pb(-1);
      |         ^~
      |         P1
Language: C++

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define int long long
using namespace std;

signed main(void){
    int n,mone = 0,mtwo = 0;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> aligns(n);
    rep(i,n) {
        cin >> aligns[i];
    }
    sort(aligns.begin(),aligns.end());
  	if(n==2){
      cout << max(a[0]-a[1],a[1]-a[0]) << endl;
      return 0;
    }
    rep(i,n) {
        mone += aligns[n-1-i] - aligns[i];
        mtwo += aligns[n-1-i] - aligns[i];
        if(n-1-i-i == 2) {
            mone += aligns[n-1] - aligns[i+1];
            mtwo += aligns[i+1] - aligns[0];
            break;
        } else if(n-1-i-i == 3) {
            mone += aligns[n-2-i] - aligns[i];
            mtwo += aligns[n-1-i] - aligns[i+1];
            mone += aligns[n-1] - aligns[i+1];
            mtwo += aligns[i+2] - aligns[0];
            break;
        } else {
            mone += aligns[n-2-i] - aligns[i];
            mtwo += aligns[n-1-i] - aligns[i+1]; 
        }
    }
    cout << max(mone,mtwo) << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:19: error: 'a' was not declared in this scope
   29 |       cout << max(a[0]-a[1],a[1]-a[0]) << endl;
      |                   ^
Language: C++

#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
typedef long long ll;
int a[100000+100];
int b[100000+100];
int len=0;
int star,end;
ll my_max(ll c,ll d)
{
	return c>d?c:d;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	star=0;
	end=n-1;
	sort(a,a+n);
	int ls=n/2;
	ll sum=abs(a[n-1]-a[0]);
	for(int i=1;i<ls;i++)
	{
		ll e,b,c,d;
		e=a[i-1];
		b=a[i];
		d=a[n-i];
		c=a[n-1-i];
		sum+=(ll)(abs(c-e)+abs(d-b));
	} 
	if(n%2==1)
	{
		int z=n/2;
		sum+=my_max(abs(a[z]-a[z+1]),abs(a[z]-a[z-1]));	
	}
	printf("%lld\n",sum);
	return 0;
 } 

Compiler output:
a.cc: In function 'int main()':
a.cc:23:9: error: reference to 'end' is ambiguous
   23 |         end=n-1;
      |         ^~~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:1:
/usr/include/c++/14/initializer_list:99:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:11:10: note:                 'int end'
   11 | int star,end;
      |          ^~~
Language: C++

#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
typedef long long ll;
int a[100000+100];
int b[100000+100];
int len=0;
int star,end;
ll my_max(ll a,ll b)
{
	return a>b?a:b;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	star=0;
	end=n-1;
	sort(a,a+n);
	int ls=n/2;
	ll sum=abs(a[n-1]-a[0]);
	for(int i=1;i<ls;i++)
	{
		ll e,b,c,d;
		e=a[i-1];
		b=a[i];
		d=a[n-i];
		c=a[n-1-i];
		sum+=(ll)(abs(c-e)+abs(d-b));
	} 
	if(n%2==1)
	{
		int z=n/2;
		sum+=my_max(abs(a[z]-a[z+1]),abs(a[z]-a[z-1]));	
	}
	printf("%lld\n",sum);
	return 0;
 } 

Compiler output:
a.cc: In function 'int main()':
a.cc:23:9: error: reference to 'end' is ambiguous
   23 |         end=n-1;
      |         ^~~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:1:
/usr/include/c++/14/initializer_list:99:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:11:10: note:                 'int end'
   11 | int star,end;
      |          ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100000+100];
int b[100000+100];
int len=0;
int star,end;
ll my_max(ll a,ll b)
{
	return a>b?a:b;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	star=0;
	end=n-1;
	sort(a,a+n);
	int ls=n/2;
	ll sum=abs(a[n-1]-a[0]);
	for(int i=1;i<ls;i++)
	{
		ll e,b,c,d;
		e=a[i-1];
		b=a[i];
		d=a[n-i];
		c=a[n-1-i];
		sum+=(ll)(abs(c-e)+abs(d-b));
	} 
	if(n%2==1)
	{
		int z=n/2;
		sum+=my_max(abs(a[z]-a[z+1]),abs(a[z]-a[z-1]));	
	}
	printf("%lld\n",sum);
	return 0;
 } 

Compiler output:
a.cc: In function 'int main()':
a.cc:19:9: error: reference to 'end' is ambiguous
   19 |         end=n-1;
      |         ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:1:
/usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/valarray:1249:5: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
 1249 |     end(valarray<_Tp>& __va) noexcept
      |     ^~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
In file included from /usr/include/c++/14/bits/algorithmfwd.h:39,
                 from /usr/include/c++/14/bits/stl_algo.h:59,
                 from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:7:10: note:                 'int end'
    7 | int star,end;
      |          ^~~
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include <functional>
using namespace std;

int main(){


int n,sum=0,x=0,y=0;
//vector<int> a;

cin >> n;
int a[n];
for(int i=0;i<n;i++){
	cin >> a[i];
}


sort(a, a+n);
if(n%2==0){
	for(int i=0;i<(n/2)-1;i++){
		x+=a[n-1-i]*2;
		y+=a[i]*2;
	}
	x+=a[n/2];
	y+=a[(n/2)-1];
	sum = x-y;
}else{
	for(int i=0;i<(n/2);i++){
		x+=a[n-1-i]*2;
		y+=a[i]*2;
	}
	y=y(-a[(n/2)-1])+a[n/2];
	

	sum = x-y;
}


cout << sum << endl;

return 0;}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:12: error: 'y' cannot be used as a function
   34 |         y=y(-a[(n/2)-1])+a[n/2];
      |           ~^~~~~~~~~~~~~
Language: C++

#include <stdio.h>
#include <stdlib.h>
long int int_sort(const void*a,const void *b){
    return *(long int*)b-*(long int*)a;
}

int main() {
    long int a,tmp,sum1=0,sum2=0;
    long int b[100000]={};
    long int big[50000]={};
    long int sma[50000]={};
    scanf("%ld",&a);
    for (int i = 0; i < a; i++) {
        scanf("%ld",&b[i]);
    }
    qsort(b,a,sizeof(b[0]),int_sort);
    if(a%2==0) {
        for (int i = 0; i < a; i++) {
            if (i<a/2) big[i] = b[i];
            else sma[-i+a-1] = b[i];
        }
        for(int i=0;i<a/2;i++){
            sum1+=big[i]*2-sma[i]*2;
        }
        sum1=sum1-big[0]+sma[a/2-1];

        if(big[a/2-1]-sma[a/2-1]<big[0]-sma[a/2-1])
            sum1+=big[0]-sma[a/2-1]-(big[a/2-1]-sma[a/2-1]);
    }
    else{
        for (int i = 0; i < a; i++) {
            if (i<a/2) big[i] = b[i];
            else sma[-i+a-1] = b[i];
        }
        for(int i=0;i<a/2;i++){
            sum1+=big[i]*2-sma[i]*2;
        }
        sum1=sum1-big[0]+sma[a/2-1];

        if(sma[a/2]-sma[a/2-1]>big[0]-sma[a/2])
            sum1+=sma[a/2]-sma[a/2-1];
        else sum1+=big[0]-sma[a/2];
    }

    printf("%ld\n",sum1);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:28: error: invalid conversion from 'long int (*)(const void*, const void*)' to '__compar_fn_t' {aka 'int (*)(const void*, const void*)'} [-fpermissive]
   16 |     qsort(b,a,sizeof(b[0]),int_sort);
      |                            ^~~~~~~~
      |                            |
      |                            long int (*)(const void*, const void*)
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/stdlib.h:36,
                 from a.cc:2:
/usr/include/stdlib.h:971:34: note:   initializing argument 4 of 'void qsort(void*, size_t, size_t, __compar_fn_t)'
  971 |                    __compar_fn_t __compar) __nonnull ((1, 4));
      |                    ~~~~~~~~~~~~~~^~~~~~~~
Language: C++

#include <stdio.h>
#include <stdlib.h>
long int int_sort(const void*a,const void *b){
    return *(long int*)b-*(long int*)a;
}

int main() {
    int a,tmp,sum1=0,sum2=0;
    long int b[100000]={};
    long int big[50000]={};
    long int sma[50000]={};
    scanf("%ld",&a);
    for (int i = 0; i < a; i++) {
        scanf("%ld",&b[i]);
    }
    qsort(b,a,sizeof(b[0]),int_sort);
    if(a%2==0) {
        for (int i = 0; i < a; i++) {
            if (i<a/2) big[i] = b[i];
            else sma[-i+a-1] = b[i];
        }
        for(int i=0;i<a/2;i++){
            sum1+=big[i]*2-sma[i]*2;
        }
        sum1=sum1-big[0]+sma[a/2-1];

        if(big[a/2-1]-sma[a/2-1]<big[0]-sma[a/2-1])
            sum1+=big[0]-sma[a/2-1]-(big[a/2-1]-sma[a/2-1]);
    }
    else{
        for (int i = 0; i < a; i++) {
            if (i<a/2) big[i] = b[i];
            else sma[-i+a-1] = b[i];
        }
        for(int i=0;i<a/2;i++){
            sum1+=big[i]*2-sma[i]*2;
        }
        sum1=sum1-big[0]+sma[a/2-1];

        if(sma[a/2]-sma[a/2-1]>big[0]-sma[a/2])
            sum1+=sma[a/2]-sma[a/2-1];
        else sum1+=big[0]-sma[a/2];
    }

    printf("%ld\n",sum1);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:28: error: invalid conversion from 'long int (*)(const void*, const void*)' to '__compar_fn_t' {aka 'int (*)(const void*, const void*)'} [-fpermissive]
   16 |     qsort(b,a,sizeof(b[0]),int_sort);
      |                            ^~~~~~~~
      |                            |
      |                            long int (*)(const void*, const void*)
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/stdlib.h:36,
                 from a.cc:2:
/usr/include/stdlib.h:971:34: note:   initializing argument 4 of 'void qsort(void*, size_t, size_t, __compar_fn_t)'
  971 |                    __compar_fn_t __compar) __nonnull ((1, 4));
      |                    ~~~~~~~~~~~~~~^~~~~~~~
Language: C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm.h>
int d[200000];
int main(){
    int n,i,j,r=1,sum=0,rp=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&d[i]);
    }
    std::sort(d+1,d+n+1);
    j=n;
    if(n%2==1){
        if(n==3){
            sum=sum+(d[j]-d[r]);
            sum=sum+(d[j-1]-d[r]);
        }
        else{
        while(j-1!=r){
            if(j==n){
            sum=sum+(d[j]-d[r]);
            rp++;
            sum=sum+(d[j]-d[r+1]);
            j--;
            }
            else{
                sum=sum+(d[j]-d[r]);
                rp++;
                if(rp==2){
                sum=sum+(d[j]-d[r+2]);
                r++;
                rp=1;
                }
                j--;
            }
        }
      }
    }
    else{
        if(n==2){
            sum=sum+(d[j]-d[r]);
        }
        else{
        while(r!=j){
            if(j==n){
                sum=sum+(d[j]-d[r]);
                rp++;
                sum=sum+(d[j]-d[r+1]);
                j--;
            }
            else{
                sum=sum+(d[j]-d[r]);
                rp++;
                if(rp==2){
                    sum=sum+(d[j]-d[r+2]);
                    r++;
                    rp=1;
                }
                j--;
            }
        }
      }
    }
    printf("%d",sum);
    return 0;
    
}

Compiler output:
main.c:4:10: fatal error: algorithm.h: No such file or directory
    4 | #include <algorithm.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
Language: C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
int d[200000];
int main(){
    int n,i,j,r=1,sum=0,rp=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&d[i]);
    }
    std::sort(d+1,d+n+1);
    j=n;
    if(n%2==1){
        if(n==3){
            sum=sum+(d[j]-d[r]);
            sum=sum+(d[j-1]-d[r]);
        }
        else{
        while(j-1!=r){
            if(j==n){
            sum=sum+(d[j]-d[r]);
            rp++;
            sum=sum+(d[j]-d[r+1]);
            j--;
            }
            else{
                sum=sum+(d[j]-d[r]);
                rp++;
                if(rp==2){
                sum=sum+(d[j]-d[r+2]);
                r++;
                rp=1;
                }
                j--;
            }
        }
      }
    }
    else{
        if(n==2){
            sum=sum+(d[j]-d[r]);
        }
        else{
        while(r!=j){
            if(j==n){
                sum=sum+(d[j]-d[r]);
                rp++;
                sum=sum+(d[j]-d[r+1]);
                j--;
            }
            else{
                sum=sum+(d[j]-d[r]);
                rp++;
                if(rp==2){
                    sum=sum+(d[j]-d[r+2]);
                    r++;
                    rp=1;
                }
                j--;
            }
        }
      }
    }
    printf("%d",sum);
    return 0;
    
}


Compiler output:
main.c:4:10: fatal error: algorithm: No such file or directory
    4 | #include <algorithm>
      |          ^~~~~~~~~~~
compilation terminated.
Language: C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
int d[200000];
int main(){
    int n,i,j,r=1,sum=0,rp=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&d[i]);
    }
    std::sort(d+1,d+n+1);
    j=n;
    if(n%2==1){
        while(j-1!=r){
            if(j==n){
            sum=sum+(d[j]-d[r]);
            rp++;
            sum=sum+(d[j]-d[r+1]);
            j--;
            }
            else{
                sum=sum+(d[j]-d[r]);
                rp++;
                if(rp==2){
                sum=sum+(d[j]-d[r+2]);
                r++;
                rp=1;
                }
                j--;
            }
        }
    }
    else{
        while(r!=j){
            if(j==n){
                sum=sum+(d[j]-d[r]);
                rp++;
                sum=sum+(d[j]-d[r+1]);
                j--;
            }
            else{
                sum=sum+(d[j]-d[r]);
                rp++;
                if(rp==2){
                    sum=sum+(d[j]-d[r+2]);
                    r++;
                    rp=1;
                }
                j--;
            }
        }
    }
    printf("%d",sum);
    return 0;
    
}




Compiler output:
main.c:4:10: fatal error: algorithm: No such file or directory
    4 | #include <algorithm>
      |          ^~~~~~~~~~~
compilation terminated.
Language: C++

n = int(input())

a = [0] * n

for i in range(0, n):
  a[i] = long(input())

a.sort()

c = 0

if len(a) == 2:
  print(abs(a[0] - a[1]))

if len(a) == 3:
  diff = abs(a[0] - a[1]) + abs(a[1] - a[2])
  diff = max(abs(a[0] - a[2]) + abs(a[1] - a[2]), diff)
  diff = max(abs(a[0] - a[2]) + abs(a[0] - a[1]), diff)
  print(diff)

mini = 0
maxi = len(a) - 1

if len(a) > 3:
  (l, r) = (a[maxi], a[maxi - 1])
  maxi -= 2
  diff = abs(a[0] - l) + abs(a[0] - r)
  mini += 1
  for i in range(0, n - 3):
    if i % 2 == 0:
      if c < 2:
        diff += abs(a[mini] - l)
        l = a[mini]
        mini += 1
      else:
        diff += abs(a[maxi] - l)
        l = a[maxi]
        maxi -= 1
    else:
      if c < 2:
        diff += abs(a[mini] - r)
        r = a[mini]
        mini += 1
      else:
        diff += abs(a[maxi] - r)
        r = a[maxi]
        maxi -= 1
    if c < 3:
      c += 1
    else:
      c = 0
  
  maxi = len(a) - 1
  mini = 0
  (l, r) = (a[mini], a[mini + 1])
  mini += 2
  diff2 = abs(a[-1] - l) + abs(a[-1] - r)
  maxi -= 1
  for i in range(0, n - 3):
    if i % 2 == 0:
      if c > 1:
        diff2 += abs(a[mini] - l)
        l = a[mini]
        mini += 1
      else:
        diff2 += abs(a[maxi] - l)
        l = a[maxi]
        maxi -= 1
    else:
      if c > 1:
        diff2 += abs(a[mini] - r)
        r = a[mini]
        mini += 1
      else:
        diff2 += abs(a[maxi] - r)
        r = a[maxi]
        maxi -= 1
    if c < 3:
      c += 1
    else:
      c = 0

  print(max(diff, diff2))



Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n = int(input())
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)

int doSum(vector<int>con, vector<int>rev, int N){
    int half,sum;
    if (N%2==0)
        half = N/2 -1;
    else
        half = (N+1)/2 -1;

    int sum =0;
    for(int i=0;i<half-1;i++){
        sum += abs(rev[i]-con[i+1]);
        sum += abs(con[i]-rev[i+1]);
    }
    sum+=(rev[0] - con[0]);
    if (N%2!=0){
        sum -= (rev[half-1]-con[half]);
    }
    return sum;
}

int main(){
    int N, half;
    cin  >> N;
    vector<int> con(N);
    rep(i,N) cin >> con[i];
    sort(con.begin(), con.end());
    vector<int> rev(con.rbegin(), con.rend());
    int sum1, sum2, sum;
    sum1 = doSum(con, rev, N);
    sum2 = doSum(rev, con, N);
    sum = sum1 > sum2 ? sum1:sum2;
    cout << sum << endl;
}

Compiler output:
a.cc: In function 'int doSum(std::vector<int>, std::vector<int>, int)':
a.cc:12:9: error: redeclaration of 'int sum'
   12 |     int sum =0;
      |         ^~~
a.cc:6:14: note: 'int sum' previously declared here
    6 |     int half,sum;
      |              ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)

int doSum(vector<int>con, vector<int>ver, int N){
    if (N%2==0)
        half = N/2 -1;
    else
        half = (N+1)/2 -1;

    int sum =0;
    for(int i=0;i<half-1;i++){
        sum += abs(rev[i]-con[i+1]);
        sum += abs(con[i]-rev[i+1]);
    }
    sum+=(rev[0] - con[0]);
    if (N%2!=0){
        sum -= (rev[half-1]-con[half]);
    }
    return sum;
}

int main(){
    int N, half;
    cin  >> N;
    vector<int> con(N);
    rep(i,N) cin >> con[i];
    sort(con.begin(), con.end());
    vector<int> rev(con.rbegin(), con.rend());
    int sum1, sum2, sum;
    sum1 = doSum(con, rev, N);
    sum2 = doSum(rev, con, N);
    sum = sum1 > sum2 ? sum1:sum2;
    cout << sum << endl;
}

Compiler output:
a.cc: In function 'int doSum(std::vector<int>, std::vector<int>, int)':
a.cc:7:9: error: 'half' was not declared in this scope
    7 |         half = N/2 -1;
      |         ^~~~
a.cc:9:9: error: 'half' was not declared in this scope
    9 |         half = (N+1)/2 -1;
      |         ^~~~
a.cc:12:19: error: 'half' was not declared in this scope
   12 |     for(int i=0;i<half-1;i++){
      |                   ^~~~
a.cc:13:20: error: 'rev' was not declared in this scope; did you mean 'rep'?
   13 |         sum += abs(rev[i]-con[i+1]);
      |                    ^~~
      |                    rep
a.cc:16:11: error: 'rev' was not declared in this scope; did you mean 'rep'?
   16 |     sum+=(rev[0] - con[0]);
      |           ^~~
      |           rep
a.cc:18:21: error: 'half' was not declared in this scope
   18 |         sum -= (rev[half-1]-con[half]);
      |                     ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
long long a[100005]={0};
long long main()
{
	long long n,m,c;
	cin>>n;
	for(long long i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	long long sum=0,mid=n/2;

       
       vector<long long>q;
    
       if(n%2==1)
       {   q.push_back(a[mid]);
	    long long disb=a[n-1]-a[mid],dise=a[mid]-a[0];
       	 if(dise<=disb)
	  {for(long long i=0;i<n/2;i++)
       {
       	q.push_back(a[n-1-i]);
       	    	 q.push_back(a[i]);	
	   }
}
else
{for(long long i=0;i<n/2;i++)
       { q.push_back(a[i]);
       	q.push_back(a[n-1-i]);
       	    		
	   }
	
	   }	   
	   }
	   else
	   {
	   	mid--;
	   long long disb=a[n-1]-a[mid],dise=a[mid]-a[0];
	      if(dise<=disb)
	   	{   q.push_back(a[mid]);
		    for(long long i=0;i<n/2-1;i++)
	   	  {
	   	  	q.push_back(a[n-1-i]);
       	    	 q.push_back(a[i]);	
			 }
	   	    q.push_back(a[mid+1]);
	   	    
			 }  
			 else
			 {      
			 	mid++;
			 	q.push_back(a[mid]);
			   for(long long i=0;i<n/2-1;i++)
	   	  {q.push_back(a[i]);	
	   	  	q.push_back(a[n-1-i]);
       	    	 
			 }
	   	    q.push_back(a[mid-1]);
			 }
	   }
	   
     
	   for(long long i=0;i<q.size()-1;i++)
	   {
	   	sum+=abs(q[i]-q[i+1]); 
		} 
cout<<sum<<endl;	
 } 


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

N = int(input())
A =[0]*N
for i in range(N):
    A[i] = int(input())
A.sort(reverse=True)
X=0
Y=0
if N % 2 == 0:
    for i in range(N//2-1):
        X = X + 2*A[i] -2*A[-i-1]
    X = X + A[N//2-1] -A[N//2]
    print(X)    
 
if N % 2 == 1:
        for i in range(N//2):
            X = X + 2 * A[i]
            Y = Y - 2 * A[-i-1]
        for i in range (N//2-1):
            X = X - 2 * A[-i-1]
            Y = Y + 2 * A[i]
        X = X - A[N//2] - A[N//2+1]
        Y = Y + A[N//2-1] + A[N//2]
        print(max(X,Y))

Compiler output:
a.cc:1:1: error: 'N' does not name a type
    1 | N = int(input())
      | ^
Language: C


#include<algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<cmath>
#include<algorithm>
using ull = unsigned long long;

ull tab[10005]{};
int main() {

	ull n{};
	std::cin >> n;
	std::vector<ull> v;
	v.resize(n);

	for (ull i{}; i < n; ++i) 
		std::cin >> v[i];
	
	std::sort(std::begin(v), std::end(v));

	std::cout << "\n";
	for (ull i{ 0 }; i < n/2 + n % 2 == 0 ? 0 : 1; ++i ) {
		//std::cout << "i " << n-i-1 << "\n";
		auto ti = 2*i +  (i % 2 == 0 ? 1 : 0);
//		std::cout <<"i, ti "<<i<<", "<< ti << "\n";
		tab[ti] = v[n - i -1];
	}

//	std::cout << "\n";
	for (ull i{ 0 }; i < n / 2 ; ++i) {
		auto ti = 2 *i + (i % 2 == 0 ? 0 : 1);
//		std::cout << "i, ti " << i << ", " << ti << "\n";
		tab[ti] = v[i];
	}



	auto lit = std::find(std::begin(tab), std::end(tab), 0);
	auto it = lit + 1;
	if (it!=std::end(tab) && *it != 0)
		std::iter_swap(lit, it);


	//std::cout << "t " << tab[1] << " " << tab[0] << "\n";
	ull result = tab[1] - tab[0];
	ull d{};
	for (ull i{2}; i < n; ++i) {

		if (tab[i] != 0 && tab[i - 2] != 0)
			 d = (i - 1) % 4 < 2 ?
				tab[i] - tab[i - 2]
				: tab[i - 2] - tab[i];

		result += d;
	//	std::cout << d << "\n";
	}
	std::cout << result << "\n";
	//for (auto&e : tab)
	//	if (e != 0)
	//		std::cout << e << " ";


	return 0;
}

Compiler output:
main.c:2:9: fatal error: algorithm: No such file or directory
    2 | #include<algorithm>
      |         ^~~~~~~~~~~
compilation terminated.