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

import java.util.*;

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


Compiler output:
Main.java:17: error: variable i is already defined in method main(String[])
      for(int i = 0; i < 40; i++) {
              ^
1 error
Language: C++

#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>
#include <stack>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  ll N, K; cin >> N >> K;
  ll A[N]; rep(i,N) cin >> A[i];
  ll t_bit[50] = {}; rep(i,N) rep(j,50) t_bit[j] += ((A[i]>>j)&1);
  ll bit[50]; rep(i,50) bit[i] = (t_bit[i]>N/2) ? 0 : 1;


  ll X = 0, result = 0;
  bool bt = false, kt = false;
  for (int i=50; i>=0; i--) {
    if (!bit[i]) bt = true;
    if (!bt) X += ((K>>i)&1) * pow(2,i);
    else {
      if (((K>>i)&1)&&bit[i]) kt = true;
      if (kt) X += bit[i] * pow(2,i);
    }
  }
  rep(i,N) result += X^A[i];
  // cout << X << " " << result << endl;

  X = 0;
  bt = false, kt = false;
  for (int i=50; i>=0; i--) {
    if (!bit[i]) bt = true;
    if (!bt) X += ((K>>i)&1) * pow(2,i);
    else {
      if (((K>>i+1)&1)&&bit[i]) kt = true;
      if (kt) X += bit[i] * pow(2,i);
    }
  }
  // ll tmp=0; rep(i,N) tmp += X^A[i]; result = max(result, tmp);
  cout << X << " " << result << endl;

  result = max(result, tmp);
  // for (int i=5; i>=0; i--) cout << bit[i] << endl;
  cout << result << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:24: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   51 |   result = max(result, tmp);
      |                        ^~~
      |                        tm
Language: C++

#include<bits/stdc++.h>
#define rep(i,k,n) for(int i =k;i<n;i++)
typedef long long ll;
using namespace std;
int main()
{
   int N,K;
  cin >> N >> K;
  vector<ll>A;
  vector<vector<ll>>dp(46,vector<ll>(2,-1));
  rep(i,0,N)cin >> A[i];
  
  dp[45][0]=0;
  for(int i=44;i>=0;--i;)
  {
    int c=0;
    rep(j,0,N)
    {
      if(A[j]&(1<<i))
      {
        ++c;
      }
    }
    
    ll d0 = (1<<i)*c;
    ll d1 = (1<<i)*(N-c);
    
    if(K&(1<<i))
    {
      dp[i][0]=max(dp[i][0],dp[i+1][0]+d1);
      dp[i][1]=max(dp[i][1],dp[i+1][0]+d0);
    }
    else
    {
      dp[i][0]=max(dp[i][0],dp[i+1][0]+d0);
    }
    
    if(dp[i+1][1]!=-1)
    {
      dp[i][1]=max(dp[i][1],dp[i+1][1]+max(d0,d1));
    }
  }
  cout << max(dp[0][0],dp[0][1]) << endl;
  return 0;
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:24: error: expected ')' before ';' token
   14 |   for(int i=44;i>=0;--i;)
      |      ~                 ^
      |                        )
a.cc:14:25: error: expected primary-expression before ')' token
   14 |   for(int i=44;i>=0;--i;)
      |                         ^
Language: C++

#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define TF(flag) (flag)?1:0
#define fi first
#define se second
#define debug if(DEBUG)
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

bool DEBUG=true;

pair<bitset<42>,ull> rec(int p);

ull N,K;
vec<ull> A;
bitset<42> k;
vec<int> cnt(42,0);
int ks=0,as=0;

int main(void){
  cin>>N>>K;
  A.resize(N); cin>>A;
  
  ull tk=K;
  while(tk>0) ++ks,tk/=2;
  rep(i,N){
    int tas=0; ull ta=A[i];
    while(ta>0) ++tas,ta/=2;
    as=max(as,tas);
    bitset<42> a(A[i]);
    rep(j,42){
      cnt[j]+=TF(a[j]);
    }
  }
  
  k=K;
  
  debug{
    cerr<<k<<endl;
  }
  
  bitset<42> X(0); ull ans;
  int p=max(ts,as)-1;
  while(p>=0&&!k[p]){
    ans+=((ull)1<<p)*cnt[p];
    --p;
  }
  if(p>=0){
    ull tans;
    tie(X,tans)=rec(p);
    ans+=tans;
  }
  
  cout<<ans<<endl;
  
  debug{
    cerr<<X<<endl;
  }
}

pair<bitset<42>,ull> rec(int p){
  bitset<42> x0(0),x1(0);
  ull f0=0,f1=0;
  
  using P=pair<bitset<42>,ull>;
  
  // Case : 0
  f0+=((ull)1<<p)*cnt[p];
  for(int i=p-1; i>=0; --i){
    if(cnt[i]>N-cnt[i]){
      // More 1 -> Select 0
      f0+=((ull)1<<i)*cnt[i];
    }
    else{
      // More 0 -> Select 1
      x0.set(i);
      f0+=((ull)1<<i)*(N-cnt[i]);
    }
  }
  
  // Case : 1
  f1+=((ull)1<<p)*(N-cnt[p]);
  x1.set(p);
  --p;
  while(p>=0&&!k[p]){
    f1+=((ull)1<<p)*(N-cnt[p]);
    --p;
  }
  if(p<0){
    if(f0<f1) return P(x1,f1);
    else return P(x0,f0);
  }
  else{
    bitset<42> tx; ull tf;
    tie(tx,tf)=rec(p);
    x1|=tx,f1+=tf;
    if(f0<f1) return P(x1,f1);
    else return P(x0,f0);
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:80:13: error: 'ts' was not declared in this scope; did you mean 'tk'?
   80 |   int p=max(ts,as)-1;
      |             ^~
      |             tk
Language: Java

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskD   {
int[][] bA;
int N;
long memo = new long[50];

public void solve(int testNumber, Scanner in, PrintWriter out) {
        N = in.nextInt();
        long K = in.nextLong();
        long A[] = new long[N];
        for (int i=0; i<=N-1; i++) {
            A[i] = in.nextLong();
        }

        bA = new int[40][2];
        for (int i=0; i<=N-1; i++) {
            long ac = A[i];
            for (int j=0; ac > 0; j++) {
                bA[j][0] += ac % 2;
                ac /= 2;
            }
        }

        long kc = K;
        int keta = 0;
        for (int i=0; kc > 0; i++){
            bA[i][1] = (int)(kc%2);
            kc /= 2;
            keta++;
        }


        long ans = dfs(keta, false);


        for (int i=keta; i<=39; i++) {
            ans += pow(2, i) * bA[i][0];
        }
        out.println(ans);
    }

long dfs(int n, boolean free) {
        long ret = 0;
        if (n < 0) return -2;
        if (n == 0) return 0; 
        long pow2 = pow(2, n-1);

        boolean free2 = free;
        if(bA[n-1][1] == 1){
            free2 = true;
        }

        if(free){
            ret = dfs(n-1, free) + Math.max(bA[n-1][0], (N-bA[n-1][0])) * pow2;
        } else if(bA[n-1][1] == 0){
            ret = dfs(n-1, free2) + bA[n-1][0] * pow2;
        } else {
            ret = Math.max(dfs(n-1, free2) + bA[n-1][0] * pow2,
                    dfs(n-1, free) + (N-bA[n-1][0]) * pow2);
        }
        return memo[n] = ret;
    }

public   static long pow(long x, long n) {
        long sum = 1;
        while (n > 0) {
            if ((n & 1) == 1) {  
                sum *= x;        
            }
            x *= x;              
            n >>= 1;
        }
        return sum;
    }

}
}



Compiler output:
Main.java:23: error: incompatible types: long[] cannot be converted to long
long memo = new long[50];
            ^
Main.java:79: error: array required, but long found
        return memo[n] = ret;
                   ^
2 errors
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	ll n, k, a[100000], cnt[41];
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<n; i++){
		for(int j=40; 0<=j; j--){
			if(((1LL<<j) & a[i])==0){
				cnt[j]++;
			}
		}
	}
	ll total=0;
	for(int i=40; 0<=i; i--){
		if((total | (1LL << i)) <=k && n-cnt[i] <= cnt[i]){
			total |= 1LL << i;
		}
	}
	ll ans=0;
	for(int i=0; i<n; i++){
		ans+=total^a[i];
	}
	cout << ans << endl;

	return 0;
}


