Problem p03138 (python)

Fixed submission:
n,k=map(int,input().split())
k2=format(k+1,"0%ib"%40)
lists=list(map(int,input().split()))
countlist=[0]*40
for j in lists:
    c=format(j,"0%ib"%40)
    for i in range(40):
        if c[i]=="1":
            countlist[i]+=1

emptylist=[]
for i in range(40):
    if k2[i]=="1":
        emptylist.append(i)
if k>=1:
    ans=0
    for i in emptylist:
        subing=0
        for j in range(40):
            if j<i:
                if k2[j]=="1":
                    subing+=(2**(39-j))*(n-countlist[j])
                elif k2[j]=="0":
                    subing+=(2**(39-j))*countlist[j]
            if j==i:
                subing+=(2**(39-i))*countlist[i]
            
            if j>i:
                subing+=(2**(39-j))*max(countlist[j],n-countlist[j])
        ans=max(ans,subing)
    print(ans)
elif k==0:
    ans=0
    for i in range(40):
        ans+=(2**(39-i))*countlist[i]
    print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
Chlist=[0]*n
countlist=[0]*40
for s in range(n):
    Chlist[s]=format(lists[s],’0%ib’%40)
    for i in range(40):
        if Chlist[s][i]=="1":
            countlist[39-i]+=1

#countlistのi桁めが2**(i-1)の数である
power=0
for i in range(40):
    if 2**i<=k<2**(i+1):
        power=i

ans1=0
for j in range(power):
    ans1+=(2**j)*max(countlist[j],n-countlist[j])
ans1+=(2**power)*(countlist[power])


uselist=[0]*(k-2**power+1)
for some in range(k-2**power+1):
    c=format(some,’0%ib’%40)
    uselist[some]=c

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
Chlist=[0]*n
countlist=[0]*40
for s in range(n):
    Chlist[s]=format(lists[s],"0%ib"%40)
    for i in range(40):
        if Chlist[s][i]=="1":
            countlist[39-i]+=1

#countlistのi桁めが2**(i-1)の数である
power=0
for i in range(40):
    if 2**i<=k<2**(i+1):
        power=i

ans1=0
for j in range(power):
    ans1+=(2**j)*max(countlist[j],n-countlist[j])
ans1+=(2**power)*(countlist[power])


uselist=[0]*(k-2**power+1)
for some in range(k-2**power+1):
    c=format(some,’0%ib’%40)
    uselist[some]=c

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
Chlist=[0]*n
countlist=[0]*40
for s in range(n):
    Chlist[s]=format(lists[s],"0%ib"%40)
    for i in range(40):
        if Chlist[s][i]=="1":
            countlist[39-i]+=1

#countlistのi桁めが2**(i-1)の数である
power=0
for i in range(40):
    if 2**i<=k<2**(i+1):
        power=i

ans1=0
for j in range(power):
    ans1+=(2**j)*max(countlist[j],n-countlist[j])
ans1+=(2**power)*(countlist[power])


