Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02887 (python)

Fixed submission:
n=int(input())
s=input()
if n==1:
    print(1)
else:
    slist=[]
    for i in range(len(s)):
        slist.append(s[i])
    
    for i in range(len(s)-1,0,-1):
        if slist[i-1]==slist[i]:
            del slist[i]

    print(len(slist))

Buggy submission (verdict: Runtime Error):
def slime(slist,t):
    if len(slist)==1:
        if len(t)==0:
            return slist[0]
        elif slist[0]==t[0]:
            return t
        else:
#            t.append(slist[0])
            t.insert(0,slist[0])
        return t
    else:
        if slist[0]==slist[1]:
            del slist[0]
        else:
#            t.append(slist[0])
            t.insert(0,slist[0])
            del slist[0]
        return slime(slist,t)
        


n=int(input())
s=input()
slist=[]
t=[]

for i in range(len(s)):
    slist.append(s[i])
    
t=slime(slist,t)
print(len(t))
Problem p02918 (python)

Fixed submission:
import sys

n,k=map(int,input().split())
s=input()

lcnt=-1
rcnt=-1

rr=[0]*n
ll=[0]*n
sim=""
for si in s:
    if si=="R" and sim=="R":
        rr[rcnt]+=1
    elif si=="R" and sim!="R":
        rcnt+=1
        rr[rcnt]=1
    if si=="L" and sim=="L":
        ll[lcnt]+=1
    elif si=="L" and sim!="L":
        lcnt+=1
        ll[lcnt]=1
    sim=si
        
ll=[i for i in ll if i!=0]
rr=[i for i in rr if i!=0]
#print(ll)
#print(rr)

minlen=min(len(ll),len(rr))
if minlen<=k:
    print(n-1)
    sys.exit()
    
for i in range(k):
    ll[i]+=rr[i]
    rr[i]=0

for i in range(len(ll)-1):
    if i<len(rr) and ll[i]!=0 and rr[i]==0 :
        ll[i+1]+=ll[i]
        ll[i]=0

icnt=0
for i in range(len(ll)):
    icnt+=max(ll[i]-1,0)
for i in range(len(rr)):
    icnt+=max(rr[i]-1,0)
    
print(icnt)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
s=input()

lcnt=-1
rcnt=-1

rr=[0]*n
ll=[0]*n
sim=""
for si in s:
    if si=="R" and sim=="R":
        rr[rcnt]+=1
    elif si=="R" and sim!="R":
        rcnt+=1
        rr[rcnt]=1
    if si=="L" and sim=="L":
        ll[lcnt]+=1
    elif si=="L" and sim!="L":
        lcnt+=1
        ll[lcnt]=1
    sim=si
        

ll=[i for i in ll if i!=0]
rr=[i for i in rr if i!=0]
#print(ll)
#print(rr)

maxlen=max(len(ll),len(rr))
if maxlen<=k:
    print(n-1)
    sys.exit()
    
for i in range(k):
    ll[i]+=rr[i]
    rr[i]=0

for i in range(maxlen-1):
    if ll[i]!=0 and rr[i]==0 :
        ll[i+1]+=ll[i]
        ll[i]=0

icnt=0
for i in range(len(ll)):
    icnt+=max(ll[i]-1,0)
for i in range(len(rr)):
    icnt+=max(rr[i]-1,0)
    
print(icnt)

Buggy submission (verdict: Runtime Error):
import sys

n,k=map(int,input().split())
#s=list(map(int,input().split()))
s=input()

lcnt=-1
rcnt=-1

rr=[0]*n
ll=[0]*n
sim=""
for si in s:
#    print(si)
    if si=="R" and sim=="R":
        rr[rcnt]+=1
    elif si=="R" and sim!="R":
        rcnt+=1
        rr[rcnt]=1
    if si=="L" and sim=="L":
        ll[lcnt]+=1
    elif si=="L" and sim!="L":
        lcnt+=1
        ll[lcnt]=1
    sim=si
        