Compiler output:
a.cc:8:9: error: 'set' does not name a type
    8 | typedef set<int> S;
      |         ^~~
Language: C++

#include <iostream>
#include <vector>
#include <math.h>
#include <utility>
using namespace std;
#define ll long long


int N;
ll K;
vector<ll> A;


void solve(){
	ll ans = 0;
	for(int i=0;i<N;i++) ans += A[i];


	int binA[40];
	for(int i=0;i<40;i++){
		if(K % 2 == 1){
			binA[i] = 1;
		}else{
			binA[i] = 0;
		}
		K /= 2;
	}

	int count[40];
	for(int i=0; i<40; i++){
		count[i] = 0;
		for(int j=0; j<N;j++){
			if(A[j] % 2 == 1) count[i]++;
			A[j] /= 2;
		}
	}

	// for(auto u:count) cout << u << endl;

	ll sub_ans;
	for(int i=39;-1<=i;i--){
		if(binA[i] == 0) continue;
		sub_ans = 0;
		for(int j=0;j<=39;j++){
			if(j<i){
				sub_ans += pow(2,j) * max(count[j], N - count[j]);
			}else if(j==i){
				sub_ans += pow(2,i) * count[i];
			}else{
				if(binA[j] == 1){
					sub_ans += pow(2,j) * (N - count[j]);
				}else{
					sub_ans += pow(2,j) * count[j];
				}
			}
		}
		// cout << sub_ans << endl;
		ans = max(ans, sub_ans);
	}
	sub_ans = 0;
	for(int i=0;i<=39;i++){
		if(binA[i] == 1){
			sub_ans += pow(2,j) * (N - count[i]);
		}else{
			sub_ans += pow(2,j) * count[i];
		}
	}
	ans = max(ans, sub_ans);
	
	cout << ans << endl;
}

