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

#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
#include<time.h>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<int, int> P;

ll dp[55][2];

int main(void) {
	int n;
	ll k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0;i < 50;i++) {
		for (int j = 0;j < 2;j++) {
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 0;
	for (int d = 0; d < 50; ++d) {
		ll mask = (ll)1 << (50 - 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) {
			dp[d + 1][1] = max(dp[d + 1][1], dp[d][1] + max(cost0, cost1));
		}

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

		if (dp[d][0] != -1) {
			if (k & mask) dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + cost1);
			else dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + cost0);
		}
	}
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare) [with _Tp = long long int; _Compare = long long int]':
a.cc:53:23:   required from here
   53 |                                 dp[d + 1][1] = max(dp[d + 1][1], dp[d][0] + cost0, cost1);
      |                                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:306:17: error: '__comp' cannot be used as a function
  306 |       if (__comp(__a, __b))
      |           ~~~~~~^~~~~~~~~~
Language: C++

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


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

    long long n,k;
    cin >> n >> k;
    long long a;
    long long cnt[50]={};
    long long sum = 0;
    for(int i=0;i<n;i++){
        cin>>a;
        sum += a;
        int d = 0;
        while(a){
            if(a%2==1){
                cnt[d]++;
            }
            a/=2;
            d++;
        }
    }
    string s="";
    while(k){
        if(k%2==0){
            s+='0';
        }
        else s+='1';
        k/=2;
    }
    reverse(s.begin(),s.end());
 
    int m = s.size();
    long long dp1[m+1]={};
    long long dp2[m+1]={};
    for(int i=0;i<m;i++){
        long long d = m - i - 1;
        if(s[i] == '1'){
            dp1[i+1] = dp1[i] + (n-cnt[d]) * pow(2LL,d);
            dp2[i+1] = dp2[i] + max(n-cnt[d], cnt[d]) * pow(2LL,d);
            dp2[i+1] = max(dp2[i+1], dp1[i] + cnt[d] * (long long)pow(wLL,d));
        }
        else {
            dp1[i+1] = dp1[i] + cnt[d] * pow(2LL,d);
            dp2[i+1] = dp2[i] + max(n-cnt[d], cnt[d]) * pow(2LL,d);
            dp2[i+1] = max(dp2[i+1], dp1[i] + cnt[d] * (long long)pow(2LL,d) );
        }
    }
    long long ans = max(dp1[m], dp2[m]);
    for(long long i=m;i<50;i++){
        ans += pow(2LL,i) * cnt[i];
    }
    
    cout << ans << endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:71: error: 'wLL' was not declared in this scope
   44 |             dp2[i+1] = max(dp2[i+1], dp1[i] + cnt[d] * (long long)pow(wLL,d));
      |                                                                       ^~~
Language: C++

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

int main(){
    long long n, k;
    cin >> n >> k;
    long long a;
    long long cnt[50]={};
    long long sum = 0;
    for (int i = 0; i < n; i++ ){
        cin >> a;
        sum+=a;
        int d = 0;
        while(a){
            if(a % 2 == 1){
                cnt[d]++;
            }
            a /= 2;
            d++;
        }
    }
    if(k==0){
        cout<<sum<<endl;
        return 0;
    }
    long long ans = 0;
    string s="";
    while(k){
        if(k%2==1){
            s += '1';
        }
        else s += '0';
        k /= 2;
    }
    reverse(s.begin(),s.end());
    long long dp1[s.size()+1] = {};
    long long dp2[s.size()+1] = {};

    for(int i = 0; i < s.size(); i++ ){
        long long m = s.size()-i-1;
        // 0
        dp2[i+1] = dp2[i] + cnt[m] * pow(2LL,m);

        if(s[i] == '1'){
            dp1[i+1] = max(dp1[i+1], dp1[i] + (n-cnt[m]) * (long long)pow(2LL,m));
            dp2[i+1] = max(dp2[i+1], dp2[i] + (n-cnt[m]) * (long long)pow(2LL,m));
        }
        else {
            dp1[i+1] = dp1[i] + cnt[m])* pow(2LL,m);
            dp2[i+1] = max(dp2[i+1], max(dp1[i],dp2[i]) + (n-cnt[m]) * (long long)pow(2LL,m));
        }
        //cerr << i << " " <<  cnt[m] << " " << pow(2LL,m) << " "<< dp1[i+1] << " "<< dp2[i+1] <<endl;
    }
    ans = max(dp1[s.size()],dp2[s.size()]);
    
    cout << ans << endl;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:39: error: expected ';' before ')' token
   49 |             dp1[i+1] = dp1[i] + cnt[m])* pow(2LL,m);
      |                                       ^
      |                                       ;
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>


#define rep(i,p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;