ll=[i for i in ll if i!=0]
rr=[i for i in rr if i!=0]
#print(ll)
#print(rr)

maxlen=max(len(ll),len(rr))
if maxlen<=k:
    print(n-1)
    sys.exit()
    
for i in range(k):
    ll[i]+=rr[i]
    rr[i]=0
#print(lr)
for i in range(maxlen-1):
    if ll[i]!=0 and rr[i]==0 :
        ll[i+1]+=ll[i]
        ll[i]=0
#print(lr)

icnt=0
for i in range(maxlen):
    icnt+=max(ll[i]-1,0)+max(rr[i]-1,0)
    
print(icnt)
Problem p02971 (python)

Fixed submission:
n=int(input())
imax=0
amax=0
amax2=amax
for i in range(n):
    ai=int(input())
    if amax<ai:
        adummy=amax
        amax=ai
        imax=i
        amax2=adummy
    elif amax2<ai:
        amax2=ai
if imax==0:
    print(amax2)
    for i in range(1,n):
        print(amax)
elif imax==n-1:
    for i in range(n-1):
        print(amax)
    print(amax2)
else:
    for i in range(imax):
        print(amax)
    print(amax2)
    for i in range(n-imax-1):
        print(amax)

Buggy submission (verdict: Runtime Error):
n=int(input())
imax=0
amax=int(input())
amax2=amax
for i in range(1,n)
    ai=int(input())
    if amax<ai:
        amax=ai
        imax=i
        if amax2<ai:
          amax2=ai
    elif amax2<ai:
        amax2=ai
if imax==0:
    print(amax2)
    for i in range(1,n):
        print(amax)
elif imax==n-1:
    for i in range(n-1):
        print(amax)
    print(amax2)
else:
    for i in range(imax):
        print(amax)
    print(amax2)
    for i in range(n-imax-1):
    print(amax)
Problem p02973 (python)

Fixed submission:
from bisect import bisect

icase=1
if icase==1:
    n=int(input())
    a=[0]*n
    for i in range(n):
        a[i]=-int(input())
elif icase==2:
    n=5
    a=[-2,-1,-4,-5,-3]
elif icase==3:
    n=4
    a=[0,0,0,0]

def loopa():

    n=len(a)
    dp = [10**10]*(n+1)
    dp[0] = -10**10
    
    for i in range(n):
#        idx = bisect(dp, a[i]-1)
        idx = bisect(dp, a[i])
        dp[idx] = min(a[i], dp[idx])

#        print("i:",i,"a:",a,"dp2:",dp2)            
    return dp

dp=loopa()        

print(bisect(dp, 10**10-1)-1)

Buggy submission (verdict: Runtime Error):
from bisect import bisect

icase=1
if icase==1:
    n=int(input())
    a=[0]*n
    for i in range(n):
        a[i]=-int(input())
elif icase==2:
    n=5
    a=[-2,-1,-4,-5,-3]
elif icase==3:
    n=4
    a=[0,0,0,0]

def loopa():

    n=len(a)
    dp = [10**10]*(n+1)
    dp[0] = -10**10
    
    print(n,a,dp)
    for i in range(n):
#        idx = bisect(dp, a[i]-1)
        idx = bisect(dp, a[i])
        dp[idx] = min(a[i], dp[idx])
        print(i,idx,dp)

#        print("i:",i,"a:",a,"dp2:",dp2)            
    return dp

dp=loopa()        

print(bisect(dp, 10**10-1)-1)

Buggy submission (verdict: Runtime Error):
from bisect import bisect

n=int(input())
a=[0]*n
for i in range(n):
   a[i]=int(input())

def loopa():

    n=len(a)
    dp = [10**10]*(n+1)
    dp[0] = -1
    dq = [0]*(n+1)    
    
#    print(n,a,dp)
    for i in range(n):
        idx = bisect(dp, a[i]-1)
        if dp[idx]==10**10:
