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


#include<algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<cmath>

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.
Language: C++

#include <iostream>
#include <vector>
#include <cstdlib>
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 int ans = 0;
    int p = 1, r = N-2;
    vector<int> B;

    B.push_back(A[N-1]);

    B.insert(B.begin(), A[0]);

    for( int i = 1; i < N-1; ++i ){
        if( i % 2 ){ // rear
            if( abs(B.front()-A[r]) < abs(B.back()-A[r]) ){
                B.push_back(A[r]);
            } else {
                B.insert(B.begin(), A[r]);
            }
            --r;
        } else {
            if( abs(B.front()-A[p]) < abs(B.back()-A[p]) ){
                B.push_back(A[p]);
            } else {
                B.insert(B.begin(), A[p]);
            }
            ++p;
        }
    }

/*
    for( int i = 0; i < N-1; ++i )
        cout << B[i] << " ";
    cout << B[N-1] << endl;
*/

    for( int i = 0; i < N-1; ++i )
        ans += abs(B[i] - B[i+1]);

    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   15 |     sort(A.begin(), A.end());
      |     ^~~~
      |     short
Language: C

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){
  int i,j;
  int n;
  int x;
  long long y=0;
  int l=0;

  scanf("%d",&n);

  long long a[n];
  long long p[n];

  for(i=0; i<=n-1; i++){
    p[i] = 0;
  }

  for(i=0; i<=n-1; i++){
    scanf("%lld",&a[i]);
  }

  for(i=0; i<=n-1; i++){
    for(j=i+1; j<=n-1; j++){
      if(a[j]<a[i]){
        x = a[i];
        a[i] = a[j];
        a[j] = x;
      }
    }
  }

  if(n==2){
    for(i=0; i<=n-1; i++){
      p[i] = a[i];
    }
    l++;
  }
  if(n==3){
    if(a[0]<=a[1] && a[0]<=a[2]){
      p[1] = a[0];
      p[0] = a[1];
      p[2] = a[2];
    }else if(a[1]<=a[0] && a[1]<=a[2]){
      p[1] = a[1];
      p[0] = a[0];
      p[2] = a[2];
    }else{
      p[1] = a[2];
      p[0] = a[0];
      p[2] = a[1];
    }
    l++
  }

  if(n%2==1 && l==0){
    p[(n-1)/2] = a[0];
    for(i=1; i<=(n+1)/2-1; i++){
      if(i%2==1){
        p[(n-1)/2+i+1] = a[i];
      }else{
        p[(n-1)/2-i] = a[i];
      }
    }
    p[(n-1)/2+1] = a[n-1];
    for(i=1; i<=(n-1)/2-1; i++){
      if(i%2==1){
        p[(n-1)/2+1-2*i] = a[n-1-i];
      }else{
        p[(n-1)/2+1+2*i] = a[n-1-i];
      }
    }
  }

  if(n%2==0 && l==0){
    p[n/2-1] = a[0];
    for(i=1; i<=n/2-1; i++){
      if(i%2==1){
        p[n/2-1+i+1] = a[i];
      }else{
        p[n/2-1-i] = a[i];
      }
    }
    p[n/2] = a[n-1];
    for(i=1; i<=n/2-1; i++){
      if(i%2==1){
        p[n/2-i-1] = a[n-1-i];
      }else{
        p[n/2+i] = a[n-1-i];
      }
    }
  }

  for(i=0; i<=n-2; i++){
    y = y + llabs(p[i+1]-p[i]);
  }

  printf("%lld\n",y);

  return 0;
}


Compiler output:
main.c: In function 'main':
main.c:55:8: error: expected ';' before '}' token
   55 |     l++
      |        ^
      |        ;
   56 |   }
      |   ~
Language: C++

#include<cstdio>
#include<algorithm>
#include<list>
#include<iterator>
#include<cmath>
using namespace std;

long long a[211111];
long long b[211111];
long long c = 0;

long long p1 = 0;
long long p2 = 0;

list<long long>old;

list<long long>ans;