//119 D

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

int main(void) {
	ll n,k;
	cin >> n >> k;
	const ll MAX_DIGIT = 41;
	vector<ll> a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}
	ll dp[MAX_DIGIT][2];
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	rep(i, 0, MAX_DIGIT) {
		ll mask = (ll)1 << (MAX_DIGIT - i - 1);

		int num = 0;
		rep(j, 0, n) if (a[j] & mask)	++num;

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

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

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

			if (k & mask) chmax(dp[i + 1][0], dp[i][0] + cost1);
			else chmax(dp[i + 1][0], dp[i][0] + cost0);
		}
	}

	cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
	
	
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:9: error: 'memset' was not declared in this scope
   32 |         memset(dp, -1, sizeof(dp));
      |         ^~~~~~
a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   10 | #include <queue>
  +++ |+#include <cstring>
   11 |
Language: C++

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

int main()
{
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    long long res = 0;
    for (int d = 60; d >= -1; d--)
    {
        if(d!=-1 && !(K&(1LL<<d))) continue;

        long long tmp = 0;

        for (int e = 60; e > -1; e--)
        {
            long long mask = 1LL << e;
            int num = 0;
            for (int i = 0; i < N; i++)
            {
                if(mask&A[i]) num++;
            }
            
            if (e > d)
            {
                if(mask&K)
                    tmp += mask * (N - num);
                else
                    tmp += mask * num;
            }
            else if(e==d){
                tmp += mask * num;

            }

            else{
                tmp += mask * max(num, N - num);
            }


        }
        res = max(res, tmp);
    }

    cout << res << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:34: error: no matching function for call to 'max(int&, long long int)'
   42 |                 tmp += mask * max(num, N - num);
      |                               ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:42:34: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   42 |                 tmp += mask * max(num, N - num);
      |                               ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:42:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   42 |                 tmp += mask * max(num, N - num);
      |                               ~~~^~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


signed main() {
	ll N,K;
	cin >> N >> K;
	vector<ll> a(N,0);
	rep(i,N)cin >> a[i];

	if(K==0){
		p(accumulate(a.begin(), a.end(), 0LL));
		return 0;
	}

	ll size=ceil(log2(K));
	siez=40;
	vector<ll> bit(size,0);

	rep(i,N){
		rep(j,size){
			if(a[i] & (1LL<<j)){
				bit[j]--;
			}else{
				bit[j]++;
			}
		}
	}

	ll k=0;
	for(ll i=size-1;i>=0;i--){
		if(bit[i]>0 && (k|(1LL<<i))<=K ){
			k|=(1LL<<i);
		}
	}
	debug(bit);
	debug(k);

	ll ans=0;
	rep(i,N){
		ans+=a[i]^k;
	}
	p(ans);
	return 0;
}


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

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


signed main() {
	ll N,K;
	cin >> N >> K;
	vector<ll> a(N,0);
	rep(i,N)cin >> a[i];

	if(K==0){
		p(accumulate(a.begin(), a.end(), 0LL));
		return 0;
	}

	ll size=ceil(log2(K));
	vector<ll> bit(size,0);

	rep(i,N){
		rep(j,size){
			if(a[i] & (1LL<<j)){
				bit[j]--;
			}else{
				bit[j]++;
			}
		}
	}

	ll k=0;
	for(ll i=size-1;i>=0;i--){
		if(bit[i]>=0) && (k|(1<<i))<=K ){
			k|=(1LL<<i);
		}
	}
	debug(bit);
	debug(k);

	ll ans=0;
	rep(i,N){
		ans+=a[i]^k;
	}
	p(ans);
	return 0;
}


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

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


signed main() {
	ll N,K;
	cin >> N >> K;
	vector<ll> a(N,0);
	rep(i,N)cin >> a[i];

	if(K==0){
		p(accumulate(v.begin(), v.end(), 0LL);
		return 0;
	}

	ll size=ceil(log2(K));
	vector<ll> bit(size,0);

	rep(i,N){
		rep(j,size){
			if(a[i] & (1<<j)){
				bit[j]--;
			}else{
				bit[j]++;
			}
		}
	}

	ll k=0;
	for(ll i=size-1;i>=0;i--){
		if(bit[i]>=0 && (k|(1<<i))<=K ){
			k|=(1<<i);
		}
	}
	debug(bit);
	debug(k);

	ll ans=0;
	rep(i,N){
		ans+=a[i]^k;
	}
	p(ans);
	return 0;
}


Compiler output:
a.cc:2:10: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory
    2 | #include <boost/multiprecision/cpp_int.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: Java

=

import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		long k=scan.nextLong();
//		System.out.println((1^0)+" "+(6^0)+" "+(3^0));
		long ar[]=new long[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextLong();
			
		}
		long now=0l;
		long ans=0l;
		for(int j=50;j>=0;j--)
		{
			if(((1L<<j)+now)>k)continue;
			int num=0;
//			System.out.println(j);
			for(int i=0;i<n;i++)
			{
				if((ar[i]&(1L<<(j)))>=1)num++;
				
			}
			if(num<=(n/2)) {
				now+=(1L<<j);
//				System.out.println("yes"+" "+num);
			}
		}
//		System.out.println(now);
		for(int i=0;i<n;i++)
		{
			ans+=(ar[i]^now);
		}
		System.out.println(ans);
	}
}