#            dp[idx] = min(a[i], dp[idx])
            if dp[idx]>a[i]:
                dp[idx]=a[i]
                dq[idx]=i
            dp2=dp[1:idx+1]
            dq2=dq[1:idx+1]
        else:
#            dp[idx] = min(a[i], dp[idx])
            if dp[idx]>a[i]:
                dp[idx]=a[i]
                dq[idx]=i

    for i in range(len(dq2)-1,-1,-1):
        del a[dq2[i]]
#        print("i:",i,"a:",a,"dp2:",dp2)            

icnt=0
while len(a)>0:
    loopa()        
    icnt+=1

print(icnt)
Problem p03001 (python)

Fixed submission:
w,h,x,y=map(int,input().split())

if w/2==x and h/2==y:
    print(0.5*h*w,1)
else:
    print(0.5*h*w,0)

Buggy submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())

w2=w//2
h2=h//2

s1=h*w2
s2=w*h2
err1=(s1-s2)/s1
if -1.0*10**(-9)<err1 and err1<1.0*10**(-9):
    print(s1,1)
elif s1>s2:
    print(s1,0)
else:
    print(s2,0)

Buggy submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())

w2=w//2
h2=h//2

s1=h*w2
s2=w*h2
err1=(s1-s2)/s1
if -1.0*10**(-9)<err1<1.0*10**(-9):
    print(s1,1)
elif s1>s2:
    print(s1,0)
else:
    print(s2,0)
Problem p03032 (python)

Fixed submission:
import sys

n,k0=map(int,input().split())
v=list(map(int,input().split()))

k=k0
if n<=k:
    v.sort()
    vsum=sum(v)
    kk=k-n
    vsum=0
    for i in range(n):
        if i>kk:
            vsum+=v[i]
        elif i<=kk and v[i]>0:
            vsum+=v[i]
    print(max(0,vsum))
    sys.exit()

vmax=-10**10

kk=k0
for k in range(kk):
    k2=kk-k-1
    
    vv=[[0]*(k+1) for i in range(k+1+1)]
    for i in range(k+1):
        vv[0][i]=v[n-k+i-1]
    vsum=sum(vv[0])
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)
#    print(vv[0])
    vvv=vv[0].copy()
    vvv.sort()
    for i in range(min(k2,k+1)):
        if vvv[i]<0:
            vsum-=vvv[i]
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)

    for i in range(k+1):
        vv[i+1]=vv[i].copy()
        vv[i+1].pop(0)
        vv[i+1].append(v[i])
        vsum=sum(vv[i+1])
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
#        print(vv[i+1])
        vvv=vv[i+1].copy()
        vvv.sort()
        for i in range(min(k2,k+1)):
            if vvv[i]<0:
                vsum-=vvv[i]
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
    
print(max(0,vmax))

Buggy submission (verdict: Runtime Error):

import sys

n,k=map(int,input().split())
v=list(map(int,input().split()))

k=k0
if n<=k:
    v.sort()
    vsum=sum(v)
    kk=k-n
    vsum=0
    for i in range(n):
        if i>kk:
            vsum+=v[i]
        elif i<=kk and v[i]>0:
            vsum+=v[i]
    print(max(0,vsum))
    sys.exit()

vmax=-10**10

kk=k0
for k in range(kk):
    k2=kk-k-1
    
    vv=[[0]*(k+1) for i in range(k+1+1)]
    for i in range(k+1):
        vv[0][i]=v[n-k+i-1]
    vsum=sum(vv[0])
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)
#    print(vv[0])
    vvv=vv[0].copy()
    vvv.sort()
    for i in range(min(k2,k+1)):
        if vvv[i]<0:
            vsum-=vvv[i]
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)

    for i in range(k+1):
        vv[i+1]=vv[i].copy()
        vv[i+1].pop(0)
        vv[i+1].append(v[i])
        vsum=sum(vv[i+1])
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
#        print(vv[i+1])
        vvv=vv[i+1].copy()
        vvv.sort()
        for i in range(min(k2,k+1)):
            if vvv[i]<0:
                vsum-=vvv[i]
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
    