int main()
{
	long long n;
	scanf("%lld", &n);

	for (long long i = 0; i < n; i++)
	{
		scanf("%lld", &a[i]);
	}

	sort(a, a + n);
	
	for (long long i = 0; i < n; i++)
	{
		old.push_back(a[i]);
	}

	//放入最小
	ans.push_back(old.front());
	old.pop_front();
	n--;

	bool turn = true;/ 大  ，否则 小
	while (n >= 2)
	{
		if (turn)
		{
			turn = false;
			ans.push_front(old.back());
			old.pop_back();
			n--;

			ans.push_back(old.back());
			old.pop_back();
			n--;
		}

		else
		{
			turn = true;
			ans.push_front(old.front());
			old.pop_front();
			n--;

			ans.push_back(old.front());
			old.pop_front();
			n--;
		}

	}

	if (n == 1)
	{
		ans.push_front(old.front());
	}

	for (auto it = ans.begin(); it != ans.end(); it++)
	{
		b[c++] = (*it);
	}

	for (long long i = 0; i < c - 1; i++)
	{
		long long k = b[i] - b[i + 1];

		if (k > 0)
			p1 += k;
		else
			p1 -= k;
	}


	while (!ans.empty())
		ans.pop_back();

	while (!old.empty())
		old.pop_back();


	n = c;
	c = 0;

	for (long long i = 0; i < n; i++)
	{
		old.push_back(a[i]);
	}

	//放入最大
	ans.push_back(old.back());
	old.pop_back();
	n--;

	turn = true;/ 小  ，否则 大
	while (n >= 2)
	{
		if (turn)
		{
			turn = false;
			ans.push_front(old.front());
			old.pop_front();
			n--;

			ans.push_back(old.front());
			old.pop_front();
			n--;
		}

		else
		{
			turn = true;
			ans.push_front(old.back());
			old.pop_back();
			n--;

			ans.push_back(old.back());
			old.pop_back();
			n--;
		}

	}

	if (n == 1)
	{
		ans.push_front(old.front());
	}

	for (auto it = ans.begin(); it != ans.end(); it++)
	{
		b[c++] = (*it);
	}

	for (long long i = 0; i < c - 1; i++)
	{
		long long k = b[i] - b[i + 1];

		if (k > 0)
			p2 += k;
		else
			p2 -= k;
	}


	printf("%lld\n", max(p1, p2));

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:26: error: expected primary-expression before '/' token
   41 |         bool turn = true;/ 大  ，否则 小
      |                          ^
a.cc:41:28: error: '\U00005927' was not declared in this scope
   41 |         bool turn = true;/ 大  ，否则 小
      |                            ^~
a.cc:111:21: error: expected primary-expression before '/' token
  111 |         turn = true;/ 小  ，否则 大
      |                     ^
a.cc:111:23: error: '\U00005c0f' was not declared in this scope
  111 |         turn = true;/ 小  ，否则 大
      |                       ^~
Language: C++

#include<cstdio>
#include<algorithm>
#include<list>
#include<iterator>
#include<cmath>
using namespace std;

long long a[211111];
long long b[211111];
long long c = 0;

long long p = 0;

list<long long>old;

list<long long>ans;

int main()
{
	long long n;
	scanf("%lld", &n);

	for (long long i = 0; i < n; i++)
	{
		scanf("%lld", &a[i]);
	}

	sort(a, a + n);
	
	for (long long i = 0; i < n; i++)
	{
		old.push_back(a[i]);
	}

	//放入最小
	ans.push_back(old.front());
	old.pop_front();
	n--;

	bool turn = true;/ 大  ，否则 小
	while (n >= 2)
	{
		if (turn)
		{
			turn = false;
			ans.push_front(old.back());
			old.pop_back();
			n--;

			ans.push_back(old.back());
			old.pop_back();
			n--;
		}

		else
		{
			turn = true;
			ans.push_front(old.front());
			old.pop_front();
			n--;

			ans.push_back(old.front());
			old.pop_front();
			n--;
		}

	}

	if (n)
	{
		ans.push_front(old.front());
	}

	for (auto it = ans.begin(); it != ans.end(); it++)
	{
		b[c++] = (*it);
	}

	for (long long i = 0; i < c - 1; i++)
	{
		p += abs(b[i] - b[i + 1]);
	}

	printf("%lld\n", p);

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:26: error: expected primary-expression before '/' token
   40 |         bool turn = true;/ 大  ，否则 小
      |                          ^
a.cc:40:28: error: '\U00005927' was not declared in this scope
   40 |         bool turn = true;/ 大  ，否则 小
      |                            ^~
Language: C++

#include<math.h>
#include<stdlib.h>
#define MAX_DATA 100000

int temp[MAX_DATA];    /* 最小でも配列と同じサイズの領域が必要 */

/* 配列 x[ ] の left から right の要素のマージソートを行う */
void MergeSort(long x[], long left, long right)
{
	long mid, i, j, k;

	if (left >= right)              /* 配列の要素がひとつなら */
		return;                     /* 何もしないで戻る */

									/* ここでは分割しているだけ */
	mid = (left + right) / 2;       /* 中央の値より */
	MergeSort(x, left, mid);        /* 左を再帰呼び出し */
	MergeSort(x, mid + 1, right);   /* 右を再帰呼び出し */

									/* x[left] から x[mid] を作業領域にコピー */
	for (i = left; i <= mid; i++)
		temp[i] = x[i];

	/* x[mid + 1] から x[right] は逆順にコピー */
	for (i = mid + 1, j = right; i <= right; i++, j--)
		temp[i] = x[j];

	i = left;         /* i とj は作業領域のデーターを */
	j = right;        /* k は配列の要素を指している */

	for (k = left; k <= right; k++)    /* 小さい方から配列に戻す */
		if (temp[i] <= temp[j])        /* ここでソートされる */
			x[k] = temp[i++];
		else
			x[k] = temp[j--];
}

int main(void)
{
	long i;
	long ok;
	int size;
long long  kouhoa;
long long kouhob;
long long sum=0;
	/* ソートされるデータ */
	long x[100000];
	scanf("%ld", &ok);
	for (i = 0; i < ok; i++) {
		scanf("%ld", &x[i]);
	}
	MergeSort(x, 0, (long)ok-1);
if(ok%2==0){
for(long i=ok;i>=ok/2;i--){
sum+=x[i]*2;
}
for(long i=0;i<ok/2;i++){
sum-=x[i]*2;
}
sum+=x[ok/2-1];
sum-=x[ok/2];
printf("%lld",sum);
}else{
for(long i=ok;i>(ok-1)/2;i--){
sum+=x[i]*2;
}
for(long i=0;i<(ok-1)/2;i++){
sum-=x[i]*2;
}
if(x[(ok-1)/2]-x[(ok-1)/2+1]>=x[(ok-1)/2-1]-x[(ok-1)/2]){
printf("%lld",sum+x[(ok-1)/2]-x[(ok-1)/2+1]-x[(ok-1)/2-1]+x[(ok-1)/2])
}else{
printf("%lld",sum+x[(ok-1)/2-1]-x[(ok-1)/2])-x[(ok-1)/2]+x[(ok-1)/2+1])
}
}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:48:9: error: 'scanf' was not declared in this scope
   48 |         scanf("%ld", &ok);
      |         ^~~~~
a.cc:62:1: error: 'printf' was not declared in this scope
   62 | printf("%lld",sum);
      | ^~~~~~
a.cc:3:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
    2 | #include<stdlib.h>
  +++ |+#include <cstdio>
    3 | #define MAX_DATA 100000
a.cc:71:1: error: 'printf' was not declared in this scope
   71 | printf("%lld",sum+x[(ok-1)/2]-x[(ok-1)/2+1]-x[(ok-1)/2-1]+x[(ok-1)/2])
      | ^~~~~~
a.cc:71:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc:73:1: error: 'printf' was not declared in this scope
   73 | printf("%lld",sum+x[(ok-1)/2-1]-x[(ok-1)/2])-x[(ok-1)/2]+x[(ok-1)/2+1])
      | ^~~~~~
a.cc:73:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
Language: C++

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

long abs long n) {
    return n < 0 ? -n : n;
}