int main(){
	cin >> N >> K;
	A.resize(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
	}

	solve();
	return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:63:42: error: 'j' was not declared in this scope
   63 |                         sub_ans += pow(2,j) * (N - count[i]);
      |                                          ^
a.cc:65:42: error: 'j' was not declared in this scope
   65 |                         sub_ans += pow(2,j) * count[i];
      |                                          ^
Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int cnt[50];//各桁、つまり2^iの桁の1の数
long long diff[50];//xの各ビットに1を立たせた時のfの増減

long long dfs(int depth, long long k, long long now_x, long long now_f){
  int undecided = 50 - depth;
  long long res=now_f;
  if((k>>(49-depth)) & 1){
    REP(i,50-depth){
      if(i==49-depth){
        res += 
      }
    }
  }
}
      
int main(){
  
  int n;
  cin>>n;
  long long k;
  cin>>k;
  long long a[n];
  REP(i,n){
    cin>>a[i];
  }
  int temp;
  REP(j,50){
    temp = 0;
    REP(i,n){
      temp += (a[i]>>j)%2;
    }
    cnt[j] = temp;
  }
  REP(j,50){
    temp = n- 2*cnt[j];
    diff[j] = (long long)temp<<j;
  }
  
  long long base_sum=0;//xが0の時のfの値
  REP(i,n){
    base_sum += a[i];
  }
  
  long long greedy[50];//xの上限を気にしない時にiビットまで決めた時のfの最大値を持つ配列
  REP(j,50){
    if(diff[j]<=0){
      if(j==0){
        greedy[j] = base_sum;
      }else{
        greedy[j] = greedy[j-1];
      }
    }else{
      if(j==0){
        greedy[j] = base_sum + diff[j];
      }else{
        greedy[j] = greedy[j-1]+diff[j];
      }
    }
  }
  
  
  
  return 0;
}


Compiler output:
a.cc: In function 'long long int dfs(int, long long int, long long int, long long int)':
a.cc:99:7: error: expected primary-expression before '}' token
   99 |       }
      |       ^
a.cc:102:1: warning: no return statement in function returning non-void [-Wreturn-type]
  102 | }
      | ^
Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int n;
  cin>>n;
  long long k;
  cin>>k;
  long long a[n];
  REP(i,n){
    cin>>a[i];
  }
  int cnt[50];//各桁の1の数
  int temp;
  REP(k,50){
    temp = 0;
    REP(i,n){
      temp += (a[i]>>k)/2;
    }
    cnt[k] = temp;
  }
  int msb=0;
  while()
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:109:9: error: expected primary-expression before ')' token
  109 |   while()
      |         ^
Language: C++

typedef long long ll;
using namespace std;

int main(){ 
   ll N,K;  cin >> N >> K; vector<ll> A(N);
   if( N * K > 1e8 ){ return 0;}
  ll ans = 0;
  for(ll X = 0; X < K; X++){
  ll res = 0;
    for(ll i = 0; i < N; i++){
      // Xと A[i]とのXORをとっていく
      res += X ^ A[i];}
   ans = max( ans, res);
  }
  
  cout << ans <<  endl; return 0;}
    

Compiler output:
a.cc: In function 'int main()':
a.cc:5:13: error: 'cin' was not declared in this scope
    5 |    ll N,K;  cin >> N >> K; vector<ll> A(N);
      |             ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | typedef long long ll;
a.cc:5:28: error: 'vector' was not declared in this scope
    5 |    ll N,K;  cin >> N >> K; vector<ll> A(N);
      |                            ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | typedef long long ll;
a.cc:5:37: error: expected primary-expression before '>' token
    5 |    ll N,K;  cin >> N >> K; vector<ll> A(N);
      |                                     ^
a.cc:5:39: error: 'A' was not declared in this scope
    5 |    ll N,K;  cin >> N >> K; vector<ll> A(N);
      |                                       ^
a.cc:13:10: error: 'max' was not declared in this scope
   13 |    ans = max( ans, res);
      |          ^~~
a.cc:16:3: error: 'cout' was not declared in this scope
   16 |   cout << ans <<  endl; return 0;}
      |   ^~~~
a.cc:16:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:16:19: error: 'endl' was not declared in this scope
   16 |   cout << ans <<  endl; return 0;}
      |                   ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | typedef long long ll;
Language: Java

import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] list = new long[n]; 
		for(int i = 0; i < n; i++){
			list[i] = sc.nextLong();
		}import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		int n = sc.nextInt();
		long k = sc.nextLong();
		long[] list = new long[n]; 
		for(int i = 0; i < n; i++){
			list[i] = sc.nextLong();
		}

		// 計算
		long maxSum = 0;
		for(long i = 0; i <= k; i++){
		    long sum = 0;
		    for(int j = 0; j < n; j++){
		        sum = sum + (long)(i^list[j]);
		        //System.out.println("k:" + i + " n:" + list[j] + " k xor n: " + String.valueOf(i^list[j]));
		        //System.out.println("sum:" + sum);
		    }
			maxSum = max(maxSum, sum);
			//System.out.println("maxSum:" + maxSum);
		}

		// 出力
		System.out.println(maxSum);
	}

}


		// 計算
		long maxSum = 0;
		for(int i = 0; i <= k; i++){
		    long sum = 0;
		    for(int j = 0; j < n; j++){
		        sum = sum + (long)(i^list[j]);
		        //System.out.println("k:" + i + " n:" + list[j] + " k xor n: " + String.valueOf(i^list[j]));
		        //System.out.println("sum:" + sum);
		    }
			maxSum = max(maxSum, sum);
			//System.out.println("maxSum:" + maxSum);
		}

		// 出力
		System.out.println(maxSum);
	}

}


Compiler output:
Main.java:14: error: illegal start of expression
		}import java.util.*;
		 ^
Main.java:14: error: <identifier> expected
		}import java.util.*;
		                  ^
Main.java:14: error: illegal start of expression
		}import java.util.*;
		                   ^
Main.java:15: error: illegal start of expression
import static java.lang.Math.*;
^
Main.java:15: error: illegal start of expression
import static java.lang.Math.*;
       ^