Compiler output:
Main.java:1: error: class, interface, enum, or record expected
=
^
1 error
Language: Java



import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		long n=scan.nextLong();
		long k=scan.nextLong();
//		System.out.println((1^0)+" "+(6^0)+" "+(3^0));
		long ar[]=new long[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextLong();
			
		}
		long now=0l;
		long ans=0l;
		for(int j=50;j>=0;j--)
		{
			if(((1L<<j)+now)>k)continue;
			int num=0;
//			System.out.println(j);
			for(int i=0;i<n;i++)
			{
				if((ar[i]&(1L<<(j)))>=1)num++;
				
			}
			if(num<=(n/2)) {
				now+=(1L<<j);
//				System.out.println("yes"+" "+num);
			}
		}
//		System.out.println(now);
		for(int i=0;i<n;i++)
		{
			ans+=(ar[i]^now);
		}
		System.out.println(ans);
	}
}


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

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
const int maxn = 2e5+100;

const ll inf = 1e18;
int mask[maxn][50][2];
int raw[50][2];

int main()
{
    ll n , k;
    cin >> n >> k;
    for(int i = 1; i<=n; i++){
        ll p; cin >> p;
        for(int j = 0; j<50; j++){
            ll bit = (p & (1ll << j)) > 0 ? 1 : 0;
            raw[bit]++;
        }
    }
    ll K = 0 , ans = 0;
    for(ll i = 50; i>=0; i--){
        ll one = raw[i][1];
        ll zero = raw[i][0];
        if(one > zero){
            ans += (1ll << i) * one;
        }
        else if(((1ll << i)+K)<=k){
            K += (1ll << i);
            ans += (1ll<<i) * zero;
        }
        else{
            ans += (1ll << i) * one;
        }
    }
    cout << ans << endl;



}



Compiler output:
a.cc: In function 'int main()':
a.cc:20:20: error: lvalue required as increment operand
   20 |             raw[bit]++;
      |             ~~~~~~~^
Language: C++

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

int LIMIT = 40;