int main() {
    int nCnt = 0;
    cin >> nCnt;
    if (nCnt % 2) return 1887415157;
    long int *Arr = new long int[nCnt];
    bool *ArrCho = new bool[nCnt];
    for (int _cnt = 0; _cnt < nCnt; ++_cnt) {
        cin >> Arr[_cnt];
        ArrCho[_cnt] = false;
    }
    sort(Arr, Arr + nCnt);
    long int *ArrRes = new long int[nCnt];
    int tmp = nCnt / 2;
    for (int _cnt = 0; _cnt < tmp; ++_cnt) {
        ArrRes[_cnt * 2] = Arr[_cnt];
        ArrRes[_cnt * 2 + 1] = Arr[_cnt + tmp];
    }
    long int res = 0;
    for (int _cnt = 1; _cnt < nCnt; ++_cnt) {
        res += abs(ArrRes[_cnt] - ArrRes[_cnt - 1]);
    }

    cout << res;

    delete[] Arr;
    delete[] ArrCho;
    delete[] ArrRes;
    return 0;
}

/*
1 5 9 8 8 6
1 5 6 8 8 9
1 5 6   8 8 9
9 6 8 5 8 1
*/


Compiler output:
a.cc:5:10: error: expected initializer before 'long'
    5 | long abs long n) {
      |          ^~~~
Language: C++

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

#include <stdio.h>

int main() {
  int n;

  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  // int a[100001], b[100001]={0};
  for(int i = 0; i<n; i++){cin >> a[i];}

  sort(a.begin(), a.end());

if(n%2==1){
  for (int i = 0; i < n; i++) {
    if (i <= n/2){
      if ( i%2 == 0) {
        b[n/2-i]=a[i];
        cout<<"even"<<endl;
      } else {
        b[n/2+i+1]=a[i];
        cout<<"odd"<<endl;
      }
    } else {
      if ( i%2 == 0) {
        b[n/2-(i-n/2-1)]=a[i];
        cout<<"even"<<endl;
      } else {
        b[n/2+(i-n/2)]=a[i];
        cout<<"odd"<<endl;
      }
    }
}
}else{
  for (int i = 0; i < n; i++) {
    if (i < n/2){
      if ( i%2 == 0) {
        b[n/2-i-1]=a[i];

      } else {
        b[n/2+i+1-1]=a[i];
    }
    } else {
      if ( i%2 ==1) {
        b[n/2-(i-n/2-1)-1-1]=a[i];

      } else {
        b[n/2+(i-n/2)-1-1]=a[i];

      }
    }

}
  }

  cout << sum << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:11: error: 'sum' was not declared in this scope
   61 |   cout << sum << endl;
      |           ^~~
Language: C++

#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int N,m=0,x=0,y=0;
 	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=x+a[N-1-i]*2;
 			y=y+a[i]*2;
 		}m=x-y+a[N/2]-a[N/2-1];
 	}else{
 		int p=0,q=0;
 		for (int i = 0; i < N/2-1; i++)
 		x=x+a[N-1-i]*2;
 		y=y+a[i]*2;
 		p=x-y+a[N/2]+a[N/2+1]-a[N/2-1]*2;
 		q=x-y-a[N/2]+a[N/2-1]-a[N/2+1]*2;
 		if(p>q)
 		m=p;
 		else
 		m=q;
 	}
 	cout << m << endl;
 }

Compiler output:
a.cc: In function 'int main()':
a.cc:25:23: error: 'i' was not declared in this scope
   25 |                 y=y+a[i]*2;
      |                       ^
Language: C++

#include <stdio.h>

int int_sort(const void*a,const void *b){
    return *(int*)b-*(int*)a;
}

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


Compiler output:
a.cc: In function 'int main()':
a.cc:16:5: error: 'qsort' was not declared in this scope
   16 |     qsort(b,a,sizeof(b[0]),int_sort);
      |     ^~~~~
Language: C++

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

long long abs(long long n) {
    return n < 0 ? -n : n;
}

int main() {
    int nCnt = 0;
    cin >> nCnt;
    if (nCnt % 2) return 1887415157;
    long long int *Arr = new long long int[nCnt];
    bool *ArrCho = new bool[nCnt];
    for (int _cnt = 0; _cnt < nCnt; ++_cnt) {
        cin >> Arr[_cnt];
        ArrCho[_cnt] = false;
    }
    sort(Arr, Arr + nCnt);
    long long int *ArrRes = new long long int[nCnt];
    int tmp = nCnt / 2;
    for (int _cnt = 0; _cnt < tmp; ++_cnt) {
        ArrRes[_cnt * 2] = Arr[_cnt];
        ArrRes[_cnt * 2 + 1] = Arr[_cnt + tmp];
    }
    long long int res = 0;
    for (int _cnt = 1; _cnt < nCnt; ++_cnt) {
        res += abs(ArrRes[_cnt] - ArrRes[_cnt - 1]);
    }

    cout << res;

    delete[] Arr;
    delete[] ArrCho;
    delete[] ArrRes;
    return 0;
}

/*
1 5 9 8 8 6
1 5 6 8 8 9
1 5 6   8 8 9
9 6 8 5 8 1
*/


Compiler output:
a.cc: In function 'int main()':
a.cc:28:19: error: call of overloaded 'abs(long long int)' is ambiguous
   28 |         res += abs(ArrRes[_cnt] - ArrRes[_cnt - 1]);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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;
      |            ^~~
a.cc:5:11: note: candidate: 'long long int abs(long long int)'
    5 | long long abs(long long n) {
      |           ^~~
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); }
      |   ^~~
Language: C++

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

int main(){
    int n;
    int ans = 0;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a, a+n);
    int k = 2;
    for(int i=n/2;i!=n/2+1;k++) {
        if(i<=n/2) {
            ans += abs(a[i]-a[i+k]);
            i -= k
        }else{
            ans += abs(a[i]-a[i-k]);
            i += k;
        }

    }

    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:19: error: expected ';' before '}' token
   18 |             i -= k
      |                   ^
      |                   ;
   19 |         }else{
      |         ~
Language: Java

import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b =new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int end = n / 2;
        if (n % 2 == 0) {
            end--;
        }
        int Bcount = 1;
        for (int i = 0; i < end; i++) {
            int j = a.length - i - 1;
            b[Bcount++] = a[j];
            b[Bcount++] = a[i];
        }

        if (n % 2 == 0) {
            b[0] = a[n/2];
            b[Bcount] = a[n/2+1];
        } else {
            if (Math.abs(b[1] - a[n/2+1]) > Math.abs(a[n/2+1] - b[Bcount - 1])) {
                b[0] = a[n/2+1];
            } else {
                b[Bcount] = a[n/2+1];
                b[0] = b[1]
            }
        }

        int sumDiff = 0;
        for (int i = 0; i < n - 1; i++) {
            sumDiff += Math.abs(b[i] - b[i+1]);
        }
        
        System.out.println(sumDiff);
    }
}


