Solve in Python:
You are given N non-negative integers A_1, A_2, ..., A_N and another non-negative integer K.
For a integer X between 0 and K (inclusive), let f(X) = (X XOR A_1) + (X XOR A_2) + ... + (X XOR A_N).
Here, for non-negative integers a and b, a XOR b denotes the bitwise exclusive OR of a and b.
Find the maximum value of f.
What is XOR?
The bitwise exclusive OR of a and b, X, is defined as follows:
 - When X is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if, when written in base two, exactly one of A and B has 1 in the 2^k's place, and 0 otherwise.
For example, 3 XOR 5 = 6. (When written in base two: 011 XOR 101 = 110.)

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 10^5
 - 0 \leq K \leq 10^{12}
 - 0 \leq A_i \leq 10^{12}

-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N

-----Output-----
Print the maximum value of f.

-----Sample Input-----
3 7
1 6 3

-----Sample Output-----
14

The maximum value is: f(4) = (4 XOR 1) + (4 XOR 6) + (4 XOR 3) = 5 + 2 + 7 = 14.
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

less = -float('inf')
eq = 0

for d in range(60)[::-1]:
    mask = (1 << d)

    one = len([0 for a in A if (a & mask) != 0])
    zero = N - one

    l = less + mask * max(one, zero)

    if (K & mask) != 0:
        l = max(l, eq + mask * one)

    less = l
    eq += mask * (one if (K & mask == 0) else zero)

print((max(less, eq)))