Main.java:15: error: <identifier> expected
import static java.lang.Math.*;
                             ^
Main.java:51: error: illegal start of type
		for(int i = 0; i <= k; i++){
		^
Main.java:51: error: <identifier> expected
		for(int i = 0; i <= k; i++){
		                ^
Main.java:51: error: <identifier> expected
		for(int i = 0; i <= k; i++){
		                     ^
Main.java:51: error: <identifier> expected
		for(int i = 0; i <= k; i++){
		                        ^
Main.java:63: error: <identifier> expected
		System.out.println(maxSum);
		                  ^
Main.java:63: error: <identifier> expected
		System.out.println(maxSum);
		                         ^
Main.java:66: error: class, interface, enum, or record expected
}
^
13 errors
Language: Java

import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		long n = sc.nextInt();
		long k = sc.nextInt();
		long[] list = new long[n]; 
		for(int i = 0; i < n; i++){
			list[i] = sc.nextLong();
		}

		// 計算
		long maxSum = 0;
		for(int i = 0; i <= k; i++){
		    long sum = 0;
		    for(int j = 0; j < n; j++){
		        sum = sum + (long)(i^list[j]);
		        //System.out.println("k:" + i + " n:" + list[j] + " k xor n: " + String.valueOf(i^list[j]));
		        //System.out.println("sum:" + sum);
		    }
			maxSum = max(maxSum, sum);
			//System.out.println("maxSum:" + maxSum);
		}

		// 出力
		System.out.println(maxSum);
	}

}


Compiler output:
Main.java:11: error: incompatible types: possible lossy conversion from long to int
		long[] list = new long[n]; 
		                       ^
1 error
Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iosfwd>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)

typedef long long ll;

const int MAX_DIGIT = 50;

ll A[100010];
ll dp[MAX_DIGIT][3];

string bit_str(ll num)
{
	auto bit_k = std::bitset<MAX_DIGIT>(num);
	string res = "";
	for (int i = MAX_DIGIT - 1; i >= 0; --i) {
		if (bit_k[i]) {
			res += "1";
		} else {
			res += "0";
		}
	}
	return res;
}

void Main()
{
	int N; cin >> N;
	ll K; cin >> K;
	rep(i,N) cin >> A[i];
	string bit_k = bit_str(K);

	memset(dp, -1, sizeof(dp));
	dp[0][1] = 0;
	rep(i,MAX_DIGIT) {
		char b = bit_k[i];
		int one_bit_sum = 0;
		rep(k,N) {
			if (A[k] & (1LL<<(MAX_DIGIT - i - 1))) {
				++one_bit_sum;
			}
		}
		ll zero_bit_cost = pow(2, MAX_DIGIT - i - 1) * one_bit_sum;
		ll one_bit_cost = pow(2, MAX_DIGIT - i - 1) * (N - one_bit_sum);

		if (dp[i][0] != -1) {
			dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + max(zero_bit_cost, one_bit_cost));
		}
		
		if (dp[i][1] != -1) {
			if (b == '1') {
		    	dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + zero_bit_cost);
		    }
		}

		if (dp[i][1] != -1) {
			if (b == '1') {
		    	dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + one_bit_cost);
		    }
		    if (b == '0') {
		    	dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + zero_bit_cost);
		    }
		}
	}
	cout << max(dp[bit_k.size()][0], dp[bit_k.size()][1]) << endl;
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


Compiler output:
a.cc: In function 'std::string bit_str(ll)':
a.cc:29:27: error: 'bitset' is not a member of 'std'
   29 |         auto bit_k = std::bitset<MAX_DIGIT>(num);
      |                           ^~~~~~
a.cc:13:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
   12 | #include <map>
  +++ |+#include <bitset>
   13 | #include <iosfwd>
Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iosfwd>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)

typedef long long ll;

const int MAX_DIGIT = 50;

ll A[100010];
ll dp[MAX_DIGIT][3];

string bit_str(ll num)
{
	auto bit_k = bitset<MAX_DIGIT>(num);
	string res = "";
	for (int i = MAX_DIGIT - 1; i >= 0; --i) {
		if (bit_k[i]) {
			res += "1";
		} else {
			res += "0";
		}
	}
	return res;
}

void Main()
{
	int N; cin >> N;
	ll K; cin >> K;
	rep(i,N) cin >> A[i];
	string bit_k = bit_str(K);

	memset(dp, -1, sizeof(dp));
	dp[0][1] = 0;
	rep(i,MAX_DIGIT) {
		char b = bit_k[i];
		int one_bit_sum = 0;
		rep(k,N) {
			if (A[k] & (1LL<<(MAX_DIGIT - i - 1))) {
				++one_bit_sum;
			}
		}
		ll zero_bit_cost = pow(2, MAX_DIGIT - i - 1) * one_bit_sum;
		ll one_bit_cost = pow(2, MAX_DIGIT - i - 1) * (N - one_bit_sum);

		if (dp[i][0] != -1) {
			dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + max(zero_bit_cost, one_bit_cost));
		}
		
		if (dp[i][1] != -1) {
			if (b == '1') {
		    	dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + zero_bit_cost);
		    }
		}

		if (dp[i][1] != -1) {
			if (b == '1') {
		    	dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + one_bit_cost);
		    }
		    if (b == '0') {
		    	dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + zero_bit_cost);
		    }
		}
	}
	cout << max(dp[bit_k.size()][0], dp[bit_k.size()][1]) << endl;
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


