Language: C++

//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
//template<class T> T power(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always



/*
 110 0 110011 ideal
 100 1 000010 k
 100 0 110011 ans
 
 
 
 */

template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
int main() {
    
    
    
    
    int n; ll k; cin >> n >> k;
    
    int table[40] = {0};
    ll b[n]; rep(i, n) cin >> b[i];
    
    rep(i, n) {
        bitset<40> a = b[i];
        rep(j, 40) {
            if (a[j] == 1) table[j]++;
        }
        
    }
    
    ll tmp = 0;
    rep(i, 40) {
        if (n % 2 == 0 && table[i] < n / 2) tmp += power(2, i);
        else if (n % 2 != 0 && table[i] <= n / 2) {tmp += power(2, i);}
    }
    
    bitset<40> a = tmp;
    bitset<40> K = k;
    //out(a); out(K);
    ll ans = 0;
    int flg = 0; //同じ間
    rep(i, 40) {
        if (flg == 0 && K[39 - i] == 1 && a[39 - i] == 0) {
            flg = 1;
        } else if (flg == 0) {
            if (K[39 - i] == 1 && a[39 - i] == 1) {
                ans += power(2, 39 - i);
            }
        } else { //flg == 1
            if (a[39 - i] == 1) {
                ans += power(2, 39 - i);
            }
        }
        
        
    }
    //out(ans);
    ll aans = 0;
    rep(i, n) {
        aans += ans ^ b[i];
    }
    out(aans);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:69:9: error: 'bitset' was not declared in this scope
   69 |         bitset<40> a = b[i];
      |         ^~~~~~
a.cc:3:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
    2 | #include<iostream>
  +++ |+#include <bitset>
    3 | using namespace std;
a.cc:69:20: error: 'a' was not declared in this scope
   69 |         bitset<40> a = b[i];
      |                    ^
a.cc:82:5: error: 'bitset' was not declared in this scope
   82 |     bitset<40> a = tmp;
      |     ^~~~~~
a.cc:82:5: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
a.cc:82:16: error: 'a' was not declared in this scope
   82 |     bitset<40> a = tmp;
      |                ^
a.cc:83:16: error: 'K' was not declared in this scope
   83 |     bitset<40> K = k;
      |                ^