int main() {
  long long N, K;
  cin >> N >> K;

  long long A[N];

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

  long long b[LIMIT];
  b[0] = 1;
  for (int i = 1; i < LIMIT; i++) {
    b[i] = b[i - 1] * 2;
  }

  reverse(b, b + LIMIT);

  long long c[LIMIT];
  for (int i = 0; i < LIMIT; i++) {
    c[i] = 0;
  }

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

  string perfect = "";
  for (int i = 0; i < LIMIT; i++) {
    perfect += (2 * c[i] >= N ? "0" : "1");
  }
  string strK = bitset<64>(K).to_string();

  vector<long long> tries;
  tries.push_back(K);
  for (int i = 0; i < strK.length(); i++) {
    if (strK[i] == '1') {
      string temp = strK.substr(0, i) + "0" +
                    perfect.substr(perfect.length() - (strK.length() - i - 1),
                                   perfect.length());
      tries.push_back(stoll(temp, nullptr, 2));
    }
  }

  // for (auto a = tries.begin(); a != tries.end(); a++) {
  //   cout << *a << ", ";
  // }
  // cout << endl;

  long long ans = 0;

  for (auto a = tries.begin(); a != tries.end(); a++) {
    string strT = bitset<32>(*a).to_string();
    while (strT.length() < LIMIT) strT = "0" + strT;
    // cout << "strT: " << strT << endl;

    long long tempAns = 0;
    for (int i = 0; i < strT.length(); i++) {
      if (strT[i] == '0') {
        // cout << "bi: " << b[i] << " ci: " << c[i] << endl;
        tempAns += b[i] * c[i];
      } else {
        tempAns += b[i] * (N - c[i]);
      }
      // cout << "tempAns: " << tempAns << endl;
    }

    if (tempAns > ans) ans = tempAns;
  }

  cout << ans << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:17: error: 'bitset' was not declared in this scope
   49 |   string strK = bitset<64>(K).to_string();
      |                 ^~~~~~
a.cc:7:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
    6 | #include <queue>
  +++ |+#include <bitset>
    7 | #include <string>
a.cc:49:31: error: request for member 'to_string' in 'K', which is of non-class type 'long long int'
   49 |   string strK = bitset<64>(K).to_string();
      |                               ^~~~~~~~~
a.cc:70:34: error: request for member 'to_string' in 'a.__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::operator*()', which is of non-class type 'long long int'
   70 |     string strT = bitset<32>(*a).to_string();
      |                                  ^~~~~~~~~
Language: C++

#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
const int MAX_DIGIT = 50;
ll dp[51][2];

int main(){
    int n; cin >> n;
    ll k; cin >> k;
    vector<ll> a(n);
    for(auto& v:a){cin >> v;}
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for(int d = 0; d < MAX_DIGIT; d++){
        ll mask = 1LL<<(MAX_DIGIT - 1 - d);
        int num = 0;
        for(int i = 0; i < n; i++) if (a[i] & mask) num++;
        ll score0 = mask * num;
        ll score1 = mask * (n - num);

        // fit to fit
        if(k & mask){
            dp[d+1][0] = dp[d][0] + score1;
        }
        else{
            dp[d+1][0] = dp[d][0] + score0;
        }
        // loose to loose
        if(dp[d][1] != -1){
            dp[d+1][1] = max(dp[d][1] + score0, dp[d][1] + score1);
        }
        // fit to loose
        if(k & mask){
            dp[d+1][1] = max(dp[d+1][1], dp[d][0] + score0);
        }
    }

    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
    return 0;
}

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

#include <vector>
#include <iostream>
#include <bitset>

using namespace std;
typedef long long ll;
#define SIZE 64

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

	vector<int> bit_cnt(SIZE, 0);

	for (int i = 0; i < n; i++) {
		ll val;
		cin >> val;

		bitset<SIZE> bits(val);

		for (int j = 0; j < SIZE; j++) {
			if (bits[j]) bit_cnt[j]++;
		}
	}

	ll cur_val = 0;
	ll cur_num = 0;
	for (int i = 41; i >= 0; i--) {
		ll add = pow((ll)2, (ll)i);

		if (cur_num + add > k) {
			cur_val += bit_cnt[i] * add;
			continue;
		}
		
		if (bit_cnt[i] > n / 2) {
			cur_val += bit_cnt[i] * add;
		}
		else {
			cur_num += add;
			cur_val += (n - bit_cnt[i]) * add;
		}
	}

	cout << cur_val;

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:26: error: 'pow' was not declared in this scope
   29 |                 ll add = pow((ll)2, (ll)i);
      |                          ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
ll mod = 1000000007;
ll INF = 1000000099;
signed main(){
    for(int i=0;i < 100;i++)
    {
        cout<<pow(2,j)<<":"<< (1ll<<j) <<endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:21: error: 'j' was not declared in this scope
   12 |         cout<<pow(2,j)<<":"<< (1ll<<j) <<endl;
      |                     ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
ll mod = 1000000007;
ll INF = 1000000099;

signed main(){
    ll n,K,ans=0,x=0;
    cin >>n>>K;
    vector<ll> v(n);
    for (ll i = 0; i < n; i++)
    {
        cin>>v.at(i);
    }
    
//bitcount,存在する桁としない桁があるので、bit数が違うことに注意

    for (ll i = 60; -1<=i ; i--)//iより上の桁はＫと一致
    {
        ll x=0;
        if( !(K & (1ll<<i)) && d!=-1){
            continue;
        }
            for (ll j = 60; 0<=j ; j--)
            {
                ll mask = 1ll<<j,cnt=0;
                for (ll i = 0; i < n; i++)
                {
                    if(mask&v.at(i)) cnt++;
                }
                
                if(j>i){
                    if(K & 1ll<<j){//kのそのビットが1
                        x+=pow(2,j)*(n-cnt);
                    }else{
                        x+=pow(2,j)*cnt;
                    }
                }else if(j==i){
                    x+=pow(2,j)*cnt;
                }else{
                    x+=pow(2,j)*max(cnt,n-cnt);
                }
            }
            ans=max(ans,x);
       
    }
    cout<<ans<<endl;
}
/*
制約がない場合のxを出しておいて、何桁目までkと一致させるか考えていく
+=する時、初期化してるか確認

bitで表したときのある桁を、直接確認する時&が使える*/

Compiler output:
a.cc: In function 'int main()':
a.cc:24:32: error: 'd' was not declared in this scope
   24 |         if( !(K & (1ll<<i)) && d!=-1){
      |                                ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
ll mod = 1000000007;
ll INF = 1000000099;
signed main(){
    ll n,k,ans=0,cnt=0,y,X;
    cin >>n>>k;
    y=k;
    vector<ll> K;

    if(y==0){
        ll y;
        cin >>y;
        cout<<y<<endl;
        return 0;
    }//コーナー処理

    while(y>0){
        if(y%2==0){
            K.pb(0);
        }else{
            K.pb(1);
        }

        y/=2;
        cnt++;
    }//K(2)を格納する（小さい方から）

    vector<ll> d(cnt,0);//各bitの１の個数

    for (ll i = 0; i < n; i++)
    {
        ll a,c=0;
        cin >> a;
        while(a>0 && c<cnt){
            if(a%2==1){
                d.at(c)++;
            }
            c++;
            a/=2;
        }
    }//count
    vector<ll> x(cnt);

    for (ll i = 0; i < cnt; i++)
    {
        if(n > 2*d.at(i)){
            ans+=pow(2,i) * (n-d.at(i));
            x.at(i)=1;
            X+=pow(2,i);
        }else{
            ans+=pow(2,i)*d.at(i)%mod;
            x.at(i)=0;
        }
    }//ansはこの時点では理想形

    if(X>k){
        for (ll i = cnt-1; 0<=i ; i--)//数を減らすとき、上から見ていける
        {
            if(x.at(i)==1 && K.at(i)==0){
                ans-=pow(2,i)*(n-d.at(i));
                ans+=pow(2,i)*d.at(i)%mod;
                X-=pow(2,i);
            }

            if(X<=k){
                break;
            }
        }
    }//X（理想形）の上位の桁からKと一致させていく
   
    cout<<ans%mod<<endl;
}
/*後から制約を導入するのは難しい 先に制約内で全探索するべきだった
制約がない場合のxを出しておいて、何桁目までkと一致させるか考えていく*/



Compiler output:
a.cc: In function 'int main()':
a.cc:56:34: error: invalid operands of types '__gnu_cxx::__promote<double>::__type' {aka 'double'} and 'll' {aka 'long long int'} to binary 'operator%'
   56 |             ans+=pow(2,i)*d.at(i)%mod;
      |                  ~~~~~~~~~~~~~~~~^~~~
      |                          |        |
      |                          |        ll {aka long long int}
      |                          __gnu_cxx::__promote<double>::__type {aka double}
a.cc:66:38: error: invalid operands of types '__gnu_cxx::__promote<double>::__type' {aka 'double'} and 'll' {aka 'long long int'} to binary 'operator%'
   66 |                 ans+=pow(2,i)*d.at(i)%mod;
      |                      ~~~~~~~~~~~~~~~~^~~~
      |                              |        |
      |                              |        ll {aka long long int}
      |                              __gnu_cxx::__promote<double>::__type {aka double}
Language: C++

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

int main() {
  long long N, K, A; cin >> N >> K;
  vector<long long> Kbin(40,0);
  for (int i=0; i<40; i++) Kbin[39-i] = 1&(K>>i);
  
  vector<vector<long long>> Abin(N, vector<long long>(40,0));
  for (int n=0; n<N; n++) {
    cin >> A;
    for (int i=0; i<40; i++) Abin[n][39-i] = 1&(A>>i);
  }
  vector<long long> Abinnum(40,0);
  for (int i=0; i<40; i++) {
    long long tmp=0;
    for (int j=0; j<N; j++) tmp += Abin[j][i];
    Abinnum[i]=tmp;
  }

  vector<vector<long long>> dp(41, vector<long long>(2,0));
  //dp[桁数][上限ギリギリ]=上限ギリギリと上限未満それぞれの各桁までのXor最大
  int Kcnt=0;
  for (int i=0; i<40; i++) {
    Kcnt+=Kbin[i];
    if(Kbin[i]==0){
      if(Kcnt>0) {
        dp[i+1][0] = dp[i][0]+max((Abinnum[i],N-Abinnum[i])*(1ull<<(39-i));
        dp[i+1][1] = dp[i][1]+Abinnum[i]*(1ull<<(39-i));
      }
      else {
        dp[i+1][0] = 0;
        dp[i+1][1] = dp[i][1]+Abinnum[i]*(1ull<<(39-i));
      }
    }
    else {
        dp[i+1][0] = max(dp[i][0]+max(Abinnum[i],N-Abinnum[i])*(1ull<<(39-i)), dp[i][1]+Abinnum[i]*(1ull<<(39-i)));
        dp[i+1][1] = dp[i][1]+(N-Abinnum[i])*(1ull<<(39-i));
    }
  }
  cout << max(dp[40][0], dp[40][1]) << "\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:45: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   28 |         dp[i+1][0] = dp[i][0]+max((Abinnum[i],N-Abinnum[i])*(1ull<<(39-i));
      |                                             ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: declared here
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
a.cc:28:75: error: expected ')' before ';' token
   28 |         dp[i+1][0] = dp[i][0]+max((Abinnum[i],N-Abinnum[i])*(1ull<<(39-i));
      |                                  ~                                        ^
      |                                                                           )
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

typedef long long ll;

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

  const ll MAX_DIGIT = 40;
  // dp[i+1][smaller]
  // 上からi桁目まで考えたときのfの最大値
  ll dp[MAX_DIGIT+1][2];
  memset(dp, -1, sizeof(dp));

  dp[0][0] = 0;
  for (ll d = 0; d < MAX_DIGIT; d++) {
    ll offset = MAX_DIGIT - 1 -d;
    ll mask = 1LL << offset;
    // d桁目のKの値(2進数)
    ll n = (K & mask) >> offset;
    // cout << "mask: " << mask << " n; " << n << endl;

    // A で元々 d 桁目にビットが立っているものの個数
    ll num = 0;
    for (ll i = 0; i < N; ++i) {
      if (A[i] & mask) {
        num++;
      }
    }

    // X の d 桁目を 0, 1 にしたときのコスト
    ll cost0 = mask * num;
    ll cost1 = mask * (N - num);
    if (mask > K) cost1 = 0;

    // cout << "cost0: " << cost0 << endl;
    // cout << "cost1: " << cost1 << endl;

    for (ll smaller = 0; smaller < 2; smaller++) {
      for (ll x = 0; x <= (smaller == 0 ? n : 1); x++) {
        chmax(dp[d+1][smaller || x < n], dp[d][smaller] + (x == 1 ? cost1 : cost0));
        // cout << "dp " << d+1 << " " << smaller << " " << "to " << dp[d+1][smaller] << endl;
      }
    }
  }

  cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
  return 0;
}


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

#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
    long long N, K; string K_bitset; cin >> N >> K; K_bitset = bitset<40>(K).to_string();
    string *A = new string[N]; for(int i=0; i<N; i++) { long long x; cin >> x; A[i] = bitset<40>(x).to_string(); }
    long long A_sum[40] = {}; for(int i=0; i<N; i++) { for(int j=0; j<40; j++) A_sum[j] += (char)A[i][j] - '0';}
    long long result = 0;
    for(int i=0; i<40; i++) {
        if ((char)K_bitset[i] == '1' and A_sum[i] * 2 < N) {
            result += pow(2, 39-i) * (N-A_sum[i]);
        } else {
            result += pow(2, 39-i) * A_sum[i];å
        }
    }
    cout << result << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:64: error: 'bitset' was not declared in this scope
    8 |     long long N, K; string K_bitset; cin >> N >> K; K_bitset = bitset<40>(K).to_string();
      |                                                                ^~~~~~
a.cc:4:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
    3 | #include <math.h>
  +++ |+#include <bitset>
    4 | 
a.cc:8:78: error: request for member 'to_string' in 'K', which is of non-class type 'long long int'
    8 |     long long N, K; string K_bitset; cin >> N >> K; K_bitset = bitset<40>(K).to_string();
      |                                                                              ^~~~~~~~~
a.cc:9:101: error: request for member 'to_string' in 'x', which is of non-class type 'long long int'
    9 |     string *A = new string[N]; for(int i=0; i<N; i++) { long long x; cin >> x; A[i] = bitset<40>(x).to_string(); }
      |                                                                                                     ^~~~~~~~~
a.cc:16:47: error: '\U000000e5' was not declared in this scope
   16 |             result += pow(2, 39-i) * A_sum[i];å
      |                                               ^
Language: C++

#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
    int N, K; string K_bitset; cin >> N >> K; K_bitset = bitset<40>(K).to_string();
    string *A = new string[N]; for(int i=0; i<N; i++) { long x; cin >> x; A[i] = bitset<40>(x).to_string(); }
    int A_sum[40] = {}; for(int i=0; i<N; i++) { for(int j=0; j<40; j++) A_sum[j] += (char)A[i][j] - '0';}
    long result = 0;
    for(int i=0; i<40; i++) {
        if ((char)K_bitset[i] == '1' and A_sum[i] * 2 < N) {
            result += pow(2, 39-i) * (N-A_sum[i]);
        } else {
            result += pow(2, 39-i) * A_sum[i];
        } 
    }
    cout << result << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:58: error: 'bitset' was not declared in this scope
    8 |     int N, K; string K_bitset; cin >> N >> K; K_bitset = bitset<40>(K).to_string();
      |                                                          ^~~~~~
a.cc:4:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
    3 | #include <math.h>
  +++ |+#include <bitset>
    4 | 
a.cc:8:72: error: request for member 'to_string' in 'K', which is of non-class type 'int'
    8 |     int N, K; string K_bitset; cin >> N >> K; K_bitset = bitset<40>(K).to_string();
      |                                                                        ^~~~~~~~~
a.cc:9:96: error: request for member 'to_string' in 'x', which is of non-class type 'long int'
    9 |     string *A = new string[N]; for(int i=0; i<N; i++) { long x; cin >> x; A[i] = bitset<40>(x).to_string(); }
      |                                                                                                ^~~~~~~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
    int N, K; string K_bitset; cin >> N >> K; K_bitset = bitset<40>(K).to_string();
    string A[N]; for(int i=0; i<N; i++) { long x; cin >> x; A[i] = bitset<40>(x).to_string(); }
    int A_sum[40] = {}; for(int i=0; i<N; i++) { for(int j=0; j<40; j++) A_sum[j] += (char)A[i][j] - '0';}
    long result = 0;
    for(int i=0; i<40; i++) {
        if ((char)K_bitset[i] == '1' and A_sum[i] * 2 < N) {
            result += pow(2, 39-i) * (N-A_sum[i]);
        } else {
            result += pow(2, 39-i) * A_sum[i];
        } 
    }
    cout << result << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:58: error: 'bitset' was not declared in this scope
    8 |     int N, K; string K_bitset; cin >> N >> K; K_bitset = bitset<40>(K).to_string();
      |                                                          ^~~~~~
a.cc:4:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
    3 | #include <math.h>
  +++ |+#include <bitset>
    4 | 
a.cc:8:72: error: request for member 'to_string' in 'K', which is of non-class type 'int'
    8 |     int N, K; string K_bitset; cin >> N >> K; K_bitset = bitset<40>(K).to_string();
      |                                                                        ^~~~~~~~~
a.cc:9:82: error: request for member 'to_string' in 'x', which is of non-class type 'long int'
    9 |     string A[N]; for(int i=0; i<N; i++) { long x; cin >> x; A[i] = bitset<40>(x).to_string(); }
      |                                                                                  ^~~~~~~~~
Language: C++


#include <iostream>
#include <vector>

using namespace std;

int main(){
    long N,k;
    long Max = 0;
    cin >> N >> K;
    vector<int> L(N);
    for(int i = 0;i < N;i++){
        cin >> L[i];
    }
    for(int i = 0;i < K;i++){
        long Ans = 0;
        for(int j = 0;j < N;j++){
            if(L[j] == i){
                break;
            }else{
                Ans += i ^ L[j];
            }
        }
        Max = std::max(Max,Ans);
    }
    cout << Max << endl;
}

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

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

int main()
{
	int n, digitNum;
	unsigned long long k, sum = 0;
	cin >> n >> k;
	if (k == 0) {
		auto temp = 0ULL;
		for (int i = 0; i < n; ++i) {
			cin >> temp;
			sum += temp;
		}
		cout << sum << endl;
		return 0;
	}

	digitNum = (int)(log2(k) + 1);
	vector<unsigned long long> ai(n);

	vector<pair<int, int>> digitOneNum(digitNum);
	for (int i = 0; i < digitNum; ++i)digitOneNum[i] = make_pair(i, 0);
	for (auto& a : ai) {
		cin >> a;
		sum += a;
		for (int i = 0; i < digitNum; ++i) {
			if (a & (1ULL << i))++digitOneNum[i].second;
		}
	}
	sort(digitOneNum.begin(), digitOneNum.end(), [](pair<int, int> l, pair<int, int> r) {
		return l.second < r.second;
		});
	auto digitOneMajorIt = upper_bound(digitOneNum.begin(), digitOneNum.end(), n / 2,
		[](int v, pair<int, int> e) {
			return v < e.second;
		});

	auto diff = 0LL;
	auto kCand = 0ULL;
	for (auto it = digitOneNum.begin(); it != digitOneMajorIt; ++it) {
		if ((kCand + (1ULL << (*it).first)) <= k) {
			kCand += (1ULL << (*it).first);
			diff += (1ULL << (*it).first) * (n - (*it).second * 2);
		}
	}

	cout << sum + diff << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:26: error: 'log2' was not declared in this scope
   22 |         digitNum = (int)(log2(k) + 1);
      |                          ^~~~
Language: C++


#include <iostream>
#include <vector>

using namespace std;

int main(){
    long N;
    long K;
    long Max = 0;
    cin >> N >> K;
    vector<int> L(N);
    for(int i = 0;i < N;i++){
        cin >> L[i];
    }
    for(int i = 0;i < K;i++){
        int Ans = 0;
        for(int j = 0;j < N;j++){
            Ans += i ^ L[j];
        }
        Max = max(Max,Ans);
    }
    cout << Max << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:18: error: no matching function for call to 'max(long int&, int&)'
   21 |         Max = max(Max,Ans);
      |               ~~~^~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:21:18: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   21 |         Max = max(Max,Ans);
      |               ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
Language: C++

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

const int LEN = 48;

using namespace std;
using lli = long long int;

int main() {
    int N;
    string K;
    lli max = 0,k;
    {
        lli tmp;
        cin >> N >> tmp;
        max = tmp;
        k   = tmp;
    }

    vector<string> A(N);
    for (auto &i : A) {
        lli tmp;
        cin >> tmp;
        if (tmp > max) max = tmp;
        i = bitset<LEN>(tmp).to_string();
    }
    K         = bitset<LEN>(max).to_string();
    bool flag = false;
    lli ans   = 0;
    for (int i = 0; i < LEN; i++) {
        if (flag == false) {
            if (K[i] == '1')
                flag = true;
            else
                continue;
        }
        int one = 0, zero = 0;
        for (auto &a : A) {
            if (a[i] == '1')
                one++;
            else
                zero++;
        }
        const lli tmp = pow(2, LEN - i - 1);
        if (one > zero||tmp>k) {
            ans += tmp * one;
        }

        else {
            ans += tmp * zero;
        }
    }
    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:25: error: 'pow' was not declared in this scope
   46 |         const lli tmp = pow(2, LEN - i - 1);
      |                         ^~~
Language: C++

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

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vll;

vi binary_digit(ll x){
  vi ans(50);
  for(int k=0;k<50;++k){
    int a=(x>>k)&1;
    ans[k]=a;
  }
  return ans;
}

vi minority(vll& A){
  vi count(50);
  int N=A.size();
  for (int n=0;n<N;++n){
    vi bi=binary_digit(A[n]);
    for (int i=0;i<50;++i){
      count[i]+=bi[i];
    }
  }

  vi ans(50);
  for (int i=0;i<50;++i){
    if(count[i]<N-count[i]){ans[i]=1;}
    else{ans[i]=0;}
  }

  return ans;
}

int main(){
  int N;cin>>N;ll K;cin>>K;
  vll A;
  for (int n=0;n<N;++n){
    ll a;cin>>a;A.push_back(a);
  }

  vi K_bin=binary_digit(K);
  vi mino=monority(A);
  ll X;
  int diff_flag=0;
  for (int i=50;i>=0;--i){
    if(diff_flag==0&&K_bin[i]==0){
      X+=0;
    }
    else{
      X+=mino[i]*(ll)pow(2,i);
      if(K_bin[i]!=mino[i]){diff_flag=1;}
    }
  }

  ll ans=0;
  for (int i=0;i<50;++i){
    ans+=X^A[i];
  }
  cout << ans;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:11: error: 'monority' was not declared in this scope; did you mean 'minority'?
   44 |   vi mino=monority(A);
      |           ^~~~~~~~
      |           minority
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define ggr getchar();getchar();return 0
using namespace std;
int n,k,a[100010];
int m[50];
int dp[60][2];
signed main(){
	cin>>n>>k;
	rep(i,n)cin>>a[i];
	int ma=0;
	rep(i,50){
		rep(j,n){
			if((a[j]>>i)&1){
				m[i]++;
				ma=max(ma,i);
			}
		}
	}
	for(int i=49;i>=0;i--){
		if(((ll)1<<i)>k)continue;
		dp[i][0]=max(dp[i][0],dp[i+1][0]);
		dp[i][0]=max(dp[i][0],dp[i+1][0]+((ll)1<<i)*m[i]);
		dp[i][0]=max(dp[i][0],dp[i+1][0]+((ll)1<<i)*(n-m[i]));
		if((k<<i)&1){
			dp[i][0]=max(dp[i][0],dp[i+1][1]+((ll)1<<i)*m[i]);
			dp[i][1]=dp[i][0];
			dp[i][1]=max(dp[i][1],dp[i+1][1]+((ll)1<<i)*(n-m[i]));
		}
		else{
			dp[i][1]=dp[i][0];
			dp[i][1]=max(dp[i][1],dp[i+1][1]+((ll)1<<i)*m[i]);
		}
	}
	int ans=0;
	rep(i,n)ans+=a[i];
	else cout<<max(dp[0][0],dp[0][1],ans)<<endl;
	ggr;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:45:9: error: 'else' without a previous 'if'
   45 |         else cout<<max(dp[0][0],dp[0][1],ans)<<endl;
      |         ^~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare) [with _Tp = long long int; _Compare = long long int]':
a.cc:45:16:   required from here
   45 |         else cout<<max(dp[0][0],dp[0][1],ans)<<endl;
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:306:17: error: '__comp' cannot be used as a function
  306 |       if (__comp(__a, __b))
      |           ~~~~~~^~~~~~~~~~