Compiler output:
a.cc: In function 'std::string bit_str(ll)':
a.cc:29:22: error: 'bitset' was not declared in this scope
   29 |         auto bit_k = bitset<MAX_DIGIT>(num);
      |                      ^~~~~~
a.cc:13:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
   12 | #include <map>
  +++ |+#include <bitset>
   13 | #include <iosfwd>
Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)

typedef long long ll;

const int MAX_DIGIT = 50;

ll A[100010];
ll dp[MAX_DIGIT][3];

string bit_str(ll num)
{
	auto bit_k = bitset<MAX_DIGIT>(num);
	string res = "";
	for (int i = MAX_DIGIT - 1; i >= 0; --i) {
		if (bit_k[i]) {
			res += "1";
		} else {
			res += "0";
		}
	}
	return res;
}

void Main()
{
	int N; cin >> N;
	ll K; cin >> K;
	rep(i,N) cin >> A[i];
	string bit_k = bit_str(K);

	memset(dp, -1, sizeof(dp));
	dp[0][1] = 0;
	rep(i,MAX_DIGIT) {
		char b = bit_k[i];
		int one_bit_sum = 0;
		rep(k,N) {
			if (A[k] & (1LL<<(MAX_DIGIT - i - 1))) {
				++one_bit_sum;
			}
		}
		ll zero_bit_cost = pow(2, MAX_DIGIT - i - 1) * one_bit_sum;
		ll one_bit_cost = pow(2, MAX_DIGIT - i - 1) * (N - one_bit_sum);

		if (dp[i][0] != -1) {
			dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + max(zero_bit_cost, one_bit_cost));
		}
		
		if (dp[i][1] != -1) {
			if (b == '1') {
		    	dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + zero_bit_cost);
		    }
		}

		if (dp[i][1] != -1) {
			if (b == '1') {
		    	dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + one_bit_cost);
		    }
		    if (b == '0') {
		    	dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + zero_bit_cost);
		    }
		}
	}
	cout << max(dp[bit_k.size()][0], dp[bit_k.size()][1]) << endl;
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


Compiler output:
a.cc: In function 'std::string bit_str(ll)':
a.cc:28:22: error: 'bitset' was not declared in this scope
   28 |         auto bit_k = bitset<MAX_DIGIT>(num);
      |                      ^~~~~~
a.cc:13:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
   12 | #include <map>
  +++ |+#include <bitset>
   13 |
Language: C++

#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

int freq[64];
unsigned long long arr[100005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    unsigned long long k, a; cin >> n >> k;

    for(int i = 0; i < n; ++i){
        cin >> a;
        arr[i] = a;
        for(int p = 0; p < 63; ++p)
            if((a >> p) & 1)
                ++freq[p];
    }

    unsigned long long nc1, nc2, x = 0;

    for(int pos = 63; pos >= 0; --pos){

        if(is_less == false && ((k >> pos) & 1) == 0)
            continue;

        if(freq[pos] * 2 < n){
            x |= 1ULL << pos;
        } else if((k >> pos) & 1){
            is_less = true;
        }

    }

    unsigned long long tot = 0;
    for(int i = 0; i < n; ++i)
        tot += x ^ arr[i];

    cout << tot << "\n";

    return 0;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:12: error: 'is_less' was not declared in this scope
   41 |         if(is_less == false && ((k >> pos) & 1) == 0)
      |            ^~~~~~~
a.cc:47:13: error: 'is_less' was not declared in this scope
   47 |             is_less = true;
      |             ^~~~~~~
Language: C++

#include <bits/stdc++.h>

using namespace std;

int arr[41];
int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  long long int k,t;
  vector <long long int> v;
  
  cin >> n >> k;
  
  for(int i=0;i<n;i++)
  {
    cin >> t;
    v.push_back(t);
  }
  
  memset(arr,0,sizeof(arr));
  
  for(int i=0;i<n;i++)
  {
    t = v[i];
    for(int j=0;j<41;j++)
    {
      if(t==0)
      {
        break;
      }
      
      if(t%2==1)
      {
        arr[j]++:
      }
    }
  }
  
  long long int temp=0;
  for(int i=40;i>=0;i--)
  {
    if(n-arr[i]>arr[i])
    {
      if(temp+(1LL<<i)<=k)
      {
        temp+=(1LL<<i);
      }
    }
  }
  
  long long int res = 0;
  for(int i=0;i<n;i++)
  {
    res+=(v[i]^temp);
  }
  
  cout << res << endl;
  
  return 0;
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:17: error: expected ';' before ':' token
   37 |         arr[j]++:
      |                 ^
      |                 ;
Language: C++

#include <bits/stdc++.h>

using namespace std;

int arr[41];
int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  long long int t;
  vector <long long int> v;
  
  cin >> n;
  
  for(int i=0;i<n;i++)
  {
    cin >> t;
    v.push_back(t);
  }
  
  memset(arr,0,sizeof(arr));
  
  for(int i=0;i<n;i++)
  {
    t = v[i];
    for(int j=0;j<41;j++)
    {
      if(t==0)
      {
        break;
      }
      
      if(t%2==1)
      {
        arr[j]++:
      }
    }
  }
  
  long long int temp=0;
  for(int i=40;i>=0;i--)
  {
    if(n-arr[i]>arr[i])
    {
      if(temp+(1LL<<i)<=k)
      {
        temp+=(1LL<<i);
      }
    }
  }
  
  long long int res = 0;
  for(int i=0;i<n;i++)
  {
    res+=(v[i]^temp);
  }
  
  cout << res << endl;
  
  return 0;
  
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:17: error: expected ';' before ':' token
   37 |         arr[j]++:
      |                 ^
      |                 ;
a.cc:47:25: error: 'k' was not declared in this scope
   47 |       if(temp+(1LL<<i)<=k)
      |                         ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

int cnt[41];
int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  long long int t;
  vector <long long int> v;
  
  cin >> n;
  
  for(int i=0;i<n;i++)
  {
    cin >> t;
    v.push_back(t);
  }
  
  memset(arr,0,sizeof(arr));
  
  for(int i=0;i<n;i++)
  {
    t = v[i];
    for(int j=0;j<41;j++)
    {
      if(t==0)
      {
        break;
      }
      
      if(t%2==1)
      {
        arr[j]++:
      }
    }
  }
  
  long long int temp=0;
  for(int i=40:i>=0;i--)
  {
    if(n-cnt[i]>cnt[i])
    {
      if(temp+(1LL<<i)<=k)
      {
        temp+=(1LL<<i);
      }
    }
  }
  
  long long int res = 0;
  for(int i=0;i<n;i++)
  {
    res+=(v[i]^temp);
  }
  
  cout << res << endl;
  
  return 0;
  
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:10: error: 'arr' was not declared in this scope
   23 |   memset(arr,0,sizeof(arr));
      |          ^~~
a.cc:43:12: error: initializer in range-based 'for' loop
   43 |   for(int i=40:i>=0;i--)
      |            ^
a.cc:43:20: error: expected ')' before ';' token
   43 |   for(int i=40:i>=0;i--)
      |      ~             ^
      |                    )
