Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*14
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(13,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*42
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(41,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=[0]*40
    p=[1]*40
    for i in range(39):
        p[i+1]=p[i]*2
    for i in a:
        for j in range(40):
            if i&p[j]>0:
                b[j]+=1
    ans=0
    for i in range(k+1):
        kai=0
        for j in range(40):
            if i&p[j]==0:
                kai+=b[j]*p[j]
            else:
                kai+=(n-b[j])*p[j]
        ans=max(ans,kai)
    print(ans)
if __name__=='__main__':
    main()


Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*42
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(41,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=[0]*40
    p=[1]*40
    for i in range(39):
        p[i+1]=p[i]*2
    for i in a:
        for j in range(40):
            if i&p[j]>0:
                b[j]+=1
    ans=0
    for i in range(k+1):
        kai=0
        for j in range(40):
            if i&p[j]==0:
                kai+=b[j]*p[j]
            else:
                kai+=(n-b[j])*p[j]
        ans=max(ans,kai)
    print(ans)
if __name__=='__main__':
    main()

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*42
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(41,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*40
p=[1]*40
for i in range(39):
    p[i+1]=p[i]*2
for i in a:
    for j in range(40):
        if i&p[j]>0:
            b[j]+=1
ans=0
for i in range(k+1):
    kai=0
    for j in range(40):
        if i&p[j]==0:
            kai+=b[j]*p[j]
        else:
            kai+=(n-b[j])*p[j]
    ans=max(ans,kai)
print(ans)


Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*42
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(41,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*40
p=[1]*40
for i in range(39):
    p[i+1]=p[i]*2
for i in a:
    for j in range(40):
        if i&p[j]>0:
            b[j]+=1
ans=0
for i in range(k+1):
    kai=0
    for j in range(40):
        if i&p[j]==0:
            kai+=b[j]*p[j]
        else:
            kai+=(n-b[j])*p[j]
    ans=max(ans,kai)
print(ans)


Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*42
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(41,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*41
p=[1]*41
for i in range(40):
    p[i+1]=p[i]*2
for i in a:
    for j in range(41):
        if i&p[j]>0:
            b[j]+=1
ans=0
for i in range(k+1):
    kai=0
    for j in range(41):
        if i&p[j]==0:
            kai+=b[j]*p[j]
        else:
            kai+=(n-b[j])*p[j]
    ans=max(ans,kai)
print(ans)


Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*42
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(41,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*41
for i in a:
    for j in range(41):
        if i&(2**j)>0:
            b[j]+=1
ans=0
for i in range(k+1):
    kai=0
    for j in range(41):
        if i&(2**j)==0:
            kai+=b[j]*(2**j)
        else:
            kai+=(n-b[j])*(2**j)
    ans=max(ans,kai)
print(ans)

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*42
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(41,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)