Compiler output:
Main.java:35: error: ';' expected
                b[0] = b[1]
                           ^
1 error
Language: C++

#include <iostream>
#include <string.h>
#include <cmath>

void bubbleSort(int numbers[], int array_size)
{
  int i, j, temp, begin, end;

  for (i = 0; i < (array_size - 1); i++) {
    for (j = (array_size - 1); j > i; j--) {
      if (numbers[j-1] > numbers[j]) {
        temp = numbers[j-1];
        numbers[j-1] = numbers[j];
        numbers[j] = temp;
      }
    }
  }
}

using namespace std;
int main(void){

  int n, diff, diff_all = 0;
  bool flag = true

  scanf("%d", &n);

  int a[100000];

  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  bubbleSort(a,n);

  begin = 0;

  for(int i = 0; i < ceil(n/2.0); i++){
    if(flag){
      end = n - 1 - i;
      flag = false;
    }else{
      end = i;
      flag = false;
    }
    diff =  std::abs(a[end] - a[begin]);
    printf("%d\n", diff);
    diff_all += diff;
    begin = end;

  }

  printf("%d\n", diff_all);

}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:3: error: expected ',' or ';' before 'scanf'
   26 |   scanf("%d", &n);
      |   ^~~~~
a.cc:36:11: error: overloaded function with no contextual type information
   36 |   begin = 0;
      |           ^
a.cc:40:21: error: overloaded function with no contextual type information
   40 |       end = n - 1 - i;
      |                     ^
a.cc:43:13: error: overloaded function with no contextual type information
   43 |       end = i;
      |             ^
a.cc:46:23: error: invalid types 'int [100000][<unresolved overloaded function type>]' for array subscript
   46 |     diff =  std::abs(a[end] - a[begin]);
      |                       ^
a.cc:46:32: error: invalid types 'int [100000][<unresolved overloaded function type>]' for array subscript
   46 |     diff =  std::abs(a[end] - a[begin]);
      |                                ^
a.cc:49:13: error: overloaded function with no contextual type information
   49 |     begin = end;
      |             ^~~
Language: C

n=gets.chomp.to_i
array=Array.new
for i in 0..n-1 do
	array[i]=gets.chomp.to_i
end


array=array.sort
reverse=array.reverse
minarray=Array.new
maxarray=Array.new



for i in 0..n-1 do

	if(i==0)
		minarray[0]=array[0]
		array.shift()
	elsif(i%4==1)
		minarray.insert(0,array.pop)

	elsif(i%4==2)
		minarray.push(array.pop)

	elsif(i%4==3)
		minarray.insert(0,array.first)
		array.shift()

	else
		minarray.push(array.first)
		array.shift()

	end
end


for i in 0..n-1 do

	if(i==0)
		maxarray[0]=reverse[0]
		reverse.shift()
	elsif(i%4==1)
		maxarray.insert(0,reverse.pop)
	elsif(i%4==2)
		maxarray.push(reverse.pop)
	elsif(i%4==3)
		maxarray.insert(0,reverse.first)
		reverse.shift()
	else
		maxarray.push(reverse.first)
		reverse.shift()
	end
end


sum1=0
sum2=0

for i in 0..n-2 do
		sum1 += (minarray[i]-minarray[i+1]).abs
end

for i in 0..n-2 do
		sum2 += (maxarray[i]-maxarray[i+1]).abs
end

puts [sum1,sum2].max

Compiler output:
main.c:1:1: warning: data definition has no type or storage class
    1 | n=gets.chomp.to_i
      | ^
main.c:1:1: error: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
main.c:1:3: error: 'gets' undeclared here (not in a function)
    1 | n=gets.chomp.to_i
      |   ^~~~
main.c:2:1: error: expected ',' or ';' before 'array'
    2 | array=Array.new
      | ^~~~~
main.c:3:10: error: too many decimal points in number
    3 | for i in 0..n-1 do
      |          ^~~~
main.c:15:10: error: too many decimal points in number
   15 | for i in 0..n-1 do
      |          ^~~~
main.c:38:10: error: too many decimal points in number
   38 | for i in 0..n-1 do
      |          ^~~~
main.c:60:10: error: too many decimal points in number
   60 | for i in 0..n-2 do
      |          ^~~~
main.c:64:10: error: too many decimal points in number
   64 | for i in 0..n-2 do
      |          ^~~~
Language: C

#include <stdio.h>
#include <string.h>
#include <iostream>
int* bubbleSort(int* A, int len);
int main(void)
{
	int N, A[100001],ans = 0;
	scanf_s("%d", &N);
	for (int i = 0; i < N; i++)
	{
		scanf_s("%d", &A[i]);
	}
	bubbleSort(A, N);
	/*if (N % 2 == 1)
	{*/
		for (int i = 0; i < N - 1; i++)	ans = ans + (A[N - i] - A[i]);
	/*}
	else
	{
		for (int i = 0; i < N - 1; i++)ans = ans + (A[N - i] - A[i]);
	}*/
	printf("%d", ans);
	return 0;
}
int* bubbleSort(int* A, int len) {
	int i, j;

	for (i = 0; i < len; i++) {
		for (j = len - 1; j > i; j--) {
			if (A[j] < A[j - 1]) {
				int temp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = temp;
			}
		}
	}
	return A;
}


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

