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

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n,m,i,j,k;
    long min=1000000,sum=0;
    bool eflg,nflowflg;
    cin>>n>>m;
    vector<int> x(m);
    vector<int> chosen(n+1);//しきりのいち
    vector<int> csum(n);
    for(i=0;i<m;i++){
        cin>>x[i];
    }

    if(n>=m){
        cout << 0 << endl;
        return 0;
    }

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




    chosen[0]=0,chosen[n]=m;


    for(i=1;i<n;i++){
        chosen[i]=i;
    }
   // for_each(chosen.begin(), chosen.end(), [](int i) { cout << i << ' ';});

    while(true){

        sum=0;
    for(i=1;i<=n;i++){
        sum+=x[chosen[i]-1]-x[chosen[i-1]];
    }
    //cout << sum << endl;
    if(min>sum)min=sum;

    for(i=n-1;i>=1;i--){
        if(chosen[i]>=chosen[i+1]){

            chosen[i-1]++;
            chosen[i]=chosen[i-1]+1;
        }
    }
    eflg=true;
    nflowflg=false;
    for(i=n-1;i>=1;i--) {
    if(chosen[i]<m-1-i+n-1){
        chosen[i]++;
        eflg=false;
        if(nflowflg)chosen[i+1]=chosen[i]+1;
        nflowflg=false;
        break;
    }else{
        nflowflg=true;
    }
    }

   // for_each(chosen.begin(), chosen.end(), [](int i) { cout << i << ' ';});
    //cout << " " << endl;
    if(eflg)break;

    }




   // for_each(x.begin(), x.end(), [](int i) { cout << i << ' ';});

    cout << min << endl;

    return 0;
}

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

#include<stdio.h>
#include<stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main(){
  int N,M,X[100000],t,a,b,max,min,len;
  int partation[100000]={0};　//どこで区切るか
  scanf("%d %d",&N,&M);
  for(int i=0;i<M;i++){
    scanf("%d",&X[i]);
  }
  qsort(X, M, sizeof(int), compare_int);
  max=X[M-1];
  min=X[0];
  for(int i=0;i<M-1;i++){
    a=partation[N-2];
    if(X[i+1]-X[i]<X[a]-X[a+1])continue;
    for(int j=0;j<N-1;j++){
      a=partation[j];
      if(X[i]-X[i-1]>X[a+1]-X[a]){
        partation[j]=i;
        break;
      }
    }
  }
  len=max-min;
  a=partation[0];
  len=len-(X[a+1]-X[a]);
  for(int i=1;i<N;i++){
    if(partation[i]!=partation[i-1]){
      a=partation[i];
      len=X[a+1]-X[a];
    }
  }
  printf("%d",len);
}

Compiler output:
main.c: In function 'main':
main.c:9:29: error: stray '\343' in program
    9 |   int partation[100000]={0};<U+3000>//<U+3069><U+3053><U+3067><U+533A><U+5207><U+308B><U+304B>
      |                             ^~~~~~~~
Language: C++

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

// int 型要素を昇順ソートするときの比較関数
int IntCompareA(const void* pElem1, const void* pElem2)
{
    return *(const int*)pElem1 - *(const int*)pElem2;
}

int main()
{
	int n,m;
	int x[100000];
	std::cin>>n>>m;
	for(int i=0;i<m;i++)
	    std::cin>>x[i];
    qsort(x, n, sizeof *x, IntCompareA);
    
    int dist[100000];
    for(int i=0;i<m-1;i++){
        dist[i]=abs(x[i+1]-x[i]);
    }
    qsort(dist, m-1, sizeof *dist, IntCompareA);
    int sum=0;
    if(m-n-1>0){
        for(int i=0;i<m-n-1;i++){
            sum+=dist[i];
        }
    }
    cout<<sum;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   31 |     cout<<sum;
      |     ^~~~
      |     std::cout
In file included from a.cc:1:
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
Language: C++

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

int main(){
    int N, M, X[100001];
    bool flag = 1;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> X[i];
        for(int j = 0; flag; j++){
            flag = 0;
            for(int k = N - 1; k >= j + 1; k--){
                if(X[k] < X[k - 1]){
                    swap(X[k], X[k - 1]);
                    flag = 1;
                }
            }
        }
    }
    int ans = 0;
    if(M == 1) cout << ans << endl;
    else{
        int d[100001];
        for(int i = 0; i < M - 1; i++){
            d[i] = abs(X[i] - X[i + 1]);
        }
        for(int j = 0; flag; j++){
            flag = 0;
            for(int k = N - 1; k >= i + 1; k--){
                if(X[k] < X[k - 1]){
                    swap(X[k], X[k - 1]);
                    flag = 1;
                }
            }
        }
        for(int i = 0; i < M - N + 1; i++){
            ans += d[i];
        }
        cout << ans << endl;
    }
    return 0;
}

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

#include<stdio.h>
#include<stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main(){
  int N,M,X[100000],t,a,b,max,min,len;
  int partation[100000]={0};　//どこで区切るか
  scanf("%d %d",&N,&M);
  for(int i=0;i<M;i++){
    scanf("%d",&X[i]);
  }
  qsort(X, M, sizeof(int), compare_int);
  max=X[M-1];
  min=X[0];
  for(int i=0;i<M-1;i++){
    a=partation[N-2];
    if(X[i+1]-X[i]<X[a]-X[a+1])continue;
    for(int j=0;j<N-1;j++){
      a=partation[j];
      if(X[i]-X[i-1]>X[a+1]-X[a]){
        partation[j]=i;
        break;
      }
    }
  }
  len=max-min;
  a=partation[0];
  len=len-(X[a+1]-X[a])
  for(int i=1;i<N;i++){
    if(partation[i]!=partation[i-1]){
      a=partation[i];
      len=X[a+1]-X[a];
    }
  }
  printf("%d",len);
}