a.cc:43:21: error: 'i' was not declared in this scope
   43 |   for(int i=40:i>=0;i--)
      |                     ^
Language: C++

#include <stdio.h>
#define MAX(ans1,ans2) ((ans1) > (ans2) ? (ans1) : (ans2))
typedef _Bool bool;
#define true   (_Bool)1
#define false (_Bool)0
//typedef enum {false, true} bool;

long long a[100000];
int cnt[41];

int main(void) {
    int n;
    long long k;

    scanf("%d %lld", &n, &k);

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

    for (int i = 0;i < n;++i)
        for (int j = 40;j >= 0;--j)
            if (((1LL << j) & a[i]) == 0)
                cnt[j]++;

    long long total1 = 0, total2 = 0;
    bool chk = false;
    for (int i = 40;i >= 0;--i) {
        if ((total1 | (1LL << i)) <= k && cnt[i] >= n - cnt[i])
            total1 |= 1LL << i;
        if (chk && (total2 | (1LL << i)) <= k && cnt[i] >= n - cnt[i])
            total2 |= 1LL << i;
        if (k >= (1LL << i))
            chk = true;
    }

    long long ans1 = 0, ans2 = 0;
    for (int i = 0;i < n;++i) {
        ans1 += total1 ^ a[i];
        ans2 += total2 ^ a[i];
    }

    printf("%lld", MAX(ans1, ans2));

    return 0;
}


Compiler output:
a.cc:3:9: error: '_Bool' does not name a type
    3 | typedef _Bool bool;
      |         ^~~~~
a.cc: In function 'int main()':
a.cc:5:16: error: '_Bool' was not declared in this scope
    5 | #define false (_Bool)0
      |                ^~~~~
a.cc:26:16: note: in expansion of macro 'false'
   26 |     bool chk = false;
      |                ^~~~~
Language: C++

#include <stdio.h>
#define MAX(ans1,ans2) ((ans1) > (ans2) ? (ans1) : (ans2))
typedef enum {false, true} bool;

long long a[100000];
int cnt[41];

int main(void) {
    int n;
    long long k;

    scanf("%d %lld", &n, &k);

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

    for (int i = 0;i < n;++i)
        for (int j = 40;j >= 0;--j)
            if (((1LL << j) & a[i]) == 0)
                cnt[j]++;

    long long total1 = 0, total2 = 0;
    bool chk = false;
    for (int i = 40;i >= 0;--i) {
        if ((total1 | (1LL << i)) <= k && cnt[i] >= n - cnt[i])
            total1 |= 1LL << i;
        if (chk && (total2 | (1LL << i)) <= k && cnt[i] >= n - cnt[i])
            total2 |= 1LL << i;
        if (k >= (1LL << i))
            chk = true;
    }

    long long ans1 = 0, ans2 = 0;
    for (int i = 0;i < n;++i) {
        ans1 += total1 ^ a[i];
        ans2 += total2 ^ a[i];
    }

    printf("%lld", MAX(ans1, ans2));

    return 0;
}


Compiler output:
a.cc:3:15: error: expected identifier before 'false'
    3 | typedef enum {false, true} bool;
      |               ^~~~~
a.cc:3:15: error: expected '}' before 'false'
    3 | typedef enum {false, true} bool;
      |              ~^~~~~
a.cc:3:15: error: expected unqualified-id before 'false'
a.cc:3:26: error: expected declaration before '}' token
    3 | typedef enum {false, true} bool;
      |                          ^
a.cc:3:28: error: declaration does not declare anything [-fpermissive]
    3 | typedef enum {false, true} bool;
      |                            ^~~~
Language: C++

#include <stdio.h>
#define MAX(ans1,ans2) ((ans1) > (ans2) ? (ans1) : (ans2))
typedef enum {false, true} bool;