#include<cstdio>
#define ll long long
#include<algorithm>
using namespace std;
const int MAX_N=100000+5;
ll arr[MAX_N];
int Next[MAX_N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%lld",&arr[i]);
    sort(arr,arr+n);
    Next[0]=n-1;
    Next[n-1]=1;
    int front,rear;
    front=0;
    rear=1;
    int frontT,rearT;
    frontT=n-1;
    rearT=n-1;
    int q,p;
    q=2;
    p=n-2;
    int i=0;
    while(p!=q)
    {
        if(i%2==0)
        {
            int k=abs(arr[q]-arr[front])>abs(arr[q]-arr[rear])?front:rear;
            Next[q]=k;
            if(k==front)
            {
                frontT=q;
                Next[q]=front;
                front=q;
            }
            else
            {
                rearT=rear;
                Next[rear]=q;
                rear=q;
            }
            q++;
        }
        else
        {
            int a=abs(arr[p]-arr[front])+abs(arr[p]-arr[frontT]);
            int b=abs(arr[p]-arr[rear])+abs(arr[p]-arr[rearT]);
            if(a>b)
            {
                Next[front]=p;
                Next[p]=frontT;
                frontT=p;
            }
            else
            {
                Next[rearT]=p;
                Next[p]=rear;
                rearT=p;
            }
            p--;
        }
        i++;
    }
    int cur=front;
    int count=0;
    ll sum=0;
    while(count!=n-1)
    {
        sum+=abs(arr[cur]-arr[Next[cur]);
        cur=Next[cur];
        count++;
    }
    printf("%lld\n",sum);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:72:40: error: expected ']' before ')' token
   72 |         sum+=abs(arr[cur]-arr[Next[cur]);
      |                                        ^
      |                                        ]
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;


int IntCompareA(const void* pElem1, const void* pElem2)
{
    return *(const int*)pElem1 - *(const int*)pElem2;
}


int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)
	{
    	int x;
    	cin >> x;
    	if(cin.eof())
        	break;
		
    	a[i]=x;
	}
	
	qsort(a,n,sizeof(int),IntCompareA);
	/*for(int i=0;i<n;i++){
		cout << a[i] << endl;
	}*/
	
	int gr=0;
	int ls=0;
	int sm=0;
	int ans;
	for(int i=0;i<n;i++){
		sm += a[i];
	}
	
	if(n%2==0){
		for(int i=0;i<n/2;i++){
			ls += a[i];
		}
		gr = sm-ls;
		cout<< (gr*2-a[n/2]) - (ls*2-a[(n/2)-1]);
	}else{
		for(int i=0;i<(n-1)/2;i++){
			ls += a[i];
			gr += a[n-1-i];
		}
		int k,l;
		k=2*gr+a[(n-1)/2]-a[(n+1)/2]-2*ls;
		l=2*gr-(2*ls-a[n]-a[n-1];)
		if(k>l){
			cout << k << endl;
		}else{
			cout <<l << endl;
		}
	}
	
	
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:41: error: expected ')' before ';' token
   55 |                 l=2*gr-(2*ls-a[n]-a[n-1];)
      |                        ~                ^
      |                                         )
a.cc:55:42: error: expected primary-expression before ')' token
   55 |                 l=2*gr-(2*ls-a[n]-a[n-1];)
      |                                          ^