Compiler output:
main.c: In function 'main':
main.c:9:29: error: stray '\343' in program
    9 |   int partation[100000]={0};<U+3000>//<U+3069><U+3053><U+3067><U+533A><U+5207><U+308B><U+304B>
      |                             ^~~~~~~~
main.c:30:24: error: expected ';' before 'for'
   30 |   len=len-(X[a+1]-X[a])
      |                        ^
      |                        ;
   31 |   for(int i=1;i<N;i++){
      |   ~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,K=0;
  cin>>N>>M;
  vector<int> x;
  vector<int> S;
  for(int i=0;i<M;i++){
    cin>>x.at(i);
  }
  sort(x.begin(),x.end());
  for(int i=0;i<M-1;i++){
    S.at(i)=x.at(i+1)-x.at(i);
    K+=S.at(i);
  }
  sort(S.begin(),S.end());
  for(int j=0;j<N;j++){
    K=K-S(M-1-j);
    if(K<=0){
      K=1;
      break;
    }
  }
  cout<<K<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:10: error: no match for call to '(std::vector<int>) (int)'
   18 |     K=K-S(M-1-j);
      |         ~^~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,p,K=0;
  cin>>N>>M;
  vector<int> x;
  vector<double> S;
  for(int i=0;i<M;i++){
    cin>>x.at(i);
  }
  sort(x.begin(),x.end());
  for(int i=0;i<M-1;i++){
    S.at(i)=x.at(i+1)-x.at(i);
    K+=S.at(i);
  }
  sort(S.begin(),S.end());
  for(int j=0;j<N;j++){
    p=M-1-j;
    K=K-S(p);
    if(K<=0){
      K=1;
      break;
    }
  }
  cout<<K<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:10: error: no match for call to '(std::vector<double>) (int&)'
   19 |     K=K-S(p);
      |         ~^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,p,K=0;
  cin>>N>>M;
  vector<int> x;
  vector<int> S;
  for(int i=0;i<M;i++){
    cin>>x.at(i);
  }
  sort(x.begin(),x.end());
  for(int i=0;i<M-1;i++){
    S.at(i)=x.at(i+1)-x.at(i);
    K+=S.at(i);
  }
  sort(S.begin(),S.end());
  for(int j=0;j<N;j++){
    p=M-1-j;
    K=K-S(p);
    if(K<=0){
      K=1;
      break;
    }
  }
  cout<<K<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:10: error: no match for call to '(std::vector<int>) (int&)'
   19 |     K=K-S(p);
      |         ~^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,p,K=0;
  cin>>N>>M;
  vector<int> x(M);
  vector<int> S(M-1);
  for(int i=0;i<M;i++){
    cin>>x.at(i);
  }
  sort(x.begin(),x.end());
  for(int i=0;i<M-1;i++){
    S.at(i)=x.at(i+1)-x.at(i);
    K+=S.at(i);
  }
  sort(S.begin(),S.end());
  for(int j=0;j<N;j++){
    p=M-1-j;
    K=K-S(M-1);
    if(K<=0){
      K=1;
      break;
    }
  }
  cout<<K<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:10: error: no match for call to '(std::vector<int>) (int)'
   19 |     K=K-S(M-1);
      |         ~^~~~~
Language: C++

#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
	long long int N,M,X[100000];
	long long int ans=0;
	long long int nokosi;
	priority_queue<long long int> x;
	priority_queue<long long int> y;
	cin>>N>>M;

	for(int i=0;i<M;i++){
		cin>>X[i];
		x.push(X[i]);
	}
	if(N>=M){
		cout<<ans<<endl;
		return 0;
	}
	while(x.size()>=2){
		nokosi=x.top();
		x.pop();
		y.push(nokosi-x.top());
	}
	for(int i=0;i<N-1;i++){
		y.pop();
	}

			while(!y.empty()){
			ans+=y.top();
			y.pop();
		
	}

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

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,K=0;
  cin>>N>>M;
  vector<int> x(M);
  vector<int> S(M-1);
  for(int i=0;i<M;i++){
    cin>>x.at(i);
  }
  sort(x.begin(),x.end());
  for(int i=0;i<M-1;i++){
    S.at(i)=x.at(i+1)-x.at(i);
    K+=S.at(i);
  }
  sort(S.begin(),S.end());
  for(int j=0;j<N;j++){
    \\K=K-S.at(M-1-j);
  }
  cout<<K<<endl;
}


Compiler output:
a.cc:18:5: error: stray '\' in program
   18 |     \\K=K-S.at(M-1-j);
      |     ^
a.cc:18:6: error: stray '\' in program
   18 |     \\K=K-S.at(M-1-j);
      |      ^
Language: C++

#include <iostream>
#include <bits/sydc++.h>
#include <algorithm>
using namespace std;