long long a[100000];
int cnt[41];

int main() {
    int n;
    long long k;

    scanf("%d %lld", &n, &k);

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

    for (int i = 0;i < n;++i)
        for (int j = 40;j >= 0;--j)
            if (((1LL << j) & a[i]) == 0)
                cnt[j]++;

    long long total1 = 0, total2 = 0;
    bool chk = false;
    for (int i = 40;i >= 0;--i) {
        if ((total1 | (1LL << i)) <= k && cnt[i] >= n - cnt[i])
            total1 |= 1LL << i;
        if (chk && (total2 | (1LL << i)) <= k && cnt[i] >= n - cnt[i])
            total2 |= 1LL << i;
        if (k >= (1LL << i))
            chk = true;
    }

    long long ans1 = 0, ans2 = 0;
    for (int i = 0;i < n;++i) {
        ans1 += total1 ^ a[i];
        ans2 += total2 ^ a[i];
    }

    printf("%lld", MAX(ans1, ans2));

    return 0;
}


Compiler output:
a.cc:3:15: error: expected identifier before 'false'
    3 | typedef enum {false, true} bool;
      |               ^~~~~
a.cc:3:15: error: expected '}' before 'false'
    3 | typedef enum {false, true} bool;
      |              ~^~~~~
a.cc:3:15: error: expected unqualified-id before 'false'
a.cc:3:26: error: expected declaration before '}' token
    3 | typedef enum {false, true} bool;
      |                          ^
a.cc:3:28: error: declaration does not declare anything [-fpermissive]
    3 | typedef enum {false, true} bool;
      |                            ^~~~
Language: Java

import java.util.*;

public class pD {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        List<Long> ai = new ArrayList<Long>(n) {{
            for (int i = 0; i < n; i++) {
                add(sc.nextLong());
            }
        }};
        //
        int strlen = Long.toBinaryString(k).length();
        for( long a : ai ) {
            int tmp = Long.toBinaryString(a).length();
            if( tmp > strlen ) strlen = tmp;
        }
        //
        int nh = n/2 + n%2;
        long ans = 0L;
        boolean isSmall = false;
        int j = strlen-1;
        long unit = Math.round(Math.pow(2, j));
        for (int i = 0; i < strlen; i++) {
            int one = 0;
            for (long a : ai) {
                one += (a >> j) & 1L;
            }

            boolean flag = ( (k>>j )&1L )==1L;
            if( one >= nh ) {
                ans += unit * one;
                if( flag ) isSmall = true;
            } else {
                if( !flag & !isSmall ) {
                    ans += unit * (long)one;
                } else {
                    ans += unit * (long)(n-one);
                }
            }
            j--;
            unit /= 2L;
        }
        System.out.println(ans);
    }
}

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

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

signed main(){
	int n,k;cin>>n>>k;
	vector<int>a(n);
	for(auto&& u:a)cin>>u;
	string s=to_string(k);
	int m=s.size();
	bool flg=true;
	int ret=0;
	repr(i,m+1){
	 int tmp=0;
	for(auto&& u:a)tmp+=(u>>i&1);
	int d=max(tmp,n-tmp);
	if(tmp<n-tmp &&(k>>i&1))flg=false;
	if(!flg||(k>>i&1)||tmp<=n-tmp)ret+=d<<i;
	}
	cout<<ret<<endl;
}

Compiler output:
a.cc:10:23: error: macro "for" requires 2 arguments, but only 1 given
   10 |         for(auto&& u:a)cin>>u;
      |                       ^
a.cc:5:9: note: macro "for" defined here
    5 | #define for(i,n) for(int i=0;i<(n);i++)
      |         ^~~
a.cc:17:23: error: macro "for" requires 2 arguments, but only 1 given
   17 |         for(auto&& u:a)tmp+=(u>>i&1);
      |                       ^
a.cc:5:9: note: macro "for" defined here
    5 | #define for(i,n) for(int i=0;i<(n);i++)
      |         ^~~
a.cc: In function 'int main()':
a.cc:10:24: error: expected '(' before 'cin'
   10 |         for(auto&& u:a)cin>>u;
      |                        ^~~
      |                        (
a.cc:10:29: error: 'u' was not declared in this scope
   10 |         for(auto&& u:a)cin>>u;
      |                             ^
a.cc:11:29: error: could not convert 's' from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'bool'
   11 |         string s=to_string(k);
      |                             ^
      |                             |
      |                             std::string {aka std::__cxx11::basic_string<char>}
a.cc:3:13: error: expected primary-expression before 'long'
    3 | #define int long long
      |             ^~~~
a.cc:12:9: note: in expansion of macro 'int'
   12 |         int m=s.size();
      |         ^~~
a.cc:11:31: error: expected ')' before 'long'
   11 |         string s=to_string(k);
      |                               ^
      |                               )
a.cc:10:24: note: to match this '('
   10 |         for(auto&& u:a)cin>>u;
      |                        ^~~