print(max(0,vmax))
Problem p03062 (python)

Fixed submission:
from bisect import bisect_left,bisect,bisect_right
import sys

icase=0
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))

a.sort()
ii=bisect(a,0)

if ii==n:
    if ii%2==0:
        asum=-sum(a)
    else:    
        asum=-sum(a[0:ii-1])+a[ii-1]
    print(asum)
    sys.exit()

if ii%2==0:
    asum=-sum(a[0:ii])+sum(a[ii:])
else:
    if -a[ii-1]<a[ii]:
        d=a[ii-1]+a[ii]
    else:
        d=-a[ii-1]-a[ii]
    asum=-sum(a[0:ii-1])+d+sum(a[ii+1:])

print(asum)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left,bisect,bisect_right
import sys

icase=1
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))

a.sort()
ii=bisect(a,0)

if ii==n:
    if ii%2==0:
        asum=-sum(a)
    else:    
        asum=-sum(a[0:ii-1])+a[ii-1]
    print(asum)
    sys.exit()

if ii%2==0:
    asum=-sum(a[0:ii])+sum(a[ii:])
else:
    if -a[ii-1]<a[ii]:
        d=a[ii-1]+a[ii]
    else:
        d=-a[ii-1]-a[ii]
    asum=-sum(a[0:ii-1])+d+sum(a[ii+1:])

print(asum)
Problem p03078 (python)

Fixed submission:
icase=0
if icase==0:
    x,y,z,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    c=list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

kk=1

ix=0
iy=0
iz=0
ss=[]
s=a[ix]+b[iy]+c[iz]

xyz=[]
xyz.append((ix+1,iy,iz))
xyz.append((ix,iy+1,iz))
xyz.append((ix,iy,iz+1))

#print(ix,iy,iz,s)
#print(xyz)
ss.append(s)
while kk<k:
    kk+=1
    s1=0
    for ix,iy,iz in xyz:
        s2=a[ix]+b[iy]+c[iz]
        if s2>s1:
            s1=s2
            ixx,iyy,izz=ix,iy,iz
#    print("1:",ixx,iyy,izz,s2)
    xyz.remove((ixx,iyy,izz))
    if ixx<x-1 and ((ixx+1,iyy,izz) not in xyz): 
        xyz.append((ixx+1,iyy,izz))
    if iyy<y-1 and ((ixx,iyy+1,izz) not in xyz): 
        xyz.append((ixx,iyy+1,izz))
    if izz<z-1 and ((ixx,iyy,izz+1) not in xyz): 
        xyz.append((ixx,iyy,izz+1))
#    print(ixx,iyy,izz,s1)
#    print(xyz)
    ss.append(s1)

for kk in range(k):
    print(ss[kk])

Buggy submission (verdict: Runtime Error):
icase=3
if icase==0:
    x,y,z,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    c=list(map(int,input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

kk=1

ix=0
iy=0
iz=0
ss=[]
s=a[ix]+b[iy]+c[iz]

xyz=[]
xyz.append((ix+1,iy,iz))
xyz.append((ix,iy+1,iz))
xyz.append((ix,iy,iz+1))

#print(ix,iy,iz,s)
#print(xyz)
ss.append(s)
while kk<k:
    kk+=1
    s1=0
    for ix,iy,iz in xyz:
        s2=a[ix]+b[iy]+c[iz]
        if s2>s1:
            s1=s2
            ixx,iyy,izz=ix,iy,iz
#    print("1:",ixx,iyy,izz,s2)
    xyz.remove((ixx,iyy,izz))
    if ixx<x-1 and ((ixx+1,iyy,izz) not in xyz): 
        xyz.append((ixx+1,iyy,izz))
    if iyy<y-1 and ((ixx,iyy+1,izz) not in xyz): 
        xyz.append((ixx,iyy+1,izz))
    if izz<z-1 and ((ixx,iyy,izz+1) not in xyz): 
        xyz.append((ixx,iyy,izz+1))
#    print(ixx,iyy,izz,s1)
#    print(xyz)
    ss.append(s1)

for kk in range(k):
    print(ss[kk])
Problem p03087 (python)

Fixed submission:
n,q=map(int,input().split())
s=input()
cnt=[0]*n
icnt=0
for i in range(n-1):
#    print(s[i:i+2])
    if s[i:i+2]=="AC":
      icnt=icnt+1
      cnt[i+1]=cnt[i]+1
    else:
      cnt[i+1]=cnt[i]
#print(cnt,s)
for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri-1]-cnt[li-1])

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
cnt=[0]*n
for i in range(n-1):
    if s[i:i+1]=="AC":
      cnt[i+1]=cnt[i]+1
