Language: C++

using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
typedef long long ll;

int main(){
  int n, k;
  cin >> n >> k;
  ll a[n];
  rep(i,n) cin >> a[i];
  bool update;
  vector<int> bitk(40,0);
  vector<int> bita(40,0);
  vector<ll> pow2(40,0);
  int j = 39;
  while(j >= 0){
    if(j == 39) pow2[j] = 1;
    else pow2[j] = pow2[j+1]*2;
    rep(i,n){
      if(a[i] % 2) bita[j]++;
      a[i] /= 2;
    }
    bitk[j] = k % 2;
    k /= 2;
    j--;
  }
  vector<vector<ll>> dp(41, vector<ll>(2,0));
  bool can = false;
  rep(i,40){
      if(bitk[i]) can = true;
      if(bitk[i]) dp[i+1][1] = max(dp[i+1][1], dp[i][0]+pow2[i]*bita[i]);
      if(can) dp[i+1][1] = max(dp[i+1][1], dp[i][1] + pow2[i]*max(bita[i],n-bita[i]));
      if(bitk[i]) dp[i+1][0] = dp[i][0] + pow2[i]*(n-bita[i]);
      else dp[i+1][0] = dp[i][0] + pow2[i]*bita[i];
  }
  cout << max(dp[40][0],dp[40][1]) << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:7:3: error: 'cin' was not declared in this scope
    7 |   cin >> n >> k;
      |   ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:11:3: error: 'vector' was not declared in this scope
   11 |   vector<int> bitk(40,0);
      |   ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:11:10: error: expected primary-expression before 'int'
   11 |   vector<int> bitk(40,0);
      |          ^~~
a.cc:12:10: error: expected primary-expression before 'int'
   12 |   vector<int> bita(40,0);
      |          ^~~
a.cc:13:12: error: expected primary-expression before '>' token
   13 |   vector<ll> pow2(40,0);
      |            ^
a.cc:13:14: error: 'pow2' was not declared in this scope
   13 |   vector<ll> pow2(40,0);
      |              ^~~~
a.cc:19:20: error: 'bita' was not declared in this scope
   19 |       if(a[i] % 2) bita[j]++;
      |                    ^~~~
a.cc:22:5: error: 'bitk' was not declared in this scope
   22 |     bitk[j] = k % 2;
      |     ^~~~
a.cc:26:19: error: expected primary-expression before '>>' token
   26 |   vector<vector<ll>> dp(41, vector<ll>(2,0));
      |                   ^~
a.cc:26:38: error: expected primary-expression before '>' token
   26 |   vector<vector<ll>> dp(41, vector<ll>(2,0));
      |                                      ^
a.cc:26:22: error: 'dp' was not declared in this scope
   26 |   vector<vector<ll>> dp(41, vector<ll>(2,0));
      |                      ^~
a.cc:29:10: error: 'bitk' was not declared in this scope
   29 |       if(bitk[i]) can = true;
      |          ^~~~
a.cc:30:10: error: 'bitk' was not declared in this scope
   30 |       if(bitk[i]) dp[i+1][1] = max(dp[i+1][1], dp[i][0]+pow2[i]*bita[i]);
      |          ^~~~
a.cc:30:65: error: 'bita' was not declared in this scope
   30 |       if(bitk[i]) dp[i+1][1] = max(dp[i+1][1], dp[i][0]+pow2[i]*bita[i]);
      |                                                                 ^~~~
a.cc:30:32: error: 'max' was not declared in this scope
   30 |       if(bitk[i]) dp[i+1][1] = max(dp[i+1][1], dp[i][0]+pow2[i]*bita[i]);
      |                                ^~~
a.cc:31:67: error: 'bita' was not declared in this scope
   31 |       if(can) dp[i+1][1] = max(dp[i+1][1], dp[i][1] + pow2[i]*max(bita[i],n-bita[i]));
      |                                                                   ^~~~
a.cc:31:63: error: 'max' was not declared in this scope
   31 |       if(can) dp[i+1][1] = max(dp[i+1][1], dp[i][1] + pow2[i]*max(bita[i],n-bita[i]));
      |                                                               ^~~
a.cc:31:28: error: 'max' was not declared in this scope
   31 |       if(can) dp[i+1][1] = max(dp[i+1][1], dp[i][1] + pow2[i]*max(bita[i],n-bita[i]));
      |                            ^~~
a.cc:32:10: error: 'bitk' was not declared in this scope
   32 |       if(bitk[i]) dp[i+1][0] = dp[i][0] + pow2[i]*(n-bita[i]);
      |          ^~~~
a.cc:32:54: error: 'bita' was not declared in this scope
   32 |       if(bitk[i]) dp[i+1][0] = dp[i][0] + pow2[i]*(n-bita[i]);
      |                                                      ^~~~
a.cc:33:44: error: 'bita' was not declared in this scope
   33 |       else dp[i+1][0] = dp[i][0] + pow2[i]*bita[i];
      |                                            ^~~~
a.cc:35:3: error: 'cout' was not declared in this scope
   35 |   cout << max(dp[40][0],dp[40][1]) << endl;
      |   ^~~~
a.cc:35:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:35:11: error: 'max' was not declared in this scope
   35 |   cout << max(dp[40][0],dp[40][1]) << endl;
      |           ^~~
a.cc:35:39: error: 'endl' was not declared in this scope
   35 |   cout << max(dp[40][0],dp[40][1]) << endl;
      |                                       ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;