a.cc:15:14: error: 'i' was not declared in this scope
   15 |         repr(i,m+1){
      |              ^
a.cc:15:16: error: 'm' was not declared in this scope
   15 |         repr(i,m+1){
      |                ^
a.cc:15:9: error: 'repr' was not declared in this scope
   15 |         repr(i,m+1){
      |         ^~~~
Language: C++

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

signed main(){
	int n,k;cin>>n>>k;
	vector<int>a(n);
	for(auto&& u:a)cin>>u;
	string s=to_string(k);
	int m=s.size();
	bool flg=true;
	int ret=0;
	repr(i,m+1){
	 int tmp=0;
	rep(i,n)tmp+=(a>>i&1);
	int d=max(tmp,n-tmp);
	if(tmp<n-tmp &&(k>>i&1))flg=false;
	if(!flg||(k>>i&1)||tmp<=n-tmp)ret+=d<<i;
	}
	cout<<ret<<endl;
}

Compiler output:
a.cc:10:23: error: macro "for" requires 2 arguments, but only 1 given
   10 |         for(auto&& u:a)cin>>u;
      |                       ^
a.cc:5:9: note: macro "for" defined here
    5 | #define for(i,n) for(int i=0;i<(n);i++)
      |         ^~~
a.cc: In function 'int main()':
a.cc:10:24: error: expected '(' before 'cin'
   10 |         for(auto&& u:a)cin>>u;
      |                        ^~~
      |                        (
a.cc:10:29: error: 'u' was not declared in this scope
   10 |         for(auto&& u:a)cin>>u;
      |                             ^
a.cc:11:29: error: could not convert 's' from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'bool'
   11 |         string s=to_string(k);
      |                             ^
      |                             |
      |                             std::string {aka std::__cxx11::basic_string<char>}
a.cc:3:13: error: expected primary-expression before 'long'
    3 | #define int long long
      |             ^~~~
a.cc:12:9: note: in expansion of macro 'int'
   12 |         int m=s.size();
      |         ^~~
a.cc:11:31: error: expected ')' before 'long'
   11 |         string s=to_string(k);
      |                               ^
      |                               )
a.cc:10:24: note: to match this '('
   10 |         for(auto&& u:a)cin>>u;
      |                        ^~~
a.cc:15:14: error: 'i' was not declared in this scope
   15 |         repr(i,m+1){
      |              ^
a.cc:15:16: error: 'm' was not declared in this scope
   15 |         repr(i,m+1){
      |                ^
a.cc:15:9: error: 'repr' was not declared in this scope
   15 |         repr(i,m+1){
      |         ^~~~
Language: C++

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

signed main(){
	int n,k;cin>>n>>k;
	vector<int>a(n);
	for(auto&& u:a)cin>>u;
	string s=to_string(k);
	int m=s.size();
	bool flg=true;
	int ret=0;
	int digit;
	repr(i,m+1){
	 int tmp=0;
	rep(i,n)tmp+=(a>>i&1);
	int k=max(tmp,n-tmp);
	if(tmp<n-tmp &&(k>>i&1))flg=false;
	if(!flg||(k>>i&1)||tmp<=n-tmp)ret+=k<<i;
	}
	cout<<ret<<endl;
}

Compiler output:
a.cc:10:23: error: macro "for" requires 2 arguments, but only 1 given
   10 |         for(auto&& u:a)cin>>u;
      |                       ^
a.cc:5:9: note: macro "for" defined here
    5 | #define for(i,n) for(int i=0;i<(n);i++)
      |         ^~~
a.cc: In function 'int main()':
a.cc:10:24: error: expected '(' before 'cin'
   10 |         for(auto&& u:a)cin>>u;
      |                        ^~~
      |                        (
a.cc:10:29: error: 'u' was not declared in this scope
   10 |         for(auto&& u:a)cin>>u;
      |                             ^
a.cc:11:29: error: could not convert 's' from 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'bool'
   11 |         string s=to_string(k);
      |                             ^
      |                             |
      |                             std::string {aka std::__cxx11::basic_string<char>}
a.cc:3:13: error: expected primary-expression before 'long'
    3 | #define int long long
      |             ^~~~
a.cc:12:9: note: in expansion of macro 'int'
   12 |         int m=s.size();
      |         ^~~
a.cc:11:31: error: expected ')' before 'long'
   11 |         string s=to_string(k);
      |                               ^
      |                               )
a.cc:10:24: note: to match this '('
   10 |         for(auto&& u:a)cin>>u;
      |                        ^~~
a.cc:16:14: error: 'i' was not declared in this scope
   16 |         repr(i,m+1){
      |              ^
a.cc:16:16: error: 'm' was not declared in this scope
   16 |         repr(i,m+1){
      |                ^
a.cc:16:9: error: 'repr' was not declared in this scope
   16 |         repr(i,m+1){
      |         ^~~~
Language: C++

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MAX_DIGIT = 40;
ll dp[100][2];

int main() {
  ll N, K; cin >> N >> K;
  vector<ll> A(N);
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for(int d = 0; d < MAX_DIGIT; ++d) {
    ll mask = 1LL<<(MAX_DIGIT - d - 1);

    int num =0 ;
    for(int i =0 ; i < N; ++i) if(A[i] & mask) ++num;

    ll cost0 = mask * num;
    ll cost1 = mask * (N - num);

    if(dp[d][1] != -1) {
      chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1));
    }

    if(dp[d][0] != -1) {
      if(K & mask) {
        chmax(dp[d+1][1], dp[d][0] + cost0);
      }
    }

    if(dp[d][0] != -1) {
      if(K & mask) chmax(dp[d+1][0], dp[d][0] + cost1);
      else chmax(dp[d+1][0], dp[d][0] + cost0);
    }
  }
  cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:16:3: error: 'memset' was not declared in this scope
   16 |   memset(dp, -1, sizeof(dp));
      |   ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include <vector>
  +++ |+#include <cstring>
    3 | using namespace std;