a.cc:58:18: error: 'else' without a previous 'if'
   58 |                 }else{
      |                  ^~~~
Language: C++

#include <iostream>
#include <list>
#include <iterator>

using namespace std;

int main(int argc, const char * argv[]) {
    int N;
    list<int> V;
    int A;
    list<int>::iterator itr;
    list<int>::iterator a;
    int answer = 0;
    
    
    cin >> N;
    
    for (int i = 0; i < N; i++) {
        cin >> A;
        V.push_back(A);
    }
    sort(V.begin() ,V.end());
    
    for (int i = 0; i < V.size(); i++) {
        itr = V.end();
        a = V.begin();
        if (V.size() % 2 == 0) {  //偶数なら
        advance(a, (V.size() / 2 - 1));
        }
        else if(V.size() % 2 == 1) {
                advance(a, (V.size() / 2));
        }
        
        answer += abs(*itr - *a);
        V.erase(a);
        V.erase(itr);
        
        }
    
    return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:22:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   22 |     sort(V.begin() ,V.end());
      |     ^~~~
      |     short
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
int N,ans=0;
cin >> N;
vector<int> data(N),A(N);
for(int i=0;i <N ;i++){
cin >> data[i];
}
sort(data.begin(),data.end());
reverse(data.begin(),data.end());
A[N/2-1]=data[0];
for(int i=1;i<N;i++){
if(i%4==1 || i%4==2){
if(i%4==1){
A[N/2-1+i]=data[i];
}
else if(i%4==2){
A[N/2-1-i]=data[i];
}
}
else if (i%4==0 ||i%4 ==3){
if(i%4==0){
A[N/2-1-i]=data[N-1-i];
}
else if(i%4==3){
A[N/2-1+i]=data[N-1-i];
}
for(int i=1;i <N;i++){
if(A[i]-A[i-1]<0){
ans +=A[i-1]-A[i];
}
else if(A[i]-A[i-1]>0){
ans +=A[i]-A[i-1];
}
}
cout << ans << endl;
}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:2: error: expected '}' at end of input
   39 | }
      |  ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>

int main() {
	int n,k,all=0;
	std::cin >> n;

	std::vector<long long int> v(n);
	std::vector<long long int> a;

	for (int& x : v) {
		std::cin >> x;
	}

	std::sort(v.begin(), v.end());

	k = n / 2;

	if (n % 2 == 0) {
		k--;
	}

	a.push_back(v[k]);

	for (int i = 0; i < n/2+1; i++) {
		a.push_back(v[n-1-i]);
		a.push_back(v[i]);
	}

	
	/*
	std::cout << "\n";

	for (int i = 0; i < n; i++) {
		std::cout << a[i] << std::endl;
	}
	
	std::cout << "\n";
	*/

	if (n == 3) {
		a[0]=v[1];
		a[1]=v[0];
		a[2]=v[2];
	}

	for (int i = 0; i < n-1; i++) {
		all = all + abs(a[i] - a[i + 1]);
	}



	std::cout << all << std::endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:23: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'long long int'
   12 |         for (int& x : v) {
      |                       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
int N,ans=0;
cin >> N;
vector<int> data(N),A(N);
for(int i=0;i <N ;i++){
cin >> data[i];
}
sort(data.begin(),data.end());
reverse(data.begin(),data.end());
A[N/2-1]=data[0];
for(int i=1;i<N;i++){
if(i%4==1 || i%4==2){
if(i%4==1){
A[N/2-1+i]=data[i];
}
else if(i%4==2){
A[N/2-1-i]=data[i];
}
}
else if (i%4==0 ||i%4 ==3){
if(i%4==0){
A[N/2-1-i]=data[N-1-i];
}
else if(i%4==3){
A[N/2-1+i]=data[N-1-i];
}
for(int i=1;i <N;i++){
if(A[i]-A[i-1]<0){
ans +=A[i-1]-A[i];
}
else if(A[i]-A[i-1]>0){
ans +=A[i]-A[i-1];
}
}
cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:2: error: expected '}' at end of input
   38 | }
      |  ^
a.cc:13:21: note: to match this '{'
   13 | for(int i=1;i<N;i++){
      |                     ^
a.cc:38:2: error: expected '}' at end of input
   38 | }
      |  ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
int N,ans=0;
cin >> N;
vector<int> data(N),A(N);
for(int i=0;i <N ;i++){
cin >> data[i];
}
sort(data.begin(),data.end());
reverse(data.begin(),data.end());
A[N/2-1]=data[0];
for(int i=1;i<N;i++){
if(i%4==1 || i%4==2){
if(i%4==1){
A[N/2-1+i]=data[i];
}
else if(i%4==2){
A[N/2-1-i=data[i];
}
}
else if (i%4==0 ||i%4 ==3){
if(i%4==0){
A[N/2-1-i]=data[N-1-i];
}
else if(i%4==3){
A[N/2-1+i]=data[N-1-i];
}
for(int i=1;i <N;i++){
if(A[i]-A[i-1]<0){
ans +=A[i-1]-A[i];
}
else if(A[i]-A[i-1]>0){
ans +=A[i-A[i-1];
}
}
cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:8: error: lvalue required as left operand of assignment
   19 | A[N/2-1-i=data[i];
      |   ~~~~~^~
a.cc:19:18: error: expected ']' before ';' token
   19 | A[N/2-1-i=data[i];
      |                  ^
      |                  ]
a.cc:34:17: error: expected ']' before ';' token
   34 | ans +=A[i-A[i-1];
      |                 ^
      |                 ]
a.cc:38:2: error: expected '}' at end of input
   38 | }
      |  ^
a.cc:13:21: note: to match this '{'
   13 | for(int i=1;i<N;i++){
      |                     ^
a.cc:38:2: error: expected '}' at end of input
   38 | }
      |  ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
int N,ans=0;
cin >> N;
vector<int> data(N),A(N);
for(int i=0;i <N ;i++){
cin >> data[i];
}
sort(data.begin(),data.end());
reverse(data.begin(),data.end());
A[N/2-1]=data[0];
for(i=1;i<N;i++){
if(i%4==1 || i%4==2){
if(i%4==1){
A[N/2-1+i]=data[i];
}
else if(i%4==2){
A[N/2-1-i=data[i];
}
}
else if (i%4==0 ||i%4 ==3){
if(i%4==0){
A[N/2-1-i]=data[N-1-i];
}
else if(i%4==3){
A[N/2-1+i]=data[N-1-i];
}
for(int i=1;i <N;i++){
if(A[i]-A[i-1]<0){
ans +=A[i-1]-A[i];
}
else if(A[i]-A[i-1]>0){
ans +=A[i-A[i-1];
}
}
cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:5: error: 'i' was not declared in this scope
   13 | for(i=1;i<N;i++){
      |     ^
a.cc:19:18: error: expected ']' before ';' token
   19 | A[N/2-1-i=data[i];
      |                  ^
      |                  ]
a.cc:34:17: error: expected ']' before ';' token
   34 | ans +=A[i-A[i-1];
      |                 ^
      |                 ]
a.cc:38:2: error: expected '}' at end of input
   38 | }
      |  ^
a.cc:13:17: note: to match this '{'
   13 | for(i=1;i<N;i++){
      |                 ^
a.cc:38:2: error: expected '}' at end of input
   38 | }
      |  ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

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

int main(){long long N,ans=0;cin>>N;vector<long long> n(N);
           for(long long i=0;i<N;i++){
             cin>>n[i];}
           sort(n.begin(),n.end());
           if(N%2==0){
           if(n[N-1]-n[(N/2)-1]>=n[(N/2)-1]-n[0]){
             ans+=n[N-1]-n[(N/2)-1];
             for(long long i=1;i<N/2;i++){
               ans+=n[N-i]-n[i-1];
               ans+=n[N-i-1]-n[i-1];}}
           else{
             ans+=n[(N/2)-1]-n[0];
             for(long long i=1;i<N/2;i++){
               ans+=n[N-i]-n[i-1];
               ans+=n[N-1]-n[i];}}
             
           else{
           if(n[N-1]-n[(N-1)/2]>=n[(N-1)/2]-n[0]){
             ans+=n[N-1]-n[(N-1)/2];
             ans+=n[((N-1)/2)+1]-n[((N-1)/2)-1];
             for(long long i=1;i<(N-1)/2;i++){
               ans+=n[N-i]-n[i-1];
               ans+=n[N-i-1]-n[i-1];}}
           else{
             ans+=n[(N-1)/2]-n[0];
             ans+=n[((N-1)/2)+1]-n[((N-1)/2)-1];
             for(long long i=1;i<8N-1)/2;i++){
               ans+=n[N-i]-n[i-1];
               ans+=n[N-i]-n[i];}}
           cout<<ans;}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:12: error: expected '}' before 'else'
   20 |            else{
      |            ^~~~
a.cc:8:22: note: to match this '{'
    8 |            if(N%2==0){
      |                      ^
a.cc:30:34: error: unable to find numeric literal operator 'operator""N'
   30 |              for(long long i=1;i<8N-1)/2;i++){
      |                                  ^~
a.cc:30:38: error: expected ';' before ')' token
   30 |              for(long long i=1;i<8N-1)/2;i++){
      |                                      ^
      |                                      ;
a.cc:30:39: error: expected primary-expression before '/' token
   30 |              for(long long i=1;i<8N-1)/2;i++){
      |                                       ^
a.cc:30:42: error: 'i' was not declared in this scope
   30 |              for(long long i=1;i<8N-1)/2;i++){
      |                                          ^
a.cc:33:23: error: expected '}' at end of input
   33 |            cout<<ans;}
      |                       ^
a.cc:4:11: note: to match this '{'
    4 | int main(){long long N,ans=0;cin>>N;vector<long long> n(N);
      |           ^
Language: Java

import java.io.*;
import java.util.*;

public class progC {
  public
    static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        int sum = scan.nextInt();

        int v = 0;

        List<Integer> listA = new ArrayList<>();

        for(int i = 0; i < sum; i++){
            int a = scan.nextInt();
            listA.add(a);
        }

        Collections.sort(listA);

        for(int i = 0; i < listA.size(); i++){
            v += listA.get(listA.size() - 1) - listA.get(i);
        }

        System.out.println(v + 1);
        scan.close();

    }
}

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

#include<vector>
#include<iostream>
#include<cmath>
int main
{
	size_t n;
	std::cin>>n;
	std::vector<unsigned long long> input(n);
	for (size_t i{};i<n;++i)
		std::cin>>input[i];
	unsigned long long total{};
	for (size_t i{2};i<n;++i)
		total+=std::abs(input[i-1],input[i]);
	std::cout<<total;
	return 0;
}

Compiler output:
a.cc:4:5: error: cannot declare '::main' to be a global variable
    4 | int main
      |     ^~~~
a.cc:6:16: error: expected primary-expression before 'n'
    6 |         size_t n;
      |                ^
a.cc:6:16: error: expected '}' before 'n'
a.cc:5:1: note: to match this '{'
    5 | {
      | ^
a.cc:7:14: error: 'cin' in namespace 'std' does not name a type
    7 |         std::cin>>n;
      |              ^~~
In file included from a.cc:2:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:8:47: error: 'n' was not declared in this scope; did you mean 'yn'?
    8 |         std::vector<unsigned long long> input(n);
      |                                               ^
      |                                               yn
a.cc:9:9: error: expected unqualified-id before 'for'
    9 |         for (size_t i{};i<n;++i)
      |         ^~~
a.cc:9:25: error: 'i' does not name a type
    9 |         for (size_t i{};i<n;++i)
      |                         ^
a.cc:9:29: error: expected unqualified-id before '++' token
    9 |         for (size_t i{};i<n;++i)
      |                             ^~
a.cc:12:9: error: expected unqualified-id before 'for'
   12 |         for (size_t i{2};i<n;++i)
      |         ^~~
a.cc:12:26: error: 'i' does not name a type
   12 |         for (size_t i{2};i<n;++i)
      |                          ^
a.cc:12:30: error: expected unqualified-id before '++' token
   12 |         for (size_t i{2};i<n;++i)
      |                              ^~
a.cc:14:14: error: 'cout' in namespace 'std' does not name a type
   14 |         std::cout<<total;
      |              ^~~~
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:15:9: error: expected unqualified-id before 'return'
   15 |         return 0;
      |         ^~~~~~
a.cc:16:1: error: expected declaration before '}' token
   16 | }
      | ^
Language: C++

#include<iostream>
#include <string>
#include<algorithm>
#include <set>
using namespace std;

int main(void){
	ios::sync_with_stdio(false);
	int N,sum,i;
	cin >> N;
	//int a[N], b[N], c[N];
	int a[N];
	for (i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N, greater<int>());
	sum = 0;
	if (N % 2 == 0) {
		sum += a[0] - a[N - 1];
		for (i = 0; i < N / 2; i++) {
			sum += a[i] + a[i + 1] - a[N - i - 1] - a[N - i];
		}
	}
	else {
		sum += a[0] - a[N - 1];
		for (i = 0; i < N / 2; i++) {
			sum += a[i] + a[i + 1] - a[N - i - 1] - a[N - i];
		}
		if (a[(N - 1) / 2] - a[(N + 1) / 2] > a[(N - 3) / 2] - a[(N - 1) / 2]) {
			sum = += a[(N - 1) / 2] - a[(N + 1) / 2];
		}
		else {
			sum += a[(N - 3) / 2] - a[(N - 1) / 2];
		}
	}
	cout << sum;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:31: error: expected primary-expression before '+=' token
   30 |                         sum = += a[(N - 1) / 2] - a[(N + 1) / 2];
      |                               ^~
Language: C++

#include<vector>
#include<iostream>
#include<cmath>
int main
{
	size_t n;
	std::cin>>n;
	std::vector<unsigned long long>input(n);
	for (size_t i{};i<n;++i)
		std::cin>>input[i];
	unsigned long long total{};
	for (size_t i{2};i<n;++i)
		total+=std::abs(input[i-1],input[i]);
	std::cout<<total;
	return 0;
}

Compiler output:
a.cc:4:5: error: cannot declare '::main' to be a global variable
    4 | int main
      |     ^~~~
a.cc:6:16: error: expected primary-expression before 'n'
    6 |         size_t n;
      |                ^
a.cc:6:16: error: expected '}' before 'n'
a.cc:5:1: note: to match this '{'
    5 | {
      | ^
a.cc:7:14: error: 'cin' in namespace 'std' does not name a type
    7 |         std::cin>>n;
      |              ^~~
In file included from a.cc:2:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:8:46: error: 'n' was not declared in this scope; did you mean 'yn'?
    8 |         std::vector<unsigned long long>input(n);
      |                                              ^
      |                                              yn
a.cc:9:9: error: expected unqualified-id before 'for'
    9 |         for (size_t i{};i<n;++i)
      |         ^~~
a.cc:9:25: error: 'i' does not name a type
    9 |         for (size_t i{};i<n;++i)
      |                         ^
a.cc:9:29: error: expected unqualified-id before '++' token
    9 |         for (size_t i{};i<n;++i)
      |                             ^~
a.cc:12:9: error: expected unqualified-id before 'for'
   12 |         for (size_t i{2};i<n;++i)
      |         ^~~
a.cc:12:26: error: 'i' does not name a type
   12 |         for (size_t i{2};i<n;++i)
      |                          ^
a.cc:12:30: error: expected unqualified-id before '++' token
   12 |         for (size_t i{2};i<n;++i)
      |                              ^~
a.cc:14:14: error: 'cout' in namespace 'std' does not name a type
   14 |         std::cout<<total;
      |              ^~~~
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:15:9: error: expected unqualified-id before 'return'
   15 |         return 0;
      |         ^~~~~~
a.cc:16:1: error: expected declaration before '}' token
   16 | }
      | ^
Language: C++

#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>

using namespace std;

long long int main() {
   
   long long int N;
   cin >> N;
   long long int A[N];
   for (long long int i = 0; i < N; i++) {
      cin >> A[i];
   }
   
   sort(A, A + N);
  
   long long int k = N/2;
   long long int ans = 0;
   if (N == 3) {
      ans = A[2] + A[1] - 2 * A[0];
   } else if (N%2 == 0) {
      long long int max = 0;
      for (long long int i = 0; i < k - 1; i++) {
         long long int tmp = N - i - 1;
         max += A[tmp];
      }
      long long int min = 0;
      for (long long int i = 0; i < k - 1; i++) {
         long long int tmp = i;
         min += A[tmp];
      }
      ans = -A[k-1] + 2 * max - 2 * min + A[k];
   } else {
      long long int max = 0;
      for (long long int i = 0; i < k; i++) {
         long long int tmp = N - i - 1;
         max += A[tmp];
      }
      long long int min = 0;
      for (long long int i = 0; i < k - 1; i++) {
         long long int tmp = i;
         min += A[tmp];
      }
      ans = -A[k-1] + 2 * max - 2 * min - A[k]; 
   }
   
   cout << ans << endl;
   return 0;
}


Compiler output:
a.cc:9:11: error: '::main' must return 'int'
    9 | long long int main() {
      |           ^~~
Language: C++

#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>

using namespace std;

long long int main() {
   
   long long int N;
   cin >> N;
   long long int A[N];
   for (int i = 0; i < N; i++) {
      cin >> A[i];
   }
   
   sort(A, A + N);
  
   long long int k = N/2;
   long long int ans = 0;
   if (N == 3) {
      ans = A[2] + A[1] - 2 * A[0];
   } else if (N%2 == 0) {
      long long int max = 0;
      for (long long int i = 0; i < k - 1; i++) {
         long long int tmp = N - i - 1;
         max += A[tmp];
      }
      long long int min = 0;
      for (long long int i = 0; i < k - 1; i++) {
         long long int tmp = i;
         min += A[tmp];
      }
      ans = -A[k-1] + 2 * max - 2 * min + A[k];
   } else {
      long long int max = 0;
      for (long long int i = 0; i < k; i++) {
         long long int tmp = N - i - 1;
         max += A[tmp];
      }
      long long int min = 0;
      for (long long int i = 0; i < k - 1; i++) {
         long long int tmp = i;
         min += A[tmp];
      }
      ans = -A[k-1] + 2 * max - 2 * min - A[k]; 
   }
   
   cout << ans << endl;
   return 0;
}


Compiler output:
a.cc:9:11: error: '::main' must return 'int'
    9 | long long int main() {
      |           ^~~
Language: C++

#include<iostream>
#include <string>
#include<algorithm>
#include <set>
using namespace std;

int main(void){
	ios::sync_with_stdio(false);
	int N,sum;
	cin >> N;
	//int a[N], b[N], c[N];
	int a[N];
	for (i = 0; i < N; i++)cin >> a[i] >>endl;
	sort(a, a + N, greater<int>());
	sum = 0;
	if (N % 2 == 0) {
		sum += a[0] - a[N - 1];
		for (i = 0; i < N / 2; i++) {
			sum += a[i] + a[i + 1] - a[N - i - 1] - a[N - i];
		}
	}
	else {
		sum += a[0] - a[N - 1];
		for (i = 0; i < N / 2; i++) {
			sum += a[i] + a[i + 1] - a[N - i - 1] - a[N - i];
		}
		if (a[(N - 1) / 2] - a[(N + 1) / 2] > a[(N - 3) / 2] - a[(N - 1) / 2]) {
			sum = += a[(N - 1) / 2] - a[(N + 1) / 2];
		}
		else {
			sum += a[(N - 3) / 2] - a[(N - 1) / 2];
		}
	}
	cout << sum;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:14: error: 'i' was not declared in this scope
   13 |         for (i = 0; i < N; i++)cin >> a[i] >>endl;
      |              ^
a.cc:18:22: error: 'i' was not declared in this scope
   18 |                 for (i = 0; i < N / 2; i++) {
      |                      ^
a.cc:24:22: error: 'i' was not declared in this scope
   24 |                 for (i = 0; i < N / 2; i++) {
      |                      ^
a.cc:28:31: error: expected primary-expression before '+=' token
   28 |                         sum = += a[(N - 1) / 2] - a[(N + 1) / 2];
      |                               ^~
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void){
	int N;
	cin >> N;
	multiset<long long> input;
	for(int cnt = 0; cnt < N; cnt++){
		int temp;
		cin >> temp;
		input.insert(temp);
	}

	int index = 0;
	vector<long long> A = vector<long long>(N, 0);
	for(auto itr = input.begin(); itr != input.end(); itr++){
		A[index++] = *itr;
	}

	int lindex = 1, rindex = N - 2;
	vector<long long> B = vector<long long>(N, 0);
	index = 0;
	bool l_flag = false, r_flag = false;
	while(true){
		if(r_flag && !l_flag){
			lindex = 0;
			l_flag = true;
		}
		B[index++] = A[lindex];
		lindex += 2;
		if((lindex > rindex && l_flag && r_flag) || index == N) break;
		if(lindex >= N || (!l_flag && lindex > rindex)){
			l_flag = true;
			lindex = 0;
		}
		if(l_flag && !r_flag){
			rindex = N - 1;
			r_flag = true;
			continue;
		}
		B[index++] = A[rindex];
		rindex -= 2;
		if((lindex > rindex && l_flag && r_flag) || index == N) break;
		if(rindex < 0 || (!r_flag && lindex > rindex)){
			r_flag = true;
			rindex = N - 1;
		}
	}
	int Sum = 0;
	for(int cnt = 0; cnt < N - 1; cnt++){
		Sum += abs(B[cnt] - B[cnt+1]);
	}
	out << Sum << endl;
	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:60:9: error: 'out' was not declared in this scope
   60 |         out << Sum << endl;
      |         ^~~