int main(){
  int N,M,sum,S;
  cin >> N >> M;
  vector<int> X(M),Y(M-1);
  for(int i=0; i<M; ++i) cin >> X.at(i);
  sort(X,X+M);
  for(int i=0; i<M-1;++i) Y[i]=X[i+1]-X[i];
  sort(Y,Y+M-1,greater<int>());
  sum=X[M-1]-X[0];
  for(int i=0; i<N; ++i) S += Y[i];
  cout << sum-S << endl;
}


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

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

int main(){
  int N,M,sum,S;
  cin >> N >> M;
  vector<int> X(M),Y[M-1];
  for(int i=0; i<M; ++i) cin >> X.at(i);
  sort(X,X+M);
  for(int i=0; i<M-1;++i) Y[i]=X[i+1]-X[i];
  sort(Y,Y+M-1,greater<int>());
  sum=X[M-1]-X[0];
  for(int i=0; i<N; ++i) S += Y[i];
  cout << sum-S << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:3: error: 'vector' was not declared in this scope
    8 |   vector<int> X(M),Y[M-1];
      |   ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
a.cc:8:10: error: expected primary-expression before 'int'
    8 |   vector<int> X(M),Y[M-1];
      |          ^~~
a.cc:9:33: error: 'X' was not declared in this scope
    9 |   for(int i=0; i<M; ++i) cin >> X.at(i);
      |                                 ^
a.cc:10:8: error: 'X' was not declared in this scope
   10 |   sort(X,X+M);
      |        ^
a.cc:11:27: error: 'Y' was not declared in this scope
   11 |   for(int i=0; i<M-1;++i) Y[i]=X[i+1]-X[i];
      |                           ^
a.cc:12:8: error: 'Y' was not declared in this scope
   12 |   sort(Y,Y+M-1,greater<int>());
      |        ^
Language: C

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

int main(){

  int i,j,k;
  int N,M;
  
  scanf("%d %d",&N,&M);
  int X[M],tmp,sum;
  
  for(i=0;i<M;i++)
    scanf("%d ",&X[i]);

  for (i=0; i<M; ++i) {
    for (j=i+1; j<M; ++j) {
      if (X[i] < X[j]) {
        tmp =  X[i];
        X[i] = X[j];
        X[j] = tmp;
      }
    }
  }
  	int check[N];
  int flg[N];
	sum = abs(X[0])+abs(X[M-1]);
  check[0] = x[M-1];
  for(i = 1;i<N;i++)
    check[i] = X[M-1] - (int)(sum/N-1)*i;
  
  for(i=1;i<N;i++){
    for(j=0;j < M;j++){
      if(X[j] >= check[i]){
        check[i] = X[j];
        flg[i]=j;
        break;
      }
    }
   int ans=0; 
    for(i=0;i<N;i++){
      ans += abs(check[i]-X[flg[i+1]]);
    }
    
    printf("%d\n",ans);
    
    return 0;
  }
      
        
  
  
  
  


Compiler output:
main.c: In function 'main':
main.c:26:15: error: implicit declaration of function 'abs' [-Wimplicit-function-declaration]
   26 |         sum = abs(X[0])+abs(X[M-1]);
      |               ^~~
main.c:3:1: note: include '<stdlib.h>' or provide a declaration of 'abs'
    2 | #include<math.h>
  +++ |+#include <stdlib.h>
    3 | 
main.c:27:14: error: 'x' undeclared (first use in this function)
   27 |   check[0] = x[M-1];
      |              ^
main.c:27:14: note: each undeclared identifier is reported only once for each function it appears in
main.c:47:3: error: expected declaration or statement at end of input
   47 |   }
      |   ^
Language: C++

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

int main(){
    int N, M, X[100001];
    bool flag = 1;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> X[i];
        for(int j = 0; flag; j++){
            flag = 0;
            for(int k = N - 1; k >= i + 1; k--){
                if(X[k] < X[k - 1]){
                    swap(X[k], X[k - 1]);
                    flag = 1;
                }
            }
        }
    }
    int ans = 0;
    if(M == 1) cout << ans << endl;
    else{
        int d[100001];
        for(int i = 0; i < M - 1; i++){
            d[i] = abs(X[i] - X[i + 1]);
        }
        for(int j = 0; flag; j++){
            flag = 0;
            for(int k = N - 1; k >= i + 1; k--){
                if(X[k] < X[k - 1]){
                    swap(X[k], X[k - 1]);
                    flag = 1;
                }
            }
        }
        for(int i = 0; i < M - N + 1; i++){
            ans += d[i];
        }
        cout << ans << endl;
    }
    return 0;
}

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

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