#    else:
#      cnt[i+1]=cnt[i]

for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri]-cnt[li])

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()
cnt=[]
for i in range(n-1):
    if s[i:i+1]=="AC":
      cnt.append(1)
    else:
      cnt.append(0)

for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
    print(cnt[li-1:ri-1].sum())
Problem p03103 (python)

Fixed submission:
n,m=map(int,input().split())
ab=[]
for i in range(n):
    abi=list(map(int,input().split()))
    ab.append(abi)
ab.sort()
msum=0
asum=0
for i in range(n):
    ai,bi=ab[i]
    asum=asum+ai*bi
    msum=msum+bi  
    if msum>=m:
        break
asum=asum-ai*(msum-m)
print(asum)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
b=[]
ai,bi=map(int,input().split())
a.append(ai)
b.append(bi)
for i in range(1:n):
    ai,bi=map(int,input().split())
    for ii in range(i-1):
        if ai<a[ii]:
            a.insert(ii,ai)
            b.insert(ii,bi)
            break
    if len(a)==i-1:
        a.append(ai)
        b.append(bi)
#print(ai)
msum=0
asum=0
for i in range(n):
    asum=asum+a[i]*b[i]
    msum=msum+b[i]  
    if msum>=m:
        break
asum=asum-a[i]*(msum-m)
print(asum)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
    for ii in range(i-1):
        if ai<a[ii]:
            a.insert(ii)=ai
            b.insert(ii)=bi
            break
        else:
            a.append(ai)
            b.append(bi)
print(ai)
Problem p03111 (python)

Fixed submission:
l=[]
n,a,b,c=map(int,input().split())
for i in range(n):
    li=int(input())
    l.append(li)

d=[a,b,c]
d.sort()

mpmin=sum(l)*4+len(l)*10+sum(d)
for i in range(4**n):
    k=[]
    kj=i%4
    k.append(kj)
    b=int((i-kj)/4)
    l0=[]
    l1=[]
    l2=[]
    l3=[]
    if kj==0:
        l0.append(l[0])
    elif kj==1:
        l1.append(l[0])
    elif kj==2:
        l2.append(l[0])
    elif kj==3:
        l3.append(l[0])
        
    for j in range(n-1):
        kj=b%4
        k.append(kj)
        b=int((b-kj)/4)
        if kj==0:
            l0.append(l[j+1])
        elif kj==1:
            l1.append(l[j+1])
        elif kj==2:
            l2.append(l[j+1])
        elif kj==3:
            l3.append(l[j+1])
    mp=0
    if len(l0)>=1:
        mp=mp+(len(l0)-1)*10
    if len(l1)>=1:
        mp=mp+(len(l1)-1)*10
    if len(l2)>=1:
        mp=mp+(len(l2)-1)*10
    ls=[]
    ls=[sum(l0),sum(l1),sum(l2)]
    ls.sort()
    mp=mp+abs(d[0]-ls[0])+abs(d[1]-ls[1])+abs(d[2]-ls[2])    
    if mpmin>mp and len(l0)>=1 and len(l1)>=1 and len(l2)>=1:
        mpmin=mp
print(mpmin)

Buggy submission (verdict: Runtime Error):
l=[]

