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

#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,K,sum;
  sum = 0;
  cin >> N >> K;
  for(int i=0;i<N;i++){
  	int x,b;
    cin >> x;
    b=x-K;
    if(b>=0){
      sum+=b;
    }
    else if(b<0){
      if(-b>x){
        sum+=x
      }else{
      	sum=sum-b;
      }
    }
  }
  cout << sum*2 << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:15: error: expected ';' before '}' token
   17 |         sum+=x
      |               ^
      |               ;
   18 |       }else{
      |       ~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> x(n);
  for(int i=;i<n;i++){
    cin>>x[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=2*min(abs(x[i]),abs(k-x[i]));
  }
  cout<<ans;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:7:13: error: expected primary-expression before ';' token
    7 |   for(int i=;i<n;i++){
      |             ^
Language: C++

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

int main(){
  int N,K,sum=0;
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    if (x>K) sum+=x-K;
    else if(K>x&&K-x>x) sum += K-x;
    else sum+=x;
  }
  cout << x << endl;
}

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

#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N,K;
  cin >> N >> K;
  
  vector<int>ball(N,0);
  
  for(int i=0;i<N;i++){
    cin >> ball[i];
  }
  
  int ans = 0;
  
  for(int i=0;i<N;i++){
    if(ball[i] >= K - ball[i])
      ans += (K - ball[i]) : 2;
    else
      ans += ball[i] * 2;
  }
  
  cout << ans << endl;
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:27: error: expected ';' before ':' token
   18 |       ans += (K - ball[i]) : 2;
      |                           ^~
      |                           ;
Language: C++

#include <iostream>
#include <string>
using namespace std;
int main(void){
  int N,K;
  cin >> N >> K;
  
  vector<int>ball(N,0);
  
  for(int i=0;i<N;i++){
    cin >> ball[i];
  }
  
  int ans = 0;
  
  for(int i=0;i<N;i++){
    if(ball[i] >= K - ball[i])
      ans += (K - ball[i]) : 2;
    else
      ans += ball[i] * 2;
  }
  
  cout << ans << endl;
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:3: error: 'vector' was not declared in this scope
    8 |   vector<int>ball(N,0);
      |   ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | #include <string>
a.cc:8:10: error: expected primary-expression before 'int'
    8 |   vector<int>ball(N,0);
      |          ^~~
a.cc:11:12: error: 'ball' was not declared in this scope
   11 |     cin >> ball[i];
      |            ^~~~
a.cc:17:8: error: 'ball' was not declared in this scope
   17 |     if(ball[i] >= K - ball[i])
      |        ^~~~
Language: C++

#include <iostream>
#include <string>
using namespace std;
int main(Void){
  int N,K;
  cin >> N >> K;
  
  vector<int>ball(N,0);
  
  for(int i=0;i<N;i++){
    cin >> ball[i];
  }
  
  int ans = 0;
  
  for(int i=0;i<N;i++){
    if(ball[i] >= K - ball[i])
      ans += (K - ball[i]) : 2;
    else
      ans += ball[i] * 2;
  }
  
  cout << ans << endl;
  
  return 0;
}


Compiler output:
a.cc:4:5: error: cannot declare '::main' to be a global variable
    4 | int main(Void){
      |     ^~~~
a.cc:4:10: error: 'Void' was not declared in this scope; did you mean 'void'?
    4 | int main(Void){
      |          ^~~~
      |          void
Language: C

#include<stdio.h>

int main(void)
{
	int n, k;
	int x[100];
	scanf("%d %d %d", &n, &k, &x);

	int ans = 0;

	for ( int i = 1; i <= 100; i++ ) {
		scanf("%d", x);
		if ( k / 2 < x ) ans += (k - x) * 2;
		else {
			ans += x * 2;
		}
		printf("%d", ans);
	}
	return 0;
}

Compiler output:
main.c: In function 'main':
main.c:13:28: warning: comparison between pointer and integer
   13 |                 if ( k / 2 < x ) ans += (k - x) * 2;
      |                            ^
main.c:13:44: error: invalid operands to binary - (have 'int' and 'int *')
   13 |                 if ( k / 2 < x ) ans += (k - x) * 2;
      |                                            ^
      |                                            |
      |                                            int *
main.c:15:34: error: invalid operands to binary * (have 'int *' and 'int')
   15 |                         ans += x * 2;
      |                                ~ ^
      |                                |
      |                                int *
Language: C++

int main(){
    
  int N, K;
  int x;
  int ans;
  cin >> N >> K;
  for (int i = 0; i < N; i++){
      cin >> x;
      if ((x >= K && x*2 < (x - K)*2)
        || (x < K && (x*2*(-1)) > (x - K)*2)){
          ans += x*2;
      }
      else if (x >= K){
          ans += (x - K)*2;
      }
      else{
          ans -= (x - K)*2;
      }
  }
  cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:3: error: 'cin' was not declared in this scope
    6 |   cin >> N >> K;
      |   ^~~
a.cc:20:3: error: 'cout' was not declared in this scope
   20 |   cout << ans << endl;
      |   ^~~~
a.cc:20:18: error: 'endl' was not declared in this scope
   20 |   cout << ans << endl;
      |                  ^~~~
Language: C++

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

int main(){
  int N, K, x;
  int sum = 0;
  cin >> N >> K;
  
  for(int i = 0; i < N; i++){
    cin x;
    if(x >= K - x){
      sum += 2*(K - x);
    }
    else{
      sum += 2*x;
    }
  }
  cout << sum << endl;
}
  

Compiler output:
a.cc: In function 'int main()':
a.cc:10:8: error: expected ';' before 'x'
   10 |     cin x;
      |        ^~
      |        ;
Language: C++

#include<bits/stdc++.h>

using namespace std;

int main(){
  int N,K;
  cin>>N>>K;
  
     for(int i=0;i<N;i++){
         int x,step;
         cin>>x;
     	
        if(K-x<x){
          step+=(K-x)*2;
        }else{
          step+=2*x;
        }
     }
  cout<<step<<endl;
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:9: error: 'step' was not declared in this scope; did you mean 'strsep'?
   19 |   cout<<step<<endl;
      |         ^~~~
      |         strsep
Language: Java

import java.util.*;
//System.out.println("")

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int cnt = 0;
        for(int i=0; i<n; i++){
            int a = sc.nextInt();
            cnt = cnt + min(a*2,(k-a)*2);
        }
        System.out.println(cnt);
    }
}

Compiler output:
Main.java:12: error: cannot find symbol
            cnt = cnt + min(a*2,(k-a)*2);
                        ^
  symbol:   method min(int,int)
  location: class Main
1 error
Language: Java

import java.util.*;
//System.out.println("")

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int cnt = 0;
        for(int i=0; i<n; i++){
            int a = sc.nextInt();
            cnt = cnt + min(a*2,(K-x[i])*2);
        }
        System.out.println(cnt);
    }
}

Compiler output:
Main.java:12: error: cannot find symbol
            cnt = cnt + min(a*2,(K-x[i])*2);
                                 ^
  symbol:   variable K
  location: class Main
Main.java:12: error: cannot find symbol
            cnt = cnt + min(a*2,(K-x[i])*2);
                                   ^
  symbol:   variable x
  location: class Main
2 errors
Language: C++

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int sum = 0;
  int x;
  for (int i = 0; i < N ; i++){
    cin >> x;
    if (x < K){
      if(x < K - x)
        sum += x　* 2;
      else
        sum += (K - x) * 2;
    }
    
    else {
      sum += (x - K) * 2;
    }
  }
  
  cout << sum << endl;
}

Compiler output:
a.cc:14:16: error: extended character 　 is not valid in an identifier
   14 |         sum += x　* 2;
      |                ^
a.cc: In function 'int main()':
a.cc:14:16: error: 'x\U00003000' was not declared in this scope
   14 |         sum += x　* 2;
      |                ^~~
Language: C++

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int sum;
  int x;
  for (int i = 0; i < N ; i++){
    cin >> x;
    if (x < K){
      if(x < K - x)
        sum += x　* 2;
      else
        sum += (K - x) * 2;
    }
    
    else {
      sum += (x - K) * 2;
    }
  }
  
  cout << sum << endl;
}

Compiler output:
a.cc:14:16: error: extended character 　 is not valid in an identifier
   14 |         sum += x　* 2;
      |                ^
a.cc: In function 'int main()':
a.cc:14:16: error: 'x\U00003000' was not declared in this scope
   14 |         sum += x　* 2;
      |                ^~~
Language: C++

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

int main() {
  
  int N,a;
  cin>>N>>a;
  for(int i=0;i<N;i++){
    int b,count=0;
    cin>>b;
    
    if(b>a-b)
      count+=(a-b);
    else
      count+=b;
  }
  cout<<count*2<<endl;
  
    
    
  }


Compiler output:
a.cc: In function 'int main()':
a.cc:17:14: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator*'
   17 |   cout<<count*2<<endl;
      |         ~~~~~^~
Language: C++

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

int main() {
  
  int N,a;
  cin>>N>>a;
  for(int i=0;i<N;i++){
    int b,count=0;
    cin>>b;
    
    if(b>a-b)
      count+=(a-b);
    else
      count+=b;
  }
  cout<<2*count;
  
    
    
  }


Compiler output:
a.cc: In function 'int main()':
a.cc:17:10: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator*'
   17 |   cout<<2*count;
      |         ~^~~~~~
Language: C++

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

int main() {
  int N, K, d;
  cin >> N >> K;
  d = 0;
  for (int i = 0; i < N; i++) {
    int a, b, x;
    cin >> x;
    a = x * 2;
    b = (K - x) * 2;
    if (a > b){
      d += b;
    }
    else {
      d += a
    }
  }
  cout << d << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:13: error: expected ';' before '}' token
   17 |       d += a
      |             ^
      |             ;
   18 |     }
      |     ~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int N, K, sum=0;
  	cin >> N >> K;
  for(int i = 0; N > i; i++){
    int x, A, B;
    cin >> x;
    A = x;
    B = K - x;
   if(B > A){
   sum += A * 2;
   }else if(A >= B){
   sum += B * 2;
   }
  }
    

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

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

int main() {
  int n,k,x;
  cin >> n >> k;
  int sum=0;
  for(int =0;i<n;i++){
    cin >> x;
    if(x<=k-x){
      sum += 2*x;
    }
    else{
      sum += 2*(k-x);
    }
  }
  cout << sum << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:11: error: expected unqualified-id before '=' token
    8 |   for(int =0;i<n;i++){
      |           ^
a.cc:8:10: error: expected ';' before '=' token
    8 |   for(int =0;i<n;i++){
      |          ^~
      |          ;
a.cc:8:11: error: expected primary-expression before '=' token
    8 |   for(int =0;i<n;i++){
      |           ^
a.cc:8:14: error: 'i' was not declared in this scope
    8 |   for(int =0;i<n;i++){
      |              ^
a.cc:8:17: error: expected ')' before ';' token
    8 |   for(int =0;i<n;i++){
      |      ~          ^
      |                 )
a.cc:8:18: error: 'i' was not declared in this scope
    8 |   for(int =0;i<n;i++){
      |                  ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;
int n,k
int a[101];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	int ans=0;
	for(int i=1;i<=n;i++){
	 int tmp=min(a[i],K-a[i]);
	 ans+=tmp;
}
	cout<<ans*2;
		return 0;
}


Compiler output:
a.cc:8:1: error: expected initializer before 'int'
    8 | int a[101];
      | ^~~
a.cc: In function 'int main()':
a.cc:10:17: error: 'k' was not declared in this scope
   10 |         cin>>n>>k;
      |                 ^
a.cc:11:36: error: 'a' was not declared in this scope
   11 |         for(int i=1;i<=n;i++) cin>>a[i];
      |                                    ^
a.cc:14:22: error: 'a' was not declared in this scope
   14 |          int tmp=min(a[i],K-a[i]);
      |                      ^
a.cc:14:27: error: 'K' was not declared in this scope
   14 |          int tmp=min(a[i],K-a[i]);
      |                           ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;
int n,k
int a[101];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	int ans=0;
	for(int i=1;i<=n;i++) int tmp=min(a[i],K-a[i]),ans+=tmp;
	cout<<ans*2;
		return 0;
}


Compiler output:
a.cc:8:1: error: expected initializer before 'int'
    8 | int a[101];
      | ^~~
a.cc: In function 'int main()':
a.cc:10:17: error: 'k' was not declared in this scope
   10 |         cin>>n>>k;
      |                 ^
a.cc:11:36: error: 'a' was not declared in this scope
   11 |         for(int i=1;i<=n;i++) cin>>a[i];
      |                                    ^
a.cc:13:43: error: 'a' was not declared in this scope
   13 |         for(int i=1;i<=n;i++) int tmp=min(a[i],K-a[i]),ans+=tmp;
      |                                           ^
a.cc:13:48: error: 'K' was not declared in this scope
   13 |         for(int i=1;i<=n;i++) int tmp=min(a[i],K-a[i]),ans+=tmp;
      |                                                ^
Language: Java

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int count = scanner.nextInt();
	int lhs = 0;
    int rhs = scanner.nextInt();
    
    int[] balls = new int[count];
    for (int ix = 0; ix < count; ix++) {
      balls[ix] = scanner.nextInt();
    }
    
    int answer = 0;
    for (int ix = 0; ix < balls.size; ix++) {
      answer += Math.min(balls[ix], rhs - balls[ix]);
    }
    
	System.out.println(answer * 2);
  }
}

Compiler output:
Main.java:16: error: cannot find symbol
    for (int ix = 0; ix < balls.size; ix++) {
                               ^
  symbol:   variable size
  location: variable balls of type int[]
1 error
Language: Java

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int count = scanner.nextInt();
	int lhs = 0;
    int rhs = scanner.nextInt();
    
    int[] balls = new int[count];
    for (int ix = 0; ix < count; ix++) {
      balls[ix] = scanner.nextInt();
    }
    
    int answer = 0;
    for (int ix = 0; ix < balls.size; ix++) {
      answer += Math.min(balls[ix], rhs - balls[ix]);
    }
    
    return answer * 2;
  }
}

Compiler output:
Main.java:16: error: cannot find symbol
    for (int ix = 0; ix < balls.size; ix++) {
                               ^
  symbol:   variable size
  location: variable balls of type int[]
Main.java:20: error: incompatible types: unexpected return value
    return answer * 2;
                  ^
2 errors
Language: C++

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  int N,K;
  cin>>N>>K;
  int x[N];
  int ans=0;
  for(int i=0;i<N;i++){
    cin>>x[i];
    ans+=min(x[i],abs(x[i]-K))*2;
  }
  cout<<ans<<endl;


Compiler output:
a.cc: In function 'int main()':
a.cc:14:19: error: expected '}' at end of input
   14 |   cout<<ans<<endl;
      |                   ^
a.cc:5:12: note: to match this '{'
    5 | int main() {
      |            ^
Language: C

s;main(x,k){for(scanf("%*d%d",&k);~scanf("%d",&x);)s+=x>k/2?abs(x-k):x;printf("%d",s*2);

Compiler output:
main.c:1:1: warning: data definition has no type or storage class
    1 | s;main(x,k){for(scanf("%*d%d",&k);~scanf("%d",&x);)s+=x>k/2?abs(x-k):x;printf("%d",s*2);
      | ^
main.c:1:1: error: type defaults to 'int' in declaration of 's' [-Wimplicit-int]
main.c:1:3: error: return type defaults to 'int' [-Wimplicit-int]
    1 | s;main(x,k){for(scanf("%*d%d",&k);~scanf("%d",&x);)s+=x>k/2?abs(x-k):x;printf("%d",s*2);
      |   ^~~~
main.c: In function 'main':
main.c:1:3: error: type of 'x' defaults to 'int' [-Wimplicit-int]
main.c:1:3: error: type of 'k' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    1 | s;main(x,k){for(scanf("%*d%d",&k);~scanf("%d",&x);)s+=x>k/2?abs(x-k):x;printf("%d",s*2);
      |                 ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | s;main(x,k){for(scanf("%*d%d",&k);~scanf("%d",&x);)s+=x>k/2?abs(x-k):x;printf("%d",s*2);
main.c:1:17: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
    1 | s;main(x,k){for(scanf("%*d%d",&k);~scanf("%d",&x);)s+=x>k/2?abs(x-k):x;printf("%d",s*2);
      |                 ^~~~~
main.c:1:17: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:1:61: error: implicit declaration of function 'abs' [-Wimplicit-function-declaration]
    1 | s;main(x,k){for(scanf("%*d%d",&k);~scanf("%d",&x);)s+=x>k/2?abs(x-k):x;printf("%d",s*2);
      |                                                             ^~~
main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'abs'
  +++ |+#include <stdlib.h>
    1 | s;main(x,k){for(scanf("%*d%d",&k);~scanf("%d",&x);)s+=x>k/2?abs(x-k):x;printf("%d",s*2);
main.c:1:72: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
    1 | s;main(x,k){for(scanf("%*d%d",&k);~scanf("%d",&x);)s+=x>k/2?abs(x-k):x;printf("%d",s*2);
      |                                                                        ^~~~~~
main.c:1:72: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:72: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:1:72: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:1: error: expected declaration or statement at end of input
    1 | s;main(x,k){for(scanf("%*d%d",&k);~scanf("%d",&x);)s+=x>k/2?abs(x-k):x;printf("%d",s*2);
      | ^
Language: C++

#include<iostream>
using namespace std;

int main(){
    int n,k;
    vector<int>x(n);

    //入力
    cin >> n;
    cin >> k;
    for(int i=0; i<n; i++){
        cin << x[i];
    }

    //処理
    int dis_a,dis_b,ans;
    for(int i=0;i<n;i++){
        dis_a=x[i];
        dis_b=k-x[i];
        //絶対値調整
        if(dis_b<0)dis_b=-dis_b;
        if(dis_a<0)dis_a=-dis_a;

        if(dis_a>=dis_b)ans+=dis_b;
        if(dis_a<dis_b)ans+=dis_a;
    }

    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:5: error: 'vector' was not declared in this scope
    6 |     vector<int>x(n);
      |     ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include<iostream>
  +++ |+#include <vector>
    2 | using namespace std;
a.cc:6:12: error: expected primary-expression before 'int'
    6 |     vector<int>x(n);
      |            ^~~
a.cc:12:16: error: 'x' was not declared in this scope
   12 |         cin << x[i];
      |                ^
a.cc:18:15: error: 'x' was not declared in this scope
   18 |         dis_a=x[i];
      |               ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  in tn,k;
  cin>>n>>k;
  vi x(n);
  REP(i,n)cin>>x[i];
  int ans = 0;
  REP(i,n)ans += 2*min(x[i],k-x[i]);
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:35:3: error: 'in' was not declared in this scope; did you mean 'yn'?
   35 |   in tn,k;
      |   ^~
      |   yn
a.cc:36:8: error: 'n' was not declared in this scope; did you mean 'yn'?
   36 |   cin>>n>>k;
      |        ^
      |        yn
a.cc:36:11: error: 'k' was not declared in this scope
   36 |   cin>>n>>k;
      |           ^
Language: C++

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

int main() {
  int N, K, S;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int x, a, b;
    cin >> x;
    a = x * 2;
    if (x <= K){
      b = (K - x) * 2;
    } else {
      b = (x - K) * 2;
    }
    if (a =< b) {
      S += a;
    } else {
      S += b;
    }
  }
  cout << S << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:12: error: expected primary-expression before '<' token
   16 |     if (a =< b) {
      |            ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
  int n,k;
  cin >> n >> k;
  vector<int> x(n);
  vector<int> kata(n);
  int sumOfKata = 0;
  for(int i = 0; i<n; i++){
    cin >> x.at(i);
  }
  for(int i = 0; i<n; i++){
    if(x.at(i)<k-x.at(i) && k-x.at(i)>0){//kがxより大きいかつAの方が近い
      kata.at(i) = x.at(i);
    }else if(x.at(i)-k>0 && x.at(i)<x.at(i)-k){//kがxより小さいかつAのほうが近い
      kata.at(i) = x.at(i)
    }else if(k-x.at(i)>0 && x.at(i)>k-x.at(i)){//kがxより大きいときかつkのほうが近い
      kata.at(i) = k-x.at(i);
    }else if(x.at(i)-k>0 && x.at(i)>x.at(i)-k){//kがxより小さい時かつkのほうが近い
      kata.at(i) = x.at(i)-k;
    }else{
      kata.at(i) = x.at(i);
    }
  }//片道の配列完了
  for(int i = 0; i<n; i++){
    sumOfKata += kata.at(i);
  }
  cout << sumOfKata*2 << endl;
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:27: error: expected ';' before '}' token
   18 |       kata.at(i) = x.at(i)
      |                           ^
      |                           ;
   19 |     }else if(k-x.at(i)>0 && x.at(i)>k-x.at(i)){//kがxより大きいときかつkのほうが近い
      |     ~
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
  int n,k;
  cin >> n >> k;
  vector<int> x(n);
  vector<int> kata(n);
  int sumOfKata = 0;
  for(int i = 0; i<n; i++){
    cin >> x.at(i);
  }
  for(int i = 0; i<n; i++){
    if(x.at(i)<k-x.at(i)){
      kata.at(i) = x.at(i); // tabunOk
    }else if(k-x.at(i)>0){//kがxより大きいとき
      if(x.at(i)>k-x.at(i)){
        kata.at(i) = k-x.at(i);
      }
    }else if(x.at(i)-k>0){//kがxより小さい時
      if(x.at(i)>x.at(i)-k){
        kata.at(i) = x.at(i)-k;
      }
    }else{
      kata.at(i) = x.at(i);
    }
  }//片道の配列完了
  for(int i = 0; i<N; i++){
    sumOfKata += kata.at(i);
  }
  cout << sumOfKata*2 << endl;
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:20: error: 'N' was not declared in this scope
   29 |   for(int i = 0; i<N; i++){
      |                    ^
Language: C++

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

int main(){
	int N,K,ans=0;
  	cin>>N>>K;
  	for(int i=0;i<N;++i){
      cin>>x;
      ans+=min(x,K-x);
    }
  	cout<<ans<<endl;
  	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:12: error: 'x' was not declared in this scope
    9 |       cin>>x;
      |            ^
Language: C++

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

int main () {
  int i,l,N,K,x;
  l=0
  for (i=0;i<N;i++) {
    cin >> x;
    if (x<(K-x)) {
      l+=x;
    }
    else {
      l+=(K-x);
    }
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:6: error: expected ';' before 'for'
    6 |   l=0
      |      ^
      |      ;
    7 |   for (i=0;i<N;i++) {
      |   ~~~ 
a.cc:7:19: error: expected ';' before ')' token
    7 |   for (i=0;i<N;i++) {
      |                   ^
      |                   ;
Language: C++

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

int main(){
  int N,K;
  cin>>N>>K;
  int sum=0;
  for(int i=0;i<N;i++){
    int p;
    cin>>p;
    if(p>=K){
      sum+=p-K;
    }
    else if(K-p<=p){
      sum+=K-p;
    }
    else if(K-p>p){
      sum+=p
    }
  }
  cout<<sum<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:13: error: expected ';' before '}' token
   18 |       sum+=p
      |             ^
      |             ;
   19 |     }
      |     ~
Language: C++

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

int main(){
  int N,K;
  cin>>N>>K;
  int sum=0;
  for(int i=0;i<N;i++){
    int p;
    cin>>p;
    if(p>=K){
      x+=p-K;
    }
    else if(K-p<=p){
      x+=K-p;
    }
    else if(K-p>p){
      x+=p
    }
  }
  cout<<x<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:7: error: 'x' was not declared in this scope
   12 |       x+=p-K;
      |       ^
a.cc:15:7: error: 'x' was not declared in this scope
   15 |       x+=K-p;
      |       ^
a.cc:18:7: error: 'x' was not declared in this scope
   18 |       x+=p
      |       ^
a.cc:21:9: error: 'x' was not declared in this scope
   21 |   cout<<x<<endl;
      |         ^
Language: C++

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

int main ()
{
  int N,K,A;
  cin >> N;
  cin >> K;
  int x;
  
  while(N > 0){
    cin >> x;
    if(k - x <= -1){
      k - x = -(k - x);
    }
    if(K - x >= x){
      A += x;
  	}else{
   	  A += K - x;
  	}
    N--;
  }
  
  cout << A << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:8: error: 'k' was not declared in this scope
   13 |     if(k - x <= -1){
      |        ^
Language: C

int def2(int a, int b){return a<b?b-a:a-b;}
int min2(int a, int b){return a>b?b:a;}
int n, k, x, ans, now, i;
int main(){
  scanf("%d%d", &n, &k);
  for(i=0; i<n; i++){
    scanf("%d", &x);
    now=min(def2(0,x),def2(k,x))<<1;
    ans+=now;
  }
  printf("%d\n", ans);
}

Compiler output:
main.c: In function 'main':
main.c:5:3: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    5 |   scanf("%d%d", &n, &k);
      |   ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | int def2(int a, int b){return a<b?b-a:a-b;}
main.c:5:3: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
    5 |   scanf("%d%d", &n, &k);
      |   ^~~~~
main.c:5:3: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:8:9: error: implicit declaration of function 'min'; did you mean 'main'? [-Wimplicit-function-declaration]
    8 |     now=min(def2(0,x),def2(k,x))<<1;
      |         ^~~
      |         main
main.c:11:3: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   11 |   printf("%d\n", ans);
      |   ^~~~~~
main.c:11:3: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:11:3: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:11:3: note: include '<stdio.h>' or provide a declaration of 'printf'
Language: C++

#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX_N = 100;
int N, K;
int X[MAX_N];
int main(){
scanf("%d", &N);
scanf("%d", &K);
for(int i = 0; i < N; ++i){
scanf("%d", X + i);
}
int ans = 0;
for(int i = 0; i < N; ++i){
int tmp = min(X[i], K - X[i]);
ans += tmp;
}
printf("%d\n", ans * 2);
return 0;

Compiler output:
a.cc: In function 'int main()':
a.cc:19:10: error: expected '}' at end of input
   19 | return 0;
      |          ^
a.cc:7:11: note: to match this '{'
    7 | int main(){
      |           ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int n,k,a;
  cin >> n >> k;
  for(int i =0;i < a;i++) {
    int x;
    cin >> x;
    
    if(x*x >(k-x)*(k-x) ) sum+=(k-x)*2;
    else sum+=x*2;
}
  cout << sum <<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:27: error: 'sum' was not declared in this scope
   12 |     if(x*x >(k-x)*(k-x) ) sum+=(k-x)*2;
      |                           ^~~
a.cc:13:10: error: 'sum' was not declared in this scope
   13 |     else sum+=x*2;
      |          ^~~
a.cc:15:11: error: 'sum' was not declared in this scope
   15 |   cout << sum <<endl;
      |           ^~~
Language: C++

#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

template<typename T> void Show(vector<vector<T>> v) {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j];
			if (j != v[i].size() - 1) {
				cout << " ";
			} else {
				cout << endl;
			}
		}
	}
}


template<typename T> void Show(vector<T> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i != v.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	int N, K;
	cin >> N >> K;
	vector<int> Xs = vector<int>();
	Xs.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> Xs[i];
	}
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += min(Xs[i], K - Xs[i]) * 2;
	}
	cout << sun << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:17: error: 'sun' was not declared in this scope; did you mean 'sum'?
   53 |         cout << sun << endl;
      |                 ^~~
      |                 sum
Language: C++

include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

template<typename T> void Show(vector<vector<T>> v) {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j];
			if (j != v[i].size() - 1) {
				cout << " ";
			} else {
				cout << endl;
			}
		}
	}
}


template<typename T> void Show(vector<T> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i != v.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	int N, K;
	cin >> N >> K;
	vector<int> Xs = vector<int>();
	Xs.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> Xs[i];
	}
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += min(Xs[i], K - Xs[i]) * 2;
	}
	cout << sun << endl;
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include <algorithm>
      | ^~~~~~~
In file included from /usr/include/c++/14/array:39,
                 from a.cc:2:
/usr/include/c++/14/initializer_list:51:15: error: 'size_t' does not name a type
   51 |       typedef size_t            size_type;
      |               ^~~~~~
/usr/include/c++/14/initializer_list:1:1: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
  +++ |+#include <cstddef>
    1 | // std::initializer_list support -*- C++ -*-
/usr/include/c++/14/initializer_list:57:7: error: 'size_type' does not name a type
   57 |       size_type                 _M_len;
      |       ^~~~~~~~~
/usr/include/c++/14/initializer_list:60:54: error: 'size_type' has not been declared
   60 |       constexpr initializer_list(const_iterator __a, size_type __l)
      |                                                      ^~~~~~~~~
/usr/include/c++/14/initializer_list:68:17: error: 'size_type' does not name a type
   68 |       constexpr size_type
      |                 ^~~~~~~~~
/usr/include/c++/14/initializer_list:45:11: fatal error: definition of 'class std::initializer_list<_E>' does not match '#include <initializer_list>'
   45 |     class initializer_list
      |           ^~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    int n, k;
    cin >> n >> k;

    vector<int> balls(n);
    rep(i, n) cin >> balls[i];

    int sum = 0;
    rep(i, n) sum += min(balls[i], abs(k - balls[i]));

    cout << sum * 2 << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:5: error: 'cin' was not declared in this scope
   20 |     cin >> n >> k;
      |     ^~~
a.cc:8:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    7 | #include <numeric>
  +++ |+#include <iostream>
    8 | 
a.cc:28:5: error: 'cout' was not declared in this scope
   28 |     cout << sum * 2 << endl;
      |     ^~~~
a.cc:28:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:28:24: error: 'endl' was not declared in this scope
   28 |     cout << sum * 2 << endl;
      |                        ^~~~
a.cc:8:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    7 | #include <numeric>
  +++ |+#include <ostream>
    8 |
Language: C++

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

int main() {
  int N, K;
  int x;
  cin >> N >> K;
  int mid = K/2;
  int sum = 0;
  for(i = 0; i < N; i++) {
    cin >> x;
    if(mid > x)
      sum += (K - x) * 2;
    else sum += x * 2;
  }
  cout << x << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:7: error: 'i' was not declared in this scope
   10 |   for(i = 0; i < N; i++) {
      |       ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,K;
  cin>>n>>K;
  int x,ans;
  ans=0;
  for (int i=0;i<n;i++){
    cin>>x;
    ans+=min(2*x,2*(K-x));
  }
  cout<<ans<<endl
}
      

Compiler output:
a.cc: In function 'int main()':
a.cc:12:18: error: expected ';' before '}' token
   12 |   cout<<ans<<endl
      |                  ^
      |                  ;
   13 | }
      | ~
Language: C

#include <cstdio>
#include <algorithm>

using namespace std;

const int man_n = 100;

int n,k;
int x[max_n];

int main(){
    scanf("%d", &n);
    scanf("%d", &k);
    for(int i=0;i<n;i++) scanf("%d", x + i);
     int ans=0;
     for(int i=0;i<n;i++){
         int tmp = min(x[i], k-x[i]);
         ans += tmp;
     }
     printf("%d \n", ans*2);
     return 0;
}


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

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

int main() {

 int N,K;
  cin >> N >> K;
  
  int x = 0;
  int a
 for(int i=0;i<N;i++){
   cin << a;
   if (K-a > a){
     x += a;
   }
   else if(K<a){
     x += a-K;
   }
   else{
     x += K-a;
   }
 }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:2: error: expected initializer before 'for'
   11 |  for(int i=0;i<N;i++){
      |  ^~~
a.cc:11:14: error: 'i' was not declared in this scope
   11 |  for(int i=0;i<N;i++){
      |              ^
Language: C++

#include <cstdio>
#include <algorithm>

using namespace std;

const int man_n = 100;

int n,k;
int x[max_n];

int main(){
    scanf("%d", &n);
    scanf("%d", &k);
    for(int i=0;i<n;i++) scanf("%d", x + i);
     int ans=0;
     for(int i=0;i<n;i++){
         int tmp = min(x[i], k-x[i]);
         ans += tmp;
     }
     printf("%d \n", ans*2);
     return 0;
}

Compiler output:
a.cc:9:7: error: 'max_n' was not declared in this scope; did you mean 'man_n'?
    9 | int x[max_n];
      |       ^~~~~
      |       man_n
a.cc: In function 'int main()':
a.cc:14:38: error: 'x' was not declared in this scope
   14 |     for(int i=0;i<n;i++) scanf("%d", x + i);
      |                                      ^
a.cc:17:24: error: 'x' was not declared in this scope
   17 |          int tmp = min(x[i], k-x[i]);
      |                        ^
Language: C++

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

int main() {
  int N, K;
  cin >> N >> K;
  int x, s;
  for (i=0; i<N; i++) {
    cin >> x;
    x = 2*x;
    if (x > K)
      x = 2*K - x;
    s += x;
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:8: error: 'i' was not declared in this scope
    8 |   for (i=0; i<N; i++) {
      |        ^
Language: C++

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

int main(){
  int N;
  cin >> N;
  
  for(int i=0;i<N;i++){
    string S;
    cin >> S;
    if(S=="Y"){
      cout << "Four" << endl;
      break;
    }else if(i==N){
      cout << "Three" << endl;
    }
    i++;
}


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

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

int main(){
  int N;
  cin >> N;
  
  for(int i=0;i<N;i++){
    string S;
    cin >> S;
    if(S=="Y"){
      cout << "Four" << endl;
      break;
    }else if(i==N){
      cout << "Three" << endl;
    }
}


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

#include<iostream>
using namespace std;

int main(){
  int N, K, x, S;
  cin >> N >> K;
  S = 0
  for(int i = 0; i < N; i++){
    cin >> x;
    if((K-x) < x){
      S += (K-x)*2;
    }else if((K-x) >= x){
      S += x*2;
    }
  }
  cout << S << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:8: error: expected ';' before 'for'
    7 |   S = 0
      |        ^
      |        ;
    8 |   for(int i = 0; i < N; i++){
      |   ~~~   
a.cc:8:18: error: 'i' was not declared in this scope
    8 |   for(int i = 0; i < N; i++){
      |                  ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, K, A[N];
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int asn = 0;
	for (int i = 0; i < N; i++) {
		ans += min(abs(A[i]), abs(A[i] - K));
	}

	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:11:17: error: 'ans' was not declared in this scope; did you mean 'asn'?
   11 |                 ans += min(abs(A[i]), abs(A[i] - K));
      |                 ^~~
      |                 asn
a.cc:14:17: error: 'ans' was not declared in this scope; did you mean 'asn'?
   14 |         cout << ans << endl;
      |                 ^~~
      |                 asn
Language: C++

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

int main() {
  int N , K;
  cin >> N >> K;
  int sum = 0;
  int i = 0;
  while(i < N ){
    cin >> x;
    A = x * 2;
    B = (K - x) * 2;
    if(A >= B){
   sum += B;
    }
    else{
      sum += A;
    }
      i++;
  }
    cout << sum << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:12: error: 'x' was not declared in this scope
   10 |     cin >> x;
      |            ^
a.cc:11:5: error: 'A' was not declared in this scope
   11 |     A = x * 2;
      |     ^
a.cc:12:5: error: 'B' was not declared in this scope
   12 |     B = (K - x) * 2;
      |     ^
Language: C++

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

int main() {
  int N , K;
  cin >> N >> K;
  int sum = 0;
  int i = 0;
  while(i < N ){
    cin >> x
    A = x * 2;
    B = (K - x) * 2;
    if(A >= B){
   sum += B;
    }
    else{
      sum += A;
    }
      i++;
  }
    cout << sum << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:12: error: 'x' was not declared in this scope
   10 |     cin >> x
      |            ^
a.cc:12:5: error: 'B' was not declared in this scope
   12 |     B = (K - x) * 2;
      |     ^
a.cc:13:8: error: 'A' was not declared in this scope
   13 |     if(A >= B){
      |        ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        ans+=min(x*2,(k-x)*2)
    }
    cout<<ans<<endl;
    return 0;
} 

Compiler output:
a.cc: In function 'int main()':
a.cc:9:30: error: expected ';' before '}' token
    9 |         ans+=min(x*2,(k-x)*2)
      |                              ^
      |                              ;
   10 |     }
      |     ~
Language: C++

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

int main() {
  int N,K;
  int L = 0;
  vector<int> x(N);
  
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
    cin >> x.at(i);
    if(K-x.at(i) > x.at(i)){
      L += (K - x.at(i))*2;
    }else{
      L += K*2
    }
  }
  cout << L << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:15: error: expected ';' before '}' token
   16 |       L += K*2
      |               ^
      |               ;
   17 |     }
      |     ~
Language: C++

// Collecting Balls (Easy Version)

#include <iostream>

using namespace std;

int main(){
	int N, K;
	cin >> N >> K;
	int x[N];
	for (int i = 0; i < N; ++i)
		cin >> x[i];

	sort(x, x+N);

	int res = 0;

	for (int i = 0; i < N; ++i){
		if (x[i] <= abs(x[i]-K))
			res += x[i] * 2;
		else
			res += abs(x[i]-K) * 2;
	}

	cout << res << endl;

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   14 |         sort(x, x+N);
      |         ^~~~
      |         short
Language: C++

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

int main() {
  int N, K, x, middle, distance = 0;

  cin >> N;
  cin >> K;

  middle = (K + 1) / 2 //中点のx座標
  
  for (int i = 0; i < N; i++){
    cin >> x;

    if (x <= middle){
      distance += 2 * x; //中点以下のときの1つのボールを取りにいたときの移動距離 
    }
    else{
      distance += 2 * (K - x); //中点より大きいときの移動距離
    }
  }
  cout << distance << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:23: error: expected ';' before 'for'
   10 |   middle = (K + 1) / 2 //中点のx座標
      |                       ^
      |                       ;
   11 | 
   12 |   for (int i = 0; i < N; i++){
      |   ~~~                  
a.cc:12:19: error: 'i' was not declared in this scope
   12 |   for (int i = 0; i < N; i++){
      |                   ^
Language: C++

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

int main() {
  int N,K,count;
  cin >> N >> K;
  for(int i = 0;i < N;i++){
    int x;
    cin >> x;
    if(x>K-x)count += 2*(K-x);
    if(x<=K-x)count += 2*x
  }
  cout << count << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:27: error: expected ';' before '}' token
   11 |     if(x<=K-x)count += 2*x
      |                           ^
      |                           ;
   12 |   }
      |   ~
Language: C++

#include <cmath>
#include <vector>

using namespace std;

int main(void){
    int n,k;
    cin >> n >> k;

    int x[n];
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    
    int ans = 0;
    for(int i=0;i<n;i++){
        ans = ans + min(2 * abs(k-x[i]), 2 * abs(x[i]));
    }
    cout << ans << endl;
    return 0;
       
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:5: error: 'cin' was not declared in this scope
    8 |     cin >> n >> k;
      |     ^~~
a.cc:3:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include <vector>
  +++ |+#include <iostream>
    3 | 
a.cc:19:5: error: 'cout' was not declared in this scope
   19 |     cout << ans << endl;
      |     ^~~~
a.cc:19:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:19:20: error: 'endl' was not declared in this scope
   19 |     cout << ans << endl;
      |                    ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include <vector>
  +++ |+#include <ostream>
    3 |
Language: C++

#include <cstdio>
using namespace std;

int main(void){
  int n,k;
  int a[100];
  int ans = 0;
  
  scanf("%d%d",&n,&k);
  for (int i=0; i<n; i++){
    scanf("%d", &a[i]);
    ans += a[i]<k-a[i]?a[i]:k-a[i];
  }
  prontf("%d\n",ans*2);
  return 0;
}
  

Compiler output:
a.cc: In function 'int main()':
a.cc:14:3: error: 'prontf' was not declared in this scope; did you mean 'printf'?
   14 |   prontf("%d\n",ans*2);
      |   ^~~~~~
      |   printf
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K,x,sum=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>x;
      if(K<=x){
        sum=sum+(x-K+1)*2;
      }
    else{
      sum=sum+(min(x,K-x)+1)*2;
    }
    cout<<sum<<endl;
      

Compiler output:
a.cc: In function 'int main()':
a.cc:14:21: error: expected '}' at end of input
   14 |     cout<<sum<<endl;
      |                     ^
a.cc:6:23: note: to match this '{'
    6 |   for(int i=0;i<N;i++){
      |                       ^
a.cc:14:21: error: expected '}' at end of input
   14 |     cout<<sum<<endl;
      |                     ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K,x;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>x;
      if(K<=x){
        sum=sum+(x-K+1)*2;
      }
    else{
      sum=sum+(min(x,K-x)+1)*2;
    }
    cout<<sum<<endl;
      

Compiler output:
a.cc: In function 'int main()':
a.cc:9:9: error: 'sum' was not declared in this scope
    9 |         sum=sum+(x-K+1)*2;
      |         ^~~
a.cc:12:7: error: 'sum' was not declared in this scope
   12 |       sum=sum+(min(x,K-x)+1)*2;
      |       ^~~
a.cc:14:11: error: 'sum' was not declared in this scope
   14 |     cout<<sum<<endl;
      |           ^~~
a.cc:14:21: error: expected '}' at end of input
   14 |     cout<<sum<<endl;
      |                     ^
a.cc:6:23: note: to match this '{'
    6 |   for(int i=0;i<N;i++){
      |                       ^
a.cc:14:21: error: expected '}' at end of input
   14 |     cout<<sum<<endl;
      |                     ^
a.cc:3:11: note: to match this '{'
    3 | int main(){
      |           ^
Language: C++

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

int main(){
	int n,k,x;
  	cin >> n >>k;
  	for(i=0;i<n;i++){
    int d;
    cin d;
    if (d<=k/2) x +=2*d;
     else x +=2*k-2*d; 
    }
cout << x <<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:13: error: 'i' was not declared in this scope
    7 |         for(i=0;i<n;i++){
      |             ^
a.cc:9:8: error: expected ';' before 'd'
    9 |     cin d;
      |        ^~
      |        ;
Language: C++

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

int main(){
	int N, K, x, a=0;
	cin >> N >> K;
	for(i=0; i<N; i++){
		cin >> x;
		a += 2*min(x, K-x);
	}
	cout << a;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:13: error: 'i' was not declared in this scope
    8 |         for(i=0; i<N; i++){
      |             ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()
#define P pair<int,int>
#define pb(v) push_back(v)
#define V vector<int>
#define S set<int>
int main(){
    CIN(N);
    CIN(K);
    V vec;
    REP(a,N)CIN(b);vec.pb(b);
    int ans = 0;
    REP(a,N){
        ans += 2*min(abs(vec.at(a)-K),vec.at(a));
    }
    COUT(ans);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:17: error: 'b' was not declared in this scope
   25 |     REP(a,N)CIN(b);vec.pb(b);
      |                 ^
a.cc:4:32: note: in definition of macro 'CIN'
    4 | #define CIN(n)  int(n);cin >> (n)
      |                                ^