Language: C++

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  uint64_t n,k;
  cin>>n>>k;
  std::vector<std::bitset<64>> a(n);
  for(uint64_t i=0;i<n;i++){
    uint64_t pushed;
    cin>>pushed;
    a[i]=std::bitset<64>(pushed);
  }

  int topbit=0;
  while(std::pow(2,topbit+1)<=k){
    topbit++;
  }


  std::bitset<64> result(0);
  for(int bi=topbit;bi>=0;bi--){
    int count=0;
    for(auto bs:a){
      if(bs[bi]){
        count++;
      }
    }
    if(count<=floor((double)n/2)){
      if(result[topbit]){
        //nothing
      }else{
        result[bi]=true;
      }
    }
  }

  uint64_t sum=0;
  if(k==0){
    for(auto bs:a){
      sum+=bs.to_ullong();
      cout<<sum<<endl;
    }
  } 

  
  for(auto bs:a){
    sum+=(bs^result).to_ullong();
  }
  cout<<sum<<endl;





  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:3: error: 'uint64_t' was not declared in this scope
   26 |   uint64_t n,k;
      |   ^~~~~~~~
a.cc:15:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
   14 | #include <utility>
  +++ |+#include <cstdint>
   15 | #include <vector>
a.cc:27:8: error: 'n' was not declared in this scope; did you mean 'yn'?
   27 |   cin>>n>>k;
      |        ^
      |        yn
a.cc:27:11: error: 'k' was not declared in this scope
   27 |   cin>>n>>k;
      |           ^
a.cc:28:20: error: 'bitset' is not a member of 'std'
   28 |   std::vector<std::bitset<64>> a(n);
      |                    ^~~~~~
a.cc:15:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
   14 | #include <utility>
  +++ |+#include <bitset>
   15 | #include <vector>
a.cc:28:27: error: template argument 1 is invalid
   28 |   std::vector<std::bitset<64>> a(n);
      |                           ^~
a.cc:28:27: error: template argument 2 is invalid
a.cc:28:29: error: expected unqualified-id before '>' token
   28 |   std::vector<std::bitset<64>> a(n);
      |                             ^~
a.cc:29:15: error: expected ';' before 'i'
   29 |   for(uint64_t i=0;i<n;i++){
      |               ^~
      |               ;
a.cc:29:20: error: 'i' was not declared in this scope
   29 |   for(uint64_t i=0;i<n;i++){
      |                    ^
a.cc:30:13: error: expected ';' before 'pushed'
   30 |     uint64_t pushed;
      |             ^~~~~~~
      |             ;
a.cc:31:10: error: 'pushed' was not declared in this scope
   31 |     cin>>pushed;
      |          ^~~~~~
a.cc:32:5: error: 'a' was not declared in this scope
   32 |     a[i]=std::bitset<64>(pushed);
      |     ^
a.cc:32:15: error: 'bitset' is not a member of 'std'
   32 |     a[i]=std::bitset<64>(pushed);
      |               ^~~~~~
a.cc:32:15: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
a.cc:41:8: error: 'bitset' is not a member of 'std'
   41 |   std::bitset<64> result(0);
      |        ^~~~~~
a.cc:41:8: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
a.cc:41:19: error: 'result' was not declared in this scope
   41 |   std::bitset<64> result(0);
      |                   ^~~~~~
a.cc:44:17: error: 'a' was not declared in this scope
   44 |     for(auto bs:a){
      |                 ^
a.cc:58:11: error: expected ';' before 'sum'
   58 |   uint64_t sum=0;
      |           ^~~~
      |           ;
a.cc:60:17: error: 'a' was not declared in this scope
   60 |     for(auto bs:a){
      |                 ^
a.cc:61:7: error: 'sum' was not declared in this scope
   61 |       sum+=bs.to_ullong();
      |       ^~~
a.cc:67:15: error: 'a' was not declared in this scope
   67 |   for(auto bs:a){
      |               ^
a.cc:68:5: error: 'sum' was not declared in this scope
   68 |     sum+=(bs^result).to_ullong();
      |     ^~~
a.cc:70:9: error: 'sum' was not declared in this scope
   70 |   cout<<sum<<endl;
      |         ^~~