uselist=[0]*(k-2**power+1)
for some in range(k-2**power+1):
    c=format(some,“0%ib"%40)
    uselist[some]=c

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
Chlist=[0]*n
countlist=[0]*40
for s in range(n):
    Chlist[s]=format(lists[s],"0%ib"%40)
    for i in range(40):
        if Chlist[s][i]=="1":
            countlist[39-i]+=1

#countlistのi桁めが2**(i-1)の数である
power=0
for i in range(40):
    if 2**i<=k<2**(i+1):
        power=i
        break       
ans1=0
for j in range(power):
    ans1+=(2**j)*max(countlist[j],n-countlist[j])
ans1+=(2**power)*(countlist[power])


uselist=[0]*(k-2**power+1)
for i in range(k-2**power+1):
    c=format(i,"0%ib"%40)
    uselist[i]=c


ans2=0

ans2+=(2**power)*(n-countlist[power])

biggest=0
for i in uselist:
    big=0
    for j in range(40):
        if  i[39-j]=="1" and j!=power:
            big+=(2**j)*(n-countlist[j])
        elif i[39-j]=="0"and j!=power:
            big+=(2**j)*countlist[j]
    biggest=max(biggest,big)

ans2+=biggest
print(max(ans1,ans2))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
Chlist=[0]*n
countlist=[0]*40
for s in range(n):
    Chlist[s]=format(lists[s],"0%ib"%40)
    for i in range(40):
        if Chlist[s][i]=="1":
            countlist[39-i]+=1

#countlistのi桁めが2**(i-1)の数である
power=0
for i in range(40):
    if 2**i<=k<2**(i+1):
        power=i
ans1=0
for j in range(power):
    ans1+=(2**j)*max(countlist[j],n-countlist[j])
ans1+=(2**power)*(countlist[power])


uselist=[0]*(k-2**power+1)
for some in range(k-2**power+1):
    c=format(some,“0%ib"%40)
    uselist[some]=c


ans2=0

ans2+=(2**power)*(n-countlist[power])

biggest=0
big=0
for i in uselist:
    for j in range(40):
        if  i[39-j]=="1" and j!=power:
            big+=(2**j)*(n-countlist[j])
        elif i[39-j]=="0"and j!=power:
            big+=(2**j)*countlist[j]
    biggest=max(biggest,big)
    big=0


ans2+=biggest
print(max(ans1,ans2))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
Chlist=[0]*n
countlist=[0]*40
for s in range(n):
    Chlist[s]=format(lists[s],"0%ib"%40)
    for i in range(40):
        if Chlist[s][i]=="1":
            countlist[39-i]+=1
        else:
          continue
        
        
        
#countlistのi桁めが2**(i-1)の数である
power=0
for i in range(40):
    if 2**i<=k<2**(i+1):
        power=i
        break    
    else:
      continue
ans1=0
for j in range(power):
    ans1+=(2**j)*max(countlist[j],n-countlist[j])
ans1+=(2**power)*(countlist[power])


uselist=[0]*(k-2**power+1)
for i in range(k-2**power+1):
    c=format(i,"0%ib"%40)
    uselist[i]=c


ans2=0

ans2+=(2**power)*(n-countlist[power])

biggest=0
for i in uselist:
    big=0
    for j in range(40):
        if  i[39-j]=="1" and j!=power:
            big+=(2**j)*(n-countlist[j])
        elif i[39-j]=="0"and j!=power:
            big+=(2**j)*countlist[j]
    biggest=max(biggest,big)

ans2+=biggest
print(max(ans1,ans2))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
Chlist=[0]*n
countlist=[0]*40
for s in range(n):
    Chlist[s]=format(lists[s],"0%ib"%40)
    for i in range(40):
        if Chlist[s][i]=="1":
            countlist[39-i]+=1

#countlistのi桁めが2**(i-1)の数である
power=0
for i in range(40):
    if 2**i<=k<2**(i+1):
        power=i
        break       
ans1=0
for j in range(power):
    ans1+=(2**j)*max(countlist[j],n-countlist[j])
ans1+=(2**power)*(countlist[power])


uselist=[0]*(k-2**power+1)
for i in range(k-2**power+1):
    c=format(i,"0%ib"%40)
    uselist[i]=c


ans2=0

ans2+=(2**power)*(n-countlist[power])

biggest=0
for i in uselist:
    big=0
    for j in range(40):
        if  i[39-j]=="1" and j!=power:
            big+=(2**j)*(n-countlist[j])
        elif i[39-j]=="0"and j!=power:
            big+=(2**j)*countlist[j]
    biggest=max(biggest,big)

ans2+=biggest
print(max(ans1,ans2))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
a=max(max(lists),k)
length=len(format(a,"b"))

uselists=[0]*length
for some in lists:
    check=format(some,"0%ib"%length)
    for i in range(length):
        if check[i]=="1":
            uselists[length-1-i]+=1       
if k>=1:
    power=0
    for j in range(41):
        if pow(2,j)<=k<pow(2,j+1):
            power=j
            break

        
    fixedlists=[0]*(k-2**power+1)
    for i in range(k-2**power+1):
        fixedlists[i]=format(i,"0%ib"%power)
    #uselistsの左からpower桁文は自由に動かすことができるがpower+1桁めを動かすことになると左からpower桁分の操作範囲は0からk-2**powerの分にまで現象
    ans1=0
    for i in range(power):
        #i=0,1,2,3,.....power-1
        ans1+=(2**i)*max(n-uselists[i],uselists[i])
    ans1+=(2**power)*uselists[power]

    ans2=0
    ans2+=(2**power)*(n-uselists[power])
    checklists=[0]*(k-2**power+1)
    for i in range(k-2**power+1):
        some=fixedlists[i]
        ch=0
        for j in range(power):
            if some[j]=="1":
                ch+=(2**j)*(n-uselists[j])
            elif some[j]=="0":
                ch+=(2**j)*(uselists[j])    
        checklists[i]=ch
    
    chmax=max(checklists)
    ans2+=chmax
    print(max(ans1,ans2))
else:
    print(10**12)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
a=max(max(lists),k)
length=len(format(a,"b"))

uselists=[0]*length
for some in lists:
    check=format(some,"0%ib"%length)
    for i in range(length):
        if check[i]=="1":
            uselists[length-1-i]+=1       
            

if k>=1:
    order=0
    for i in range(40):
        if  2**i<=k<2**(i+1):
            order=i
            break  
            
    fixedlists=[0]*(k-2**order+1)
    for g in range(0,k-2**order+1):
        fixedlists[g]=format(g,"0%ib"%order)
        
    ans1=0
    ans2=0
    for j in range(order):
        ans1+=(2**j)*max(uselists[j],n-uselists[j])       
    for j in range(order+1,length):
        ans2+=(2**j)*uselists[j]
    ans2+=(2**order)*(n-uselists[order])
    bigger=0
    for g in range(0,k-2**order+1):
        some=fixedlists[g]
        checker=0
        for i in range(order):
            if some[i]=="1":
                checker+=(2**(order-1-i))*(n-uselists[i])
            else:
                checker+=(2**(order-1-i))*uselists[i]
                
        bigger=max(bigger,checker)  
        
    ans2=ans2+bigger
    print(max(ans1,ans2))
elif k==0:
    print(10**12)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
a=format(k,"b")
length=max(len(a),len(format(max(lists),"b")))
fixedlists=[0]*n
uselists=[0]*length
for some in lists:
    check=format(some,"0%ib"%length)

    for i in range(length):
        if check[i]=="1":
            uselists[length-1-i]+=1         
if k>=1:
    order=0
    for i in range(length):
        if  2**i<=k<2**(i+1):
            order=i
            break  
            
    fixedlists=[0]*(k-2**order+1)
    for g in range(0,k-2**order+1):
        fixedlists[g]=format(g,"0%ib"%order)
        
    ans1=0
    ans2=0
    for j in range(order):
        ans1+=(2**j)*max(uselists[j],n-uselists[j])
        
    for j in range(order+1,length):
        ans2+=(2**j)*uselists[j]
    ans2+=(2**order)*(n-uselists[order])
    bigger=0
    for g in range(0,k-2**order+1):
        some=fixedlists[g]
        checker=0
        for i in range(order):
            if some[i]=="1":
                checker+=(2**(order-1-i))*(n-uselists[i])
            else:
                checker+=(2**(order-1-i))*uselists[i]
                
        bigger=max(bigger,checker)  
        
    ans2=ans2+bigger
    print(max(ans1,ans2))
elif k==0:
    print(1)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
a=format(k,"b")
length=max(len(a),len(format(max(lists),"b")))
fixedlists=[0]*n
uselists=[0]*length
for some in lists:
    check=format(some,"0%ib"%length)

    for i in range(length):
        if check[i]=="1":
            uselists[length-1-i]+=1         
if k>=1:
    order=0
    for i in range(length):
        if  2**i<=k<2**(i+1):
            order=i
            break  
            
    fixedlists=[0]*(k-2**order+1)
    for g in range(0,k-2**order+1):
        fixedlists[g]=format(g,"0%ib"%order)
        
    ans1=0
    ans2=0
    for j in range(order):
        ans1+=(2**j)*max(uselists[j],n-uselists[j])
        
    for j in range(order+1,length):
        ans2+=(2**j)*uselists[j]
    ans2+=(2**order)*(n-uselists[order])
    bigger=0
    for g in range(0,k-2**order+1):
        some=fixedlists[g]
        checker=0
        for i in range(order):
            if some[i]=="1":
                checker+=(2**(order-1-i))*(n-uselists[i])
            else:
                checker+=(2**(order-1-i))*uselists[i]
                
        bigger=max(bigger,checker)  
        
    ans2=ans2+bigger
    print(max(ans1,ans2))
    
elif k==0:
    ans=0
    for i in range(length):
        if uselists[i]=="1":
            ans+=(2**i)*(n-uselists[i])
        else:
            ans+=(2**i)*uselists[i]     
    print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
a=format(k,"b")
length=max(len(a),len(format(max(lists),"b")))
uselists=[0]*length
for some in lists:
    check=format(some,"0%ib"%length)
    for i in range(length):
        if check[i]=="1":
            uselists[length-1-i]+=1         
if k>=1:
    order=0
    for i in range(length):
        if  2**i<=k<2**(i+1):
            order=i
            break            
    ans1=0
    ans2=0
    for j in range(order):
        ans1+=(2**j)*max(uselists[j],n-uselists[j])
        
    for j in range(order+1,length):
        ans2+=(2**j)*uselists[j]
    ans2+=(2**order)*(n-uselists[order])
    bigger=0
    newlist=[0]*(k-2**order+1)
    for g in range(0,k-2**order+1):
        some=format(g,"0%ib"%order)
        newlist[g]=some
    for some in newlist:
        checker=0
        for i in range(order):
            if some[i]=="1":
                checker+=(2**(order-1-i))*(n-uselists[i])
            else:
                checker+=(2**(order-1-i))*uselists[i]
        bigger=max(bigger,checker)  
    ans2=ans2+bigger
    print(max(ans1,ans2))
    
elif k==0:
    ans=0
    for i in range(length):
        if uselists[i]=="1":
            ans+=(2**i)*(n-uselists[i])
        else:
            ans+=(2**i)*uselists[i]     
    print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lists=list(map(int,input().split()))
a=format(k,"b")
length=max(len(a),len(format(max(lists),"b")))
uselists=[0]*length
for some in lists:
    check=format(some,"0%ib"%length)
    for i in range(length):
        if check[i]=="1":
            uselists[length-1-i]+=1         
if k>=1:
  	order=0
    for i in range(length):
        if  2**i<=k<2**(i+1):
            order=i
            break            
    ans1=0
    ans2=0
    for j in range(order):
        ans1+=(2**j)*max(uselists[j],n-uselists[j])
        
    for j in range(order+1,length):
        ans2+=(2**j)*uselists[j]
    ans2+=(2**order)*(n-uselists[order])
    bigger=0
    newlist=[0]*(k-2**order+1)
    for g in range(0,k-2**order+1):
        some=format(g,"0%ib"%order)
        newlist[g]=some
    for some in newlist:
        checker=0
        for i in range(order):
            if some[i]=="1":
                checker+=(2**(order-1-i))*(n-uselists[i])
            else:
                checker+=(2**(order-1-i))*uselists[i]
        bigger=max(bigger,checker)  
    ans2=ans2+bigger
    print(max(ans1,ans2))
    
elif k==0:
    ans=0
    for i in range(length):
        if uselists[i]=="1":
            ans+=(2**i)*(n-uselists[i])
        else:
            ans+=(2**i)*uselists[i]     
    print(ans)

Buggy submission (verdict: Runtime Error):
#D-XXOR

n,k=map(int,input().split())
lists=list(map(int,input().split()))
a=format(k,"b")
length=max(len(a),len(format(max(lists),"b")))
uselists=[0]*length
for some in lists:
    check=format(some,"0%ib"%length)
    for i in range(length):
        if check[i]=="1":
            uselists[length-1-i]+=1         
if k>=1:
    for i in range(length):
        if  2**i<=k<2**(i+1):
            order=i
            break            
    ans1=0
    ans2=0
    for j in range(order):
        ans1+=(2**j)*max(uselists[j],n-uselists[j])
    for j in range(order+1,length):
        ans2+=(2**j)*uselists[j]
    ans2+=(2**order)*(n-uselists[order])
    bigger=0
    newlist=[0]*(k-2**order+1)
    for g in range(0,k-2**order+1):
        some=format(g,"0%ib"%order)
        newlist[g]=some
    for some in newlist:
        checker=0
        for i in range(order):
            if some[i]=="1":
                checker+=(2**(order-1-i))*(n-uselists[i])
            else:
                checker+=(2**(order-1-i))*uselists[i]
        bigger=max(bigger,checker)  
    ans2=ans2+bigger
    print(max(ans1,ans2))
    
elif k==0:
    ans=0
    for i in range(length):
        if uselists[i]=="1":
            ans+=(2**i)*(n-uselists[i])
        else:
            ans+=(2**i)*uselists[i]     
    print(ans)

Buggy submission (verdict: Runtime Error):
#D-XXOR

n,k=map(int,input().split())
lists=list(map(int,input().split()))
a=format(k,"b")
length=max(len(a),len(format(max(lists),"b")))
uselists=[0]*length
for some in lists:
    check=format(some,"0%ib"%length)
    for i in range(length):
        if check[i]=="1":
            uselists[length-1-i]+=1         
if k>=1:
    for i in range(length):
        if  2**i<=k<2**(i+1):
            order=i
            break            
    ans1=0
    
    ans2=0
    for j in range(order):
        ans1+=(2**j)*max(uselists[j],n-uselists[j])
    for j in range(order+1,length):
        ans2+=(2**j)*uselists[j]
        
    ans2+=(2**order)*(n-uselists[order])
    bigger=0
    listss=[0]*(k-2**order+1)
    for g in range(0,k-2**order+1):
        some=format(g,"0%ib"%order)
        listss[g]=some

    for some in listss:
        checker=0
        for i in range(order):
            if some[i]=="1":
                checker+=(2**(order-1-i))*(n-uselists[i])
            else:
                checker+=(2**(order-1-i))*uselists[i]
        bigger=max(bigger,checker)
    ans2=ans2+bigger

    print(max(ans1,ans2))
    
elif k==0:
    ans=0
    for i in range(length):
        if uselists[i]=="1":
            ans+=(2**i)*(n-uselists[i])
        else:
            ans+=(2**i)*uselists[i]
            
    print(ans)