def detain(n,a,b,c,l):
    
    n,a,b,c=map(int,input().split())
    for i in range(n):
        li=int(input())
        l.append(li)
    return


detain(n,a,b,c,l)
d=[a,b,c]
d.sort()

mpmin=sum(l)*4+len(l)*10
for i in range(4**n):
    k=[]
    kj=i%4
    k.append(kj)
    b=int((i-kj)/4)
    l0=[]
    l1=[]
    l2=[]
    l3=[]
    if kj==0:
        l0.append(l[0])
    elif kj==1:
        l1.append(l[0])
    elif kj==2:
        l2.append(l[0])
    elif kj==3:
        l3.append(l[0])
        
    for j in range(n-1):
        kj=b%4
        k.append(kj)
        b=int((b-kj)/4)
        if kj==0:
            l0.append(l[j+1])
        elif kj==1:
            l1.append(l[j+1])
        elif kj==2:
            l2.append(l[j+1])
        elif kj==3:
            l3.append(l[j+1])
    mp=0
    if len(l0)>=1:
        mp=mp+(len(l0)-1)*10
    if len(l1)>=1:
        mp=mp+(len(l1)-1)*10
    if len(l2)>=1:
        mp=mp+(len(l2)-1)*10
    ls=[]
    ls=[sum(l0),sum(l1),sum(l2)]
    ls.sort()
    mp=mp+abs(d[0]-ls[0])+abs(d[1]-ls[1])+abs(d[2]-ls[2])    
    if mpmin>mp and len(l0)>=1 and len(l1)>=1 and len(l2)>=1:
        mpmin=mp
print(mpmin)
Problem p03138 (python)

Fixed submission:
import sys

icase=0
if icase==0:
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
elif icase==1:
    n,k=4,9
    a=[7,4,0,3]
elif icase==2:
    n,k=3,7
    a=[1,6,3]
elif icase==3:
    n,k=1,0
    a=[1000000000000]

if k==0:
    print(sum(a))
    sys.exit()
    
kk=[0]*42
kkk=k
kcnt=0
while kkk>0:
    kk[kcnt]=kkk%2
    kcnt+=1
    kkk=kkk//2
    
f=[0]*42
for ai in a:
    icnt=0
    while ai>0:
        f[icnt]+=ai%2
        ai=ai//2
        icnt+=1

n2=n//2+1
fm=[0]*42

flg1=0
flg2=0
for i in range(41,-1,-1):
    if flg1==0 and kk[i]==0:
        fm[i]=0
    if flg1==0 and kk[i]==1:
        flg1=1
    if flg1==0:
        fm[i]=f[i]        
        continue
#  case : flg1=1
    if kk[i]==1 and f[i]>=n2 and flg2==0:
        flg2=1
    if kk[i]==1 or (kk[i]==0 and flg2==1):
        if f[i]<n2:
            fm[i]=n-f[i]
        else:
            fm[i]=f[i]        
    else:
        fm[i]=f[i]        
    
smax=0
idx=1
for i in range(len(fm)):
    smax+=idx*fm[i]
    idx*=2

print(smax)

Buggy submission (verdict: Runtime Error):

import sys

n,k=map(int,input().split())
a=list(map(int,input().split()))

if k==0:
    print(sum(a))
    sys.exit()
    
kk=[]
kkk=k
kcnt=0
while kkk>0:
    kk.append(kkk%2)
    kcnt+=1
    kkk=kkk//2
#print(kcnt)    
    
f=[0]*kcnt
for ai in a:
    icnt=0
    while ai>0:
        f[icnt]+=ai%2
        ai=ai//2
        icnt+=1

n2=n//2
smax=0
idx=1
for i in range(len(f)):
    if f[i]>n2:
        smax+=idx*f[i]
    else:
        smax+=idx*(n-f[i])
    idx*=2

print(smax)
Problem p03240 (python)

Fixed submission:
def abs(x1,x2):
    if x1>x2:
        return x1-x2
    else:
        return x2-x1
    
n=int(input())
x=[]
y=[]
h=[]

