Language: C++

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

    memset(dp, -1, sizeof(dp)); // -1に初期化
    dp[0][0] = 0;
    for(int d= 0; d < MAX_DIGIT; ++d){
        long long mask = 1LL << (MAX_DIGIT - d - 1);

        // A で元々 d 桁目にビットが立っているものの個数
        int num = 0;

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

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

        //smaller --> smaller 
        if(dp[d][1] != -1 ){
            chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1)); // 0でも1でも可能
        }

        //exat --> smaller
        if(dp[d][0] != -1){
            // K の d 桁目が 1 だったら、X の d 桁目は 0 にする
            if(K & mask){
            chmax(dp[d+1][1], dp[d][0] + cost0);                
            }
        }

        //exact -- > exact
        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;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:4:5: error: 'cin' was not declared in this scope
    4 |     cin >> N >> K;
      |     ^~~
a.cc:5:5: error: 'vector' was not declared in this scope
    5 |     vector<long long> A(N);
      |     ^~~~~~
a.cc:5:12: error: expected primary-expression before 'long'
    5 |     vector<long long> A(N);
      |            ^~~~
a.cc:6:40: error: 'A' was not declared in this scope
    6 |     for(int i = 0 ; i < N; ++i) cin >> A[i];
      |                                        ^
a.cc:8:12: error: 'dp' was not declared in this scope
    8 |     memset(dp, -1, sizeof(dp)); // -1に初期化
      |            ^~
a.cc:8:5: error: 'memset' was not declared in this scope
    8 |     memset(dp, -1, sizeof(dp)); // -1に初期化
      |     ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
  +++ |+#include <cstring>
    1 | int main(){
a.cc:10:23: error: 'MAX_DIGIT' was not declared in this scope
   10 |     for(int d= 0; d < MAX_DIGIT; ++d){
      |                       ^~~~~~~~~
a.cc:17:16: error: 'A' was not declared in this scope
   17 |             if(A[i] & mask ) ++ num;
      |                ^
a.cc:26:42: error: 'max' was not declared in this scope
   26 |             chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1)); // 0でも1でも可能
      |                                          ^~~
a.cc:26:13: error: 'chmax' was not declared in this scope
   26 |             chmax(dp[d+1][1], dp[d][1] + max(cost0, cost1)); // 0でも1でも可能
      |             ^~~~~
a.cc:33:13: error: 'chmax' was not declared in this scope
   33 |             chmax(dp[d+1][1], dp[d][0] + cost0);
      |             ^~~~~
a.cc:40:17: error: 'chmax' was not declared in this scope
   40 |                 chmax(dp[d+1][0], dp[d][0] + cost1);
      |                 ^~~~~
a.cc:42:17: error: 'chmax' was not declared in this scope
   42 |                 chmax(dp[d+1][0], dp[d][0] + cost0);
      |                 ^~~~~
a.cc:47:5: error: 'cout' was not declared in this scope
   47 |     cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
      |     ^~~~
a.cc:47:20: error: 'MAX_DIGIT' was not declared in this scope
   47 |     cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
      |                    ^~~~~~~~~
a.cc:47:13: error: 'max' was not declared in this scope
   47 |     cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
      |             ^~~
a.cc:47:56: error: 'endl' was not declared in this scope
   47 |     cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
      |                                                        ^~~~