Buggy python submission (verdict: Runtime Error):
from itertools import zip_longest
def get_X(ls):
    X = list()
    for xs in zip_longest(*ls):
        xs = [i for i in xs if i is not None]
        _sum = sum(xs)
        _len = len(xs)
        if _len - _sum > _sum:
            X.append(1)
        else:
            X.append(0)
    return X

def get_2_order(d, max_len=None):
    ls = str(bin(d))[2:]
    if max_len is not None and max_len > len(ls):
        ls = (max_len - len(ls)) * "0" + ls
    return ls

def get_max(X,ls):
    _sum = 0
    for i, xs in enumerate(zip_longest(*ls)):
        xs = [i for i in xs if i is not None]
        _sum += 2**i*sum([1 if x != X[i] else 0 for j,x in enumerate(xs)])
    return _sum


N, K = map(int, input().split())
A_ls = [int(i) for i in input().split()]
if len(A_ls) == 1:
    print(A_ls[0])
else:
    _max = 0
    len_K = len(bin(K))-2
    A_ls = [get_2_order(d, len_K)[::-1] for d in A_ls]
    for i in range(K):
        X = get_2_order(i, len_K)[::-1]
        result = get_max(X, A_ls)
        if _max < result:
            _max = result
    print(_max)

Fixed submission:
import sys
from collections import Counter
INF = 10**18
N, K = [int(i) for i in sys.stdin.readline().split()]
len_k = len(bin(K)[2:])
A_ls = [bin(int(i))[2:] for i in sys.stdin.readline().split()]
max_len = max([len(i) for i in A_ls] + [len_k])
K = bin(K)[2:].zfill(max_len)
A_ls = [A.zfill(max_len) for A in A_ls]
# i番目の解
memo_ls = [0 for i in range(max_len)]
# i番目のみの最適解を考えた時の和
memo_ls2 = [0 for i in range(max_len)]
for i in range(max_len):
    ct = Counter([A[-1-i] for A in A_ls])
    # i番目のけたとして0を選んだ時の和
    ans_0 = 2**i*ct["1"]
    ans_1 = 2**i*ct["0"]
    ct.clear()
    memo_ls[-1-i] = (ans_0, ans_1)
    memo_ls2[-1-i] = max(ans_0, ans_1)
# i-1番目までの解の最大
# memo_ls3[i][j] j : 答えが決まっている時1, いない時0
memo_ls3 = [[0 for i in range(2)] for i in range(max_len + 1)]
memo_ls3[0][1] = -INF
for i, j in enumerate(K, 1):
    if j == "0":
        memo_ls3[i][0] = memo_ls3[i-1][0] + memo_ls[i-1][0]
        memo_ls3[i][1] = memo_ls3[i-1][1] + memo_ls2[i-1]
    else:
        memo_ls3[i][0] = memo_ls3[i-1][0] + memo_ls[i-1][1]
        memo_ls3[i][1] = max(memo_ls3[i-1][1] + memo_ls2[i-1], memo_ls3[i-1][0] + memo_ls[i-1][0])
res = max(memo_ls3[-1])
print(int(res))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import zip_longest
def get_X(ls):
    X = list()
    for xs in zip_longest(*ls):
        xs = [i for i in xs if i is not None]
        _sum = sum(xs)
        _len = len(xs)
        if _len - _sum > _sum:
            X.append(1)
        else:
            X.append(0)
    return X

def get_2_order(d, max_len=None):
    i = 1
    ls = []
    while True:
        amari = d%2**i
        ls.append(amari//2**(i-1))
        d -= amari
        if d < 2**i:
            break
        i += 1
    if max_len is not None:
        while len(ls) < max_len:
            ls.append(0)
    return ls

def get_max(X,ls):
    _sum = 0
    for i, xs in enumerate(zip_longest(*ls)):
        xs = [i for i in xs if i is not None]
        _sum += 2**i*sum([1 if x != X[i] else 0 for j,x in enumerate(xs)])
    return _sum


N, K = map(int, input().split())
A_ls = [int(i) for i in input().split()]
if len(A_ls) == 1:
    print(A_ls[0])
else:
    _max = 0
    len_K = len(get_2_order(K))
    A_ls = [get_2_order(d, len_K) for d in A_ls]
    for i in range(K):
        X = get_2_order(i, len_K)
        result = get_max(X, A_ls)
        if _max < result:
            _max = result
    print(_max)

Fixed submission:
import sys
from collections import Counter
INF = 10**18
N, K = [int(i) for i in sys.stdin.readline().split()]
len_k = len(bin(K)[2:])
A_ls = [bin(int(i))[2:] for i in sys.stdin.readline().split()]
max_len = max([len(i) for i in A_ls] + [len_k])
K = bin(K)[2:].zfill(max_len)
A_ls = [A.zfill(max_len) for A in A_ls]
# i番目の解
memo_ls = [0 for i in range(max_len)]
# i番目のみの最適解を考えた時の和
memo_ls2 = [0 for i in range(max_len)]
for i in range(max_len):
    ct = Counter([A[-1-i] for A in A_ls])
    # i番目のけたとして0を選んだ時の和
    ans_0 = 2**i*ct["1"]
    ans_1 = 2**i*ct["0"]
    ct.clear()
    memo_ls[-1-i] = (ans_0, ans_1)
    memo_ls2[-1-i] = max(ans_0, ans_1)
# i-1番目までの解の最大
# memo_ls3[i][j] j : 答えが決まっている時1, いない時0
memo_ls3 = [[0 for i in range(2)] for i in range(max_len + 1)]
memo_ls3[0][1] = -INF
for i, j in enumerate(K, 1):
    if j == "0":
        memo_ls3[i][0] = memo_ls3[i-1][0] + memo_ls[i-1][0]
        memo_ls3[i][1] = memo_ls3[i-1][1] + memo_ls2[i-1]
    else:
        memo_ls3[i][0] = memo_ls3[i-1][0] + memo_ls[i-1][1]
        memo_ls3[i][1] = max(memo_ls3[i-1][1] + memo_ls2[i-1], memo_ls3[i-1][0] + memo_ls[i-1][0])
res = max(memo_ls3[-1])
print(int(res))