for i in range(n):
    xi,yi,hi=map(int,input().split())
    x.append(xi)
    y.append(yi)
    h.append(hi)

hmax=h[0]
xhmax=x[0]
yhmax=y[0]
ihmax=0

for i in range(n):
    if hmax<h[i]:
        hmax=h[i]
        xhmax=x[i]
        yhmax=y[i]
        ihmax=i
    
for cx in range(101):
    for cy in range(101):
        hh=hmax+abs(xhmax,cx)+abs(yhmax,cy)
        yesno="yes"
        for i in range(n):
            if h[i]!=max(hh-abs(x[i],cx)-abs(y[i],cy),0):
                yesno="no"
                break
        if yesno=="yes":
            print(cx,cy,hh)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=[]
y=[]
h=[]

for i in range(n):
    xi,yi,hi=map(int,input().split())
    x.append(xi)
    y.append(yi)
    h.append(hi)

hmax=h[0]
xhmax=x[0]
yhmax=y[0]
ihmax=0

for i in range(n):
    if hmax<h[i]:
        hmax=h[i]
        xhmax=x[i]
        yhmax=y[i]
        ihmax=i
    
for cx in range(101):
    for cy in range(101):
        hh=hmax+abs(xhmax,cx)+abs(yhmax,cy)
        yesno="yes"
        for i in range(n):
            if h[i]!=max(hh-abs(x[i],cx)-abs(y[i],cy),0):
                yesno="no"
                break
        if yesno=="yes":
            print(cx,cy,hh)
Problem p03262 (python)

Fixed submission:
def gcdf(a):
    a.sort()
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a) 
    
n,x=map(int,input().split())
xi=list(map(int,input().split()))

for i in range(n):
    if xi[i]>x:
        xi[i]=xi[i]-x
    else:
        xi[i]=x-xi[i]
    
gcdx=gcdf(xi)
print(gcdx)

Buggy submission (verdict: Runtime Error):

from functools import reduce
from fanctions import gcd
#from math import gcd

n,x0=map(int,input().split())
x=list(map(int,input().split()))

for i in range(n):
    x[i]=abs(x[i]-x0)

print(reduce(gcd, x))

Buggy submission (verdict: Runtime Error):

from functools import reduce
from math import gcd

n,x0=map(int,input().split())
x=list(map(int,input().split()))

for i in range(n):
    x[i]=abs(x[i]-x0)

print(reduce(gcd, x))
Problem p03282 (python)

Fixed submission:
import math

s=input()
k=int(input())

ss=[]
cont0=0
cont1=0
for i in range(len(s)):
    if s[i]!="1":
        ss.append(int(s[i]))
    else:
        if len(ss)==0:
            cont0=cont0+1
        else:
            cont1=cont1+1
        
k=k-cont0
    
n=5000*10000**3

if len(ss)==0:
    print(1)
elif k<=0:
    print(1)
else:
    logk=math.log10(k)

    logketa=n*math.log10(ss[0])
    if logketa>logk:
        print(ss[0])
    else:
        print(ss[1])

Buggy submission (verdict: Runtime Error):
import math

s=input()
k=int(input())

ss=[]
cont0=0
cont1=0
for i in range(len(s)):
    if s[i]!="1":
        ss.append(int(s[i]))
    else:
        if len(ss)==0:
            cont0=cont0+1
        else:
            cont1=cont1+1
        
k=k-cont0
logk=math.log10(k)
    
n=5000*10000**3

if len(ss)==0:
    print(1)
else:
    logketa=n*math.log10(ss[0])
    if logketa>logk:
        print(ss[0])
    else:
        print(ss[1])

Buggy submission (verdict: Runtime Error):
import math

s=input()
k=int(input())

logk=math.log10(k)

ss=[]
for i in range(len(s)):
    if s[i]!="1":
        ss.append(int(s[i]))
    
n=5000*10000**3

logketa=n*math.log10(ss[0])
if logketa>logk:
    print(ss[0])
else:
    print(ss[1])