int main()
{
int N,M;
cin>>N;
cin>>M;
double array[10000];
double max=-10000;
double min=10000;

for(int i=0;i<M;i++){
  cin>>array[i];
}
std::sort(array, array + M);
double r[10000];
for(int i=0;i<M-1;i++){r[i]=array[i+1]-array[i];}
double a=0;
std::sort(r, r + M-1);
for(int i=0;i<M-N;i++)a=a+abs(r[i]);
a=std::ceil(a);
cout<<a<<endl;
return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:8: error: 'ceil' is not a member of 'std'
   26 | a=std::ceil(a);
      |        ^~~~
Language: C++

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

int main(void) {
  int N, M;
  cin >> N >> M;

  int X[M];
  for (int i = 0; i < M; i++) {
    cin >> X[i];
  }
  sort(X, X + M);

  int tmp[M - 1];
  int sum = 0;
  for (int i = 0; i < M - 1; i++) {
    tmp[i] = X[i+1] - X[i];
    sum += tmp[i];
  }


  sort(tmp, tmp + M - 1, greater<int>());

  int unused = 0;
  for (int i = 0; i < N - 1; i++) {
    unused += tmp[i];
  }

  if (N >= M) {
    cout << 0 << endl;
    return 0;
  }

  cout << sum - unused << endl;
}

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

#coding: utf-8
N, M = map(int, input().split())
points = list(map(int, input().split()))
points.sort()
koma = [points[i+1] - points[i] for i in range(M-1)]
for i in range(N-1):
  koma.remove(max(koma))
print(sum(koma))

Compiler output:
a.cc:1:2: error: invalid preprocessing directive #coding
    1 | #coding: utf-8
      |  ^~~~~~
a.cc:2:1: error: 'N' does not name a type
    2 | N, M = map(int, input().split())
      | ^
Language: C++

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

int bubbleSort(int A[], int N){
    bool flag = 1;
    for(int i = 0; flag; i++){
        flag = 0;
        for(int j = N - 1; j >= i + 1; j--){
            if(A[j] < A[j - 1]){
                swap(A[j], A[j - 1]);
                flag = 1;
            }
        }
    }
    return A[];
}

int main(){
    int N, M, X[100001];
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> X[i];
    }
    X[] = bubbleSort(X, M);
    int ans = 0;
    if(M == 1) cout << ans << endl;
    else{
        int d[100001];
        for(int i = 0; i < M - 1; i++){
            d[i] = abs(X[i] - X[i + 1]);
        }
        d[] = bubbleSort(d, M - 1);
        for(int i = 0; i < M - N + 1; i++){
            ans += d[i];
        }
        cout << ans << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int bubbleSort(int*, int)':
a.cc:15:14: error: expected primary-expression before ']' token
   15 |     return A[];
      |              ^
a.cc: In function 'int main()':
a.cc:24:7: error: expected primary-expression before ']' token
   24 |     X[] = bubbleSort(X, M);
      |       ^
a.cc:32:11: error: expected primary-expression before ']' token
   32 |         d[] = bubbleSort(d, M - 1);
      |           ^
Language: C++

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

int main() {
  // ここにプログラム
  long int n m;
  cin >> n >> m;
  if(n >= m) {
    cout << "0" << endl;
    return 0;
  }
  vector<long int> vec(m);
  for(long int i = 0; i < m; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  vector<long int> ans(m - 1);
  long int sum = 0;
  for(long int i = 0; i < m - 1; i++) {
    ans.at(i) = vec.at(i + 1) - vec.at(i);
    sum += ans.at(i);
  }
  sort(ans.begin(), ans.end());
  for(long int i = 0; i < n - 1; i++) {
    sum -= ans.at(m - 2 - i);
  }
  cout << sum << endl;
  
    
  
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:14: error: expected initializer before 'm'
    6 |   long int n m;
      |              ^
a.cc:7:10: error: 'n' was not declared in this scope; did you mean 'yn'?
    7 |   cin >> n >> m;
      |          ^
      |          yn
a.cc:7:15: error: 'm' was not declared in this scope; did you mean 'tm'?
    7 |   cin >> n >> m;
      |               ^
      |               tm
Language: C++

#include <iostream>
using namespace std;

int main(){
    int N,M;
    int X[110000];
    cin >> N >> M;
    for(int i=0;i<M;++i) cin >> X[i];

    if(N >= M){
        cout << "0" << endl;
        return 0;
    }

    sort(X,X+M);
    int diff[110000];
    for(int i=0;i<M-1;++i){
        diff[i] = X[i+1] - X[i];
    }

    sort(diff,diff+M-1);
    int sum = 0;
    for(int i=0;i<M-N;++i){
        sum += diff[i];
    }

    cout << sum << 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(X,X+M);
      |     ^~~~
      |     short
Language: C++

#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

const int MAX_N = 1e+5 + 1;

ll X[MAX_N];

int main() {
    int N, M;
    ll sum = 0;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> X[i];
    }
    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }
    sort(X, X + M);
    vector<ll> a;
    for (int i = 0; i < M - 1; i++) {
        a.push_back(X[i + 1] - X[i]);
        sum += X[i + 1] - X[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for (int i = 0; i < N - 1; i++) {
        sum -= a[i];
    }
    cout << sum << endl;
    return 0;
}

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

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

using namespace std;

int main(){
    int n, m; cin >> n >> m;
    if(m==1){
        cout << 0 << endl;
        return 0;
    }
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    vector<int> xs(m);
    for(int i=0; i<m; ++i){
        cin >> xs[i];
    }
    sort(xs.begin(), xs.end());
    vector<int> diffs(m-1);
    for(int i=0; i<m-1; ++i){
        diffs[i]=xs[i+1]-xs[i];
    }
    sort(diffs.begin(), diffs.end());
    int sum=accumulate(diffs.begin(), diffs.end()-(n-1), 0);
    cout << sum << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:27:13: error: 'accumulate' was not declared in this scope
   27 |     int sum=accumulate(diffs.begin(), diffs.end()-(n-1), 0);
      |             ^~~~~~~~~~
Language: Java

import static org.junit.jupiter.api.Assumptions.assumingThat;

import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		if (N >= M) {
			System.out.println(0);
			return;
		}
		
		int[] map = new int[M];
		for (int i = 0; i < M; i++) {
			map[i] = sc.nextInt();
		}
		
		Arrays.sort(map);
		
		int sum = 0;
		LinkedList<X> list = new LinkedList<X>();
		for (int i = 0; i < M-1; i++) {
			X x = new X(i, map[i+1]-map[i]);
			list.add(x);
			sum += x.cost;
		}
		
		Collections.sort(list);
		for (int i = 0; i < N-1; i++) {
			X x = list.removeFirst();
			sum -= x.cost;
		}
		
		System.out.println(sum);
		
		
	}
	
	static class X implements Comparable<X>{
		int index;
		int cost;
		
		public X(int index, int cost) {
			this.index = index;
			this.cost = cost;
		}

		@Override
		public int compareTo(X o) {
			return o.cost - this.cost;
		}
	}
}

Compiler output:
Main.java:1: error: package org.junit.jupiter.api does not exist
import static org.junit.jupiter.api.Assumptions.assumingThat;
                                   ^
Main.java:1: error: static import only from classes and interfaces
import static org.junit.jupiter.api.Assumptions.assumingThat;
^
2 errors
Language: C++

#include <iostream>
#include <string.h>
#include <vector>
#include <map>
using namespace std;
#define ll long long

int main () {
  ll n, m;
  cin >> n >> m;
  ll x[m];
  ll sum[m - 1];
  for (ll i = 0; i < m - 1; i++) {
    sum[i] = 0;  
  }
  for (ll i = 0; i < m; i++) {
    cin >> x[i];
  }
  if (n >= m) {
    cout << 0 << endl;
    return 0;  
  }
  sort(x, x + m);
  for (ll i = 1; i < m; i++) {
    sum[i-1] = x[i] - x[i - 1];  
  }
  sort(sum, sum + m - 1);
  ll ans = 0;
  for (ll i = 0; i < m - n; i++) {
    ans += sum[i];
  }
  cout << ans << endl;

    
}

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

#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
typedef long long LL;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> x;
    for (int i=0; i<m; i++) {
        int tmp;
        cin >> tmp;
        x.push_back(tmp);
    }
    sort(x.being(), x.end());    

    vector<int> diff;
    for (int i=0; i<m-1; i++) {
        diff.push_back(x[i+1] - x[i]);
    }
    sort(diff.begin(), diff.end());

    int ans = 0;   
    for (int i=0; i<m-n-1; i++) {
        ans += diff[i];
    }
    if (n >= m) cout << 0 << endl;
    else cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:12: error: 'class std::vector<int>' has no member named 'being'
   23 |     sort(x.being(), x.end());
      |            ^~~~~
Language: C++

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> X(M),Y(M-1);
  for(int i=0;i<M;i++)cin >> X[i];
  sort(X.begin(),X.end());
  for(int i=0;i<M-1;i++){Y[i]=X[i+1]-X[i];}
  //vector<pair<int,int>> a(N);
  //for(int i=0;i<M-1;i++){a[i]=make_pair(Y[i],i);}
  sort(Y.begin(),Y.end());
  int ans=X[M-1]-X[0];
  if(N==1){cout << ans << endl;}
  else if(N>=M){cout << 0 << endl;}
  else{
    for(int i=M-2;i>=M-N && i>=0;i--){
      ans-=Y[i];
    }
    cout << ans << endl;
  }

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

import Foundation

class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
    
    static func readString() -> String {
        return readLine()!
    }
}

class Printer {
    static func printIntArray(_ arr: [Int]) {
        print(arr.map { String($0) }.joined(separator: " "))
    }
}
class Solution {
    func maxXXOR(_ arr: [Int], _ k: Int) -> Int {
        guard k > 0 else {
            return arr.reduce(0) { $0 + $1 }
        }
        let n = Int(log(Double(k))/log(Double(2))) + 1
        var res = 0
        for i in stride(from: 0, to: n, by: 1) {
            let c = 1<<i;
            var zcnt = 0, ocnt = 0
            for num in arr {
                if c&num != 0 {
                    ocnt += 1
                } else {
                    zcnt += 1
                }
            }
            if zcnt > ocnt { //we will set
                
            } else {
                
            }
            res += (max(zcnt, ocnt) * c)
        }
        return res
    }
}


let nk = Scanner.readIntArr()
let arr = Scanner.readIntArr()
print(Solution().maxXXOR(arr,nk[1]))


Compiler output:
a.cc:14:18: error: too many decimal points in number
   14 |         for _ in 0..<n {
      |                  ^~~
a.cc:1:1: error: 'import' does not name a type
    1 | import Foundation
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:34:12: error: 'func' does not name a type
   34 |     static func printIntArray(_ arr: [Int]) {
      |            ^~~~
a.cc:37:2: error: expected ';' after class definition
   37 | }
      |  ^
      |  ;
a.cc:39:5: error: 'func' does not name a type
   39 |     func maxXXOR(_ arr: [Int], _ k: Int) -> Int {
      |     ^~~~
a.cc:67:5: error: expected initializer before 'nk'
   67 | let nk = Scanner.readIntArr()
      |     ^~
Language: C++

//桁dp
https://drken1215.hatenablog.com/entry/2019/02/03/224200
これを読んだ

Compiler output:
a.cc:2:6: error: found ':' in nested-name-specifier, expected '::'
    2 | https://drken1215.hatenablog.com/entry/2019/02/03/224200
      |      ^
      |      ::
a.cc:2:1: error: 'https' does not name a type
    2 | https://drken1215.hatenablog.com/entry/2019/02/03/224200
      | ^~~~~
Language: C++

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

int main(){
	ll n,k;
	cin >> n >> k;
	vector<ll> a(n);
	vector<ll> nums(40);

	for(int i=0; i<n; i++){
		cin >> a[i];
		for(int j=0; j<40; j++) if(a[i] & (1ll << j)) nums[j]++;	
	}

	ll x = 0;
	for(int i=39; i>=0; i--){
		if(nums[i]*2 <= n) x += (1ll << i);
		if(x > k) x -= (1ll << i);
	}

	ll sum = 0;
	for(ll A : a) sum += A^ans;
	cout << sum << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:23:32: error: 'ans' was not declared in this scope; did you mean 'abs'?
   23 |         for(ll A : a) sum += A^ans;
      |                                ^~~
      |                                abs
Language: C++

#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		sum += v[i];
	}
	int val = 0;
	for (int bit = 40; bit >= 0; --bit) {
		int set = 0;
		for (int i = 0; i < n; ++i) {
			if ((v[i] >> bit) & 1) {
				set++;
			}
		}
		if ((n - set) > set && ((1LL << bit) + val) <= k) {
			val = (val | (1LL << bit));
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		ans += (val ^ v[i]);
	}
	cout << ans;
}


Compiler output:
a.cc:4:1: error: 'stack' does not name a type; did you mean 'stack_t'?
    4 | stack<int> st;
      | ^~~~~
      | stack_t
a.cc:5:1: error: 'queue' does not name a type
    5 | queue<int> qu;
      | ^~~~~
a.cc:6:1: error: 'queue' does not name a type
    6 | queue<pair<int,int> > qu2;
      | ^~~~~
a.cc:7:1: error: 'priority_queue' does not name a type
    7 | priority_queue<int> pq;
      | ^~~~~~~~~~~~~~
a.cc:13:9: error: 'set' does not name a type; did you mean 'se'?
   13 | typedef set<int> set_t;
      |         ^~~
      |         se
a.cc:14:9: error: 'set' does not name a type; did you mean 'se'?
   14 | typedef set<string> set_g;
      |         ^~~
      |         se
a.cc:15:9: error: 'complex' does not name a type
   15 | typedef complex<double> xy_t;
      |         ^~~~~~~
a.cc:24:1: error: 'deque' does not name a type
   24 | deque<int> deq;
      | ^~~~~
a.cc:29:9: error: 'pair' does not name a type
   29 | typedef pair<int, int> P;
      |         ^~~~
a.cc:30:9: error: 'vector' does not name a type
   30 | typedef vector<ll> vec;
      |         ^~~~~~
a.cc:31:9: error: 'vector' does not name a type
   31 | typedef vector<vec> mat;
      |         ^~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,K;
    cin >>N>>K;
    vector<ll> A(N);
    ll mx=0;
    vector<ll> BT(50);
    rep(i,N){
        ll a;
        cin>>a;
        A[i] = a;
        rep(j,50){
            if(((ll(1)<<(j))&a) != 0){
                //cout<<j<<endl;
                BT[j]++;
            }
        }

    }
    /*rep(i,50){
        cout<<BT[i]<<endl;
    }*/
    ll X=0;
   
    vector<bool> BK;
    ll B=0;
    ll flag = 0;
    rep(i,50){
        if((ll(1)<<(49-i)) & K){
            flag = 1;
        }
        if(flag == 1){
            if((ll(1)<<(49-i)) & K){
                BK.pb(1);
            }else{
                BK.pb(0);
            }
            
        }else{
            //cout << bitset<50>(B)<<endl;
            B += (ll(1)<<(49-i));
        }
    }
    
    ll M = BK.size();
    //cout<<M<<endl;
    vector<vector<ll>> dp(M+1,vector<ll>(2));
    for(i=M-1;i<=0;i--){
        ll a,b,c,d;
        a = dp[i][0]+BT[M-1-i]*(ll(1)<<(M-1-i));
        b = dp[i][0]+(N-BT[M-1-i])*(ll(1)<<(M-1-i));
        c = dp[i][1]+BT[M-1-i]*(ll(1)<<(M-1-i));
        d = dp[i][1]+(N-BT[M-1-i])*(ll(1)<<(M-1-i));
        if(BK[i]==1){
            dp[i+1][0] = max({a,b,c});
            dp[i+1][1] = d;
        }else{
            dp[i+1][0] = max({a,b});
            dp[i+1][1] = c;
        }
        
    }
    
    ll ans = max(dp[M][0],dp[M][1]);
    //cout<<ans<<endl;
    //cout << bitset<50>(B)<<" "<<bitset<50>(A[0]);
    rep3(i,M,50){
        ans += BT[i]*(ll(1)<<(i));
        //cout<<(B&A[i])<<endl;
    }

    cout << ans << endl;


    return 0;
    

}

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

#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rreq(i,n) for(ll i = n;i >= 1;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
const ll INF = 1e18;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MOD = 1e9+7;
int main(void) {
    ll n,k; cin >> n>>k; vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll val = 0;
    rep(i, 41) {
        int set = 0;
        rep(j, n) {
            if ((a[j]>> i)&1)set++;
        }if (n - set > set && val + (1LL << i) <= k)val += (1LL << i);
    }ll ans = 0;
    rep(i, n) {
        ans += (a[i] ^ val);
    }cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:13: error: 'cin' was not declared in this scope
   25 |     ll n,k; cin >> n>>k; vector<ll> a(n);
      |             ^~~
a.cc:10:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    9 | #include<bitset>
  +++ |+#include <iostream>
   10 | using namespace std;
a.cc:36:6: error: 'cout' was not declared in this scope
   36 |     }cout << ans << endl;
      |      ^~~~
a.cc:36:6: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
const ll MOD=1e9+7;

int main(){
    ll N,K;cin>>N>>K;K++;
    vector<ll> A(N);
    for(int i=0;i<N;++i) cin>>A[i];
    ll ans=0;
    for(int d=50;d>=0;--d){
        if(!(K&(1LL<<d))) continue;
        ll tmp=0;
        for(int e=50;e>=0;--e){
            ll mask=1LL<<e;
            int num=0;
            for(int i=0;i<N;++i){
                if(A[i]&mask) ++num;
            }
            if(e>d){
                if(K&mask) tmp+=mask*(N-num);
                else tmp+=mask*num;
            }else if(e==d){
                tmp+=mask*num;
            }else{
                tmp+=mask*max(num,n-num);
            }
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:35: error: 'n' was not declared in this scope
   46 |                 tmp+=mask*max(num,n-num);
      |                                   ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

#define BITS 60

int main(){
    ll N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vi cnt(BITS);
    rep(i,N){
        rep(j,BITS){
            if(A[i] & (1LL << j)){
                cnt[j]++;
            }
        }
    }

    ll dp[BITS+1][2];
    rep(i,BITS+1) rep(j,2) dp[i][j]=0;
    for(int i=0;i<BITS;i++){
        ll bit = BITS - 1 - i;
        for(int j=0;j<2;j++){
            int x = (K & (1LL << bit)) > 0;
            ll y = cnt[bit] <= N/2;
            //printf("bit = %d, flag = %d, lim = %d, try = %d\n",i,j,x,y);
            if(y <= x){
                dp[i+1][j || (y < x)] = dp[i][j] | (y << bit);
            }else{
                dp[i+1][j || (z < x)] = dp[i][j];
            }
        }
    }
    ll X = max(dp[BITS][0], dp[BITS][1]);
    /* debug(X); */
    /* debug(bitset<BITS>(X)); */

    ll ans = 0;
    rep(i,N){
        ans += X ^ A[i];
    }
    cout << ans << endl;


    /* for(int i=0;i<=BITS;i++){ */
    /*     cout << i << " " << bitset<BITS>(dp[i][0]) << " " << bitset<BITS>(dp[i][1]) << endl; */
    /* } */
}


Compiler output:
a.cc: In function 'int main()':
a.cc:65:31: error: 'z' was not declared in this scope
   65 |                 dp[i+1][j || (z < x)] = dp[i][j];
      |                               ^
Language: C

#include<stdio.h>
#define max(a, b) ((a)>(b)?(a):(b))
int N;
long long K, A[100100], b[50], ans = 0;
int main(){
	scanf("%d%lld", &N, &K);
	for(int i=0; i<N; i++){
		scanf("%lld", A+i);
		int j=0;
		ans += A[i];
		long long tmp = A[i];
		while(tmp){
			b[j++] += (tmp&1);
			tmp >>= 1;
		}
	}
	for(int i=0; (K+1) >= (1ll<<i); i++){
		long long tmp = 0;
		for(int j=0; (K+1) >= (1ll<<j); j++){
			if(j < i){
				if(b[j] < (N-b[j])) tmp += (1ll<<j) * (N-b[j]);
				else tmp += (1ll<<j) * b[j];
			}else if(i == j){
				tmp += (1ll<<j) * b[j];
			}else {
				if((K>>j)&1){
					tmp += (1ll<<j) * (N-b[j]);
				}else {
					tmp += (1ll<<j) * b[j];
				}
			}
		}
		ans = max(ans, tmp);
	}
	printf("%lld\n", ans);
	return 0;


Compiler output:
main.c: In function 'main':
main.c:36:9: error: expected declaration or statement at end of input
   36 |         return 0;
      |         ^~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

vector<ll> num;

struct Nbase {
    int n;
    int sz = 1;
    long long max = 1e18;

    Nbase(int k = 2){
        n = k;
        while(max != 0){
            max /= n;
            sz++;
        }
        num.resize(sz);
    };

    //繰り返し二乗法
    ll EX(ll x,ll n){
        if(n == 0) return 1;
        else if(n%2 == 1) return EX(x,n-1)*x;
        else return EX(x*x,n/2);
    }

    vector<int> to_n(int num){
        vector<int> ret(sz);
        for(int i = sz-1; i >= 0; i--){
            long long subtraction = EX(n,i);
            if(subtraction <= num){
                for(int j = 1; j <= n; j++){
                    if(num < j*subtraction){
                        ret[i] = j-1;
                        num -= ret[i]*subtraction;
                    } 
                }
            } else ret[i] = 0;
        }
        return ret;
    }

    long long re_n(vector<int>& vec){
        long long ret = 0;
        vec.resize(sz);
        for(int i = 0; i < sz; i++){
            ret += vec[i]*EX(n,i);
        }
        return ret;
    }

    void supress(const vector<int>& lim,vector<int>& at){
        bool upper = true;
        for(int i = sz; i >= 0; i--){
            /*if(upper && lim[i] > 0) upper = false;
            if(lim[i] > at[i]) break;
            else if(upper || lim[i] < at[i]) at[i] = lim[i];*/
            if(upper && lim[i] == 1) upper = false;
            if(lim[i] == 1 && at[i] == 0) break;
            else if(lim[i] == 0 || upper) x[i] = 0;
        }
    }
};

int main(){
    Nbase base = 2;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        vector<int> sam = base.to_n(a[i]);
        for(int j = 0; j < base.sz; j++){
            if(sam[j] == 1) num[j]++;
        }
    }
    vector<int> x(base.sz);
    for(int i = 0; i < base.sz; i++){
        if(num[i] <= n/2) x[i] = 1;
        else x[i] = 0;
    }
    vector<int> kd = base.to_n(k);
    base.supress(kd,x);
    int X = base.re_n(x);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += X^a[i];
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In member function 'void Nbase::supress(const std::vector<int>&, std::vector<int>&)':
a.cc:62:43: error: 'x' was not declared in this scope
   62 |             else if(lim[i] == 0 || upper) x[i] = 0;
      |                                           ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

vector<ll> num;

struct Nbase {
    int n;
    int sz = 1;
    long long max = 1e18;

    Nbase(int k = 2){
        n = k;
        while(max != 0){
            max /= n;
            sz++;
        }
        num.resize(sz);
    };

    //繰り返し二乗法
    ll EX(ll x,ll n){
        if(n == 0) return 1;
        else if(n%2 == 1) return EX(x,n-1)*x;
        else return EX(x*x,n/2);
    }

    vector<int> to_n(int num){
        vector<int> ret(sz);
        for(int i = sz-1; i >= 0; i--){
            long long subtraction = EX(n,i);
            if(subtraction <= num){
                for(int j = 1; j <= n; j++){
                    if(num < j*subtraction){
                        ret[i] = j-1;
                        num -= ret[i]*subtraction;
                    } 
                }
            } else ret[i] = 0;
        }
        return ret;
    }

    long long re_n(vector<int>& vec){
        long long ret = 0;
        vec.resize(sz);
        for(int i = 0; i < sz; i++){
            ret += vec[i]*EX(n,i);
        }
        return ret;
    }

    void supress(const vector<int>& lim,vector<int>& at){
        bool upper = true;
        for(int i = sz; i >= 0; i--){
            if(upper && lim[i] > 0) upper = false;
            if(lim[i] > at[i]) break;
            else if(upper || lim[i] < at[i]) at[i] = lim[i];
        }
    }
};

int main(){
    Nbase base = 2;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        vector<int> sam = base.to_n(a[i]);
        for(int j = 0; j < base.sz; j++){
            if(sam[j] == 1) num[j]++;
        }
    }
    /*vector<int> x(base.sz);
    for(int i = 0; i < n; i++){
        if(num[i] <= n/2) x[i] = 1;
        else x[i] = 0;
    }*/
    vector<int> kd = base.to_n(k);
    base.supress(kd,x);
    int X = base.re_n(x);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += X^a[i];
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:82:21: error: 'x' was not declared in this scope
   82 |     base.supress(kd,x);
      |                     ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

vector<ll> num;

struct Nbase {
    int n;
    int sz = 1;
    long long max = 1e18;

    Nbase(int k = 2){
        n = k;
        while(max != 0){
            max /= n;
            sz++;
        }
        num.resize(sz);
    };

    //繰り返し二乗法
    ll EX(ll x,ll n){
        if(n == 0) return 1;
        else if(n%2 == 1) return EX(x,n-1)*x;
        else return EX(x*x,n/2);
    }

    vector<int> to_n(int num){
        vector<int> ret(sz);
        for(int i = sz-1; i >= 0; i--){
            long long subtraction = EX(n,i);
            if(subtraction <= num){
                for(int j = 1; j <= n; j++){
                    if(num < j*subtraction){
                        ret[i] = j-1;
                        num -= ret[i]*subtraction;
                    } 
                }
            } else ret[i] = 0;
        }
        return ret;
    }

    long long re_n(vector<int>& vec){
        long long ret = 0;
        vec.resize(sz);
        for(int i = 0; i < sz; i++){
            ret += vec[i]*EX(n,i);
        }
        return ret;
    }

    void supress(const vector<int>& lim,vector<int>& at){
        bool upper = true;
        for(int i = sz; i >= 0; i--){
            if(upper && lim[i] > 0) upper = false;
            if(lim[i] > at[i]) break;
            else if(upper || lim[i] < at[i]) at[i] = lim[i];
        }
    }
};

int main(){
    Nbase base = 2;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    /*for(ll i = 0; i < n; i++){
        cin >> a[i];
        vector<int> sam = base.to_n(a[i]);
        for(int j = 0; j < base.sz; j++){
            if(sam[j] == 1) num[j]++;
        }
    }
    vector<int> x(base.sz);
    for(int i = 0; i < n; i++){
        if(num[i] <= n/2) x[i] = 1;
        else x[i] = 0;
    }*/
    vector<int> kd = base.to_n(k);
    //base.supress(kd,x);
    int X = base.re_n(x);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += X^a[i];
    }
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:83:23: error: 'x' was not declared in this scope
   83 |     int X = base.re_n(x);
      |                       ^