Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=sorted(list(map(int,input().split())))
if len(set(l))==3:
  h=sorted(list(set(l)),reverse=1)
  ff=len(bin(h[0]))
  p=["0"*(ff-len(bin(s)))+bin(s)[2:] for s in h]
  y=p[0]
  dfg,dgf=p[1],p[2]
  for i in range(ff-2):
    q,w=dfg[i],dgf[i]
    if (q!=w and y[i]=="0") or (q==w and y[i]=="1"):print("No");exit()
  else:
    from collections import Counter as cou
    if len(set(cou(l).values()))==1:print("Yes")
    else:print("No")
elif len(set(l))>=4 or 0 not in set(l):
  print("No")
elif set(l)==set([0]):
  print("Yes")
else:
  if n%3:print("No");exit()
  from collections import Counter as cou
  fl,fll=0,0
  for g,gh in cou(l).items():
    if g==0 and gh==n//3:fl=1
    if g!=0 and gh==2*n//3:fll=1
  print("Yes" if fl and fll else "No"))

Fixed submission:
n=int(input())
l=sorted(list(map(int,input().split())))
if len(set(l))==3:
  h=sorted(list(set(l)),reverse=1)
  ff=len(bin(h[0]))
  p=["0"*(ff-len(bin(s)))+bin(s)[2:] for s in h]
  y=p[0]
  dfg,dgf=p[1],p[2]
  for i in range(ff-2):
    q,w=dfg[i],dgf[i]
    if (q!=w and y[i]=="0") or (q==w and y[i]=="1"):print("No");exit()
  else:
    from collections import Counter as cou
    if len(set(cou(l).values()))==1:print("Yes")
    else:print("No")
elif len(set(l))>=4 or 0 not in set(l):
  print("No")
elif set(l)==set([0]):
  print("Yes")
else:
  if n%3:print("No");exit()
  from collections import Counter as cou
  fl,fll=0,0
  for g,gh in cou(l).items():
    if g==0 and gh==n//3:fl=1
    if g!=0 and gh==2*n//3:fll=1
  print("Yes" if fl and fll else "No")
Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=0
for i in range(1,n-1):
  p=max(l[i-1],l[i+1])
  q=min(l[i-1],l[i+1])
  if q<=l[i]<=p:ans+=1
print(ans)

Fixed submission:
n=int(input())
ans=0
l=list(map(int,input().split()))
for i in range(1,n-1):
  p=max(l[i-1],l[i+1])
  q=min(l[i-1],l[i+1])
  if q<=l[i]<=p:ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d=map(int,input().split())
print(len([1 for i in range(a,b+1) if i%c and i%d]))

Fixed submission:
a,b,c,d=map(int,input().split())
def gcd(x,y):
  if x==0:
    return y
  else:return gcd(y%x,x)

def f(a,s,d):
  x=s*d//gcd(s,d)
  return a-a//s-a//d+a//x

print(f(b,c,d)-f(a-1,c,d))
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=sorted(list(map(int,input().split())) for nd in range(n),key=lambda x:x[1])
now=0
for a,s in l:
  if a+now>s:print("No");exit()
  now+=a
else:print("Yes")


Fixed submission:
n=int(input())
l=sorted([list(map(int,input().split())) for nd in range(n)],key=lambda x: x[1])
now=0
for a,s in l:
  if a+now>s:print("No");exit()
  now+=a
else:print("Yes")

Buggy python submission (verdict: Runtime Error):
n=int(inuput())
l=sorted(list(map(int,input().split())) for nd in range(n),key=lambda x:x[1])
now=0
for a,s in l:
  if a+now>s:print("No");exit()
  now+=a
else:print("Yes")

Fixed submission:
n=int(input())
l=sorted([list(map(int,input().split())) for nd in range(n)],key=lambda x: x[1])
now=0
for a,s in l:
  if a+now>s:print("No");exit()
  now+=a
else:print("Yes")
Buggy python submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
p=w*h/2
a=1 if w/h==x/y else 0
print(p,a)

Fixed submission:
w,h,x,y=map(int,input().split())
p=w*h/2
a=1 if 2*x==w and 2*y==h else 0
print(p,a)
Buggy python submission (verdict: Runtime Error):
ans=float("INF")
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
if n==1:print(1);exit()
for i in range(n):
    for j in range(n):
        if i==j:continue
        p,q=l[i][0]-l[j][0],l[i][1]-l[j][1]
        ret=0
        pre=sorted(l,reverse=1,key=lambda x:p*x[0]+q*x[1])
        while pre:
            ret+=1
            x,y=pre.pop()
            while  [x+p,y+q] in pre:
                pre.remove([x+p,y+q])
                x,y=[x+p,y+q]
        ans=min(ans,ret)
print(ans)ans=float("INF")
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
if n==1:print(1);exit()
for i in range(n):
    for j in range(n):
        if i==j:continue
        p,q=l[i][0]-l[j][0],l[i][1]-l[j][1]
        ret=0
        pre=sorted(l,reverse=1,key=lambda x:p*x[0]+q*x[1])
        while pre:
            ret+=1
            x,y=pre.pop()
            while  [x+p,y+q] in pre:
                pre.remove([x+p,y+q])
                x,y=[x+p,y+q]
        ans=min(ans,ret)
print(ans)ans=float("INF")
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
if n==1:print(1);exit()
for i in range(n):
    for j in range(n):
        if i==j:continue
        p,q=l[i][0]-l[j][0],l[i][1]-l[j][1]
        ret=0
        pre=sorted(l,reverse=1,key=lambda x:p*x[0]+q*x[1])
        while pre:
            ret+=1
            x,y=pre.pop()
            while  [x+p,y+q] in pre:
                pre.remove([x+p,y+q])
                x,y=[x+p,y+q]
        ans=min(ans,ret)
print(ans)

Fixed submission:
ans=float("INF")
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
if n==1:print(1);exit()
for i in range(n):
    for j in range(n):
        if i==j:continue
        p,q=l[i][0]-l[j][0],l[i][1]-l[j][1]
        ret=0
        pre=sorted(l,reverse=1,key=lambda x:p*x[0]+q*x[1])
        while pre:
            ret+=1
            x,y=pre.pop()
            while  [x+p,y+q] in pre:
                pre.remove([x+p,y+q])
                x,y=[x+p,y+q]
        ans=min(ans,ret)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
p,m=[],[]
z=0
for i in list(map(int,input().split())):
    if i<0:m.append(i)
    elif i==0:
        z+=1
    else:p.append(i)
if p and m:
    print(sum(p)-sum(m))
    if z:
        for h in range(z-1):
            print("0 0")
        now=0
    else:now=p.pop()
    for j in m[1:]:
        print(now,j)
        now-=j
    print(m[0],now)
    now=-now+m[0]
    for j in p[1:]:
        print(now,j)
        now-=j
    print(p[0],now)
elif p:
    if z:
        print(sum(p))
        for h in  range(z-1):
            print("0 0")
        now=0
        f=p.pop()
        for i in p:
            print(now,i)
            now-=i
        print(f,now)
    else:
        print(sum(p)-2*min(p))
        p.sort()
        now=p[0]
        k=p.pop()
        for j in p[1:]:
            print(now,j)
            now-=j
        print(k,now)
else:
    if z:
        print(-sum(m))
        for h in  range(z-1):
            print("0 0")
        now=0
    else:
        m.sort()
        print(-sum(m)+2*max(m))
        now=m.pop()
    for i in p:
        print(now,i)
        now-=i



Fixed submission:
n=int(input())
p,m=[],[]
z=0
for i in list(map(int,input().split())):
    if i<0:m.append(i)
    elif i==0:
        z+=1
    else:p.append(i)
if p and m:
    print(sum(p)-sum(m))
    if z:
        for h in range(z-1):
            print("0 0")
        now=0
    else:now=p.pop()
    for j in m[1:]:
        print(now,j)
        now-=j
    if p:
        print(m[0],now)
        now=-now+m[0]
        for j in p[1:]:
            print(now,j)
            now-=j
        print(p[0],now)
    else:
        print(now,m[0])
elif p:
    if z:
        print(sum(p))
        for h in  range(z-1):
            print("0 0")
        now=0
        f=p.pop()
        for i in p:
            print(now,i)
            now-=i
        print(f,now)
    else:
        print(sum(p)-2*min(p))
        p.sort()
        now=p[0]
        k=p.pop()
        for j in p[1:]:
            print(now,j)
            now-=j
        print(k,now)
else:
    if z:
        print(-sum(m))
        for h in  range(z-1):
            print("0 0")
        now=0
    else:
        m.sort()
        print(-sum(m)+2*max(m))
        now=m.pop()
    for i in m:
        print(now,i)
        now-=i
Buggy python submission (verdict: Runtime Error):
s=list(map(int,input().split()))
print(sum(l)-max(l))

Fixed submission:
l=list(map(int,input().split()))
print(sum(l)-max(l))
Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
s=[input() for ri in range(h)]
table=[0]*(h*w)
for i in range(h):
    p=0
    pre=0
    for j in range(w):
        if s[i][j]=="#":
            if p==0:continue
            for x in range(pre,j):
                table[w*i+x]+=p
            p=0
        else:
            if p==0:
                pre=j
            p+=1
    else:
        if p:
            for x in range(pre,w):table[w*i+x]+=p

for j in range(w):
    p=0
    pre=0
    for i in range(h):
        if s[i][j]=="#":
            if p==0:continue
            for x in range(pre,i):
                table[j+w*x]+=p
            p=0
        else:
            if p==0:pre=i
            p+=1
    else:
        if p:
            for x in range(pre,h):table[j+w*x]+=p
        p=0

print(max(table)-1)

Fixed submission:
h,w=map(int,input().split())
s=[input() for ri in range(h)]
table=[0]*(h*w)
for i in range(h):
    p=0
    pre=0
    for j in range(w):
        if s[i][j]=="#":
            if p==0:continue
            for x in range(pre,j):
                table[w*i+x]+=p
            p=0
        else:
            if p==0:
                pre=j
            p+=1
    else:
        if p:
            for x in range(pre,w):table[w*i+x]+=p

for j in range(w):
    p=0
    pre=0
    for i in range(h):
        if s[i][j]=="#":
            if p==0:continue
            for x in range(pre,i):
                table[j+w*x]+=p
            p=0
        else:
            if p==0:pre=i
            p+=1
    else:
        if p:
            for x in range(pre,h):table[j+w*x]+=p
        p=0

print(max(table)-1)
Buggy python submission (verdict: Time Limit Exceeded):
k,m=map(int,input().split())
ans=set(range(1,k+1))
for i in range(m):
  f=list(map(int,input().split()))
  ans&=set(range(f[0],f[1]+1))
print(len(ans))

Fixed submission:
k,m=map(int,input().split())
l=[0 for i in range(k+1)]
for i in range(m):
  a,s=map(int,input().split())
  l[a-1]+=1;l[s]-=1
ans=0
f=0
for j in range(k):
  l[j]+=f
  f=l[j]
print(len([1 for i in l if i==m]))
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
ans=0
r,g,b=max(r,g,b),r+g+b-max(r,g,b)-min(r,g,b),min(r,g,b)
for i in range(n//r+1):
  for j in range(n//g+1):
    if (n-i*r-j*g)%b or (n-i*r-j*g)<0:
      continue
    ans+=1
print(ans)


Fixed submission:
r,g,b,n=map(int,input().split())
ans=0
r,g,b=max(r,g,b),r+g+b-max(r,g,b)-min(r,g,b),min(r,g,b)
for i in range(n//r+1):
  for j in range(n//g+1):
    if (n-i*r-j*g)%b or (n-i*r-j*g)<0:
      continue
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
d=l.copy()
ans=-float("INF")
for i in range(1,n-1):
    if 0>=d[i]+d[i+1]:
        if d[i]<0:
            d[i]*=-1
            d[i+1]*=-1
        

ans=max(ans,sum(d))
l[0]*=-1
l[1]*=-1
for i in range(1,n-1):
    if 0>=l[i]+l[i+1]:
        if l[i]<0:
            l[i]*=-1
            l[i+1]*=-1
print(max(ans,sum(l)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

    # 要素の絶対値
B = list(map(abs, A))

    # 負の要素の個数
C = [a for a in A if a < 0]
if len(C) % 2 == 0:
  print(sum(B))
else:
        # 最小値を負として計算する
  print(sum(B) - min(B)*2)
Buggy python submission (verdict: Runtime Error):
p,a=1,0
n=input()
for i in list(map(int,input().split())):
  if p<=i:ans+=1
  p=i
print(a)

Fixed submission:
p,a=1,0
n=input()
for i in list(map(int,input().split())):
  if p<=i:a+=1
  p=max(i,p)
print(a)

Buggy python submission (verdict: Runtime Error):
p,a=1,0
n=input()
for i in list(map(int,input().split())):
  if p<=i:ans+=1
  p=i
print(ans)

Fixed submission:
p,a=1,0
n=input()
for i in list(map(int,input().split())):
  if p<=i:a+=1
  p=max(i,p)
print(a)
Buggy python submission (verdict: Runtime Error):
n=input()
s,a="",""
sd,ad=0,0
for i in range(len(n)):
  if i%2:
    s+="1"
    a+="0"
  else:
    s+="0"
    a+="1"
for i in range(n):
  if n[i]!=a[i]:ad+=1
  if n[i]!=s[i]:sd+=1
print(min(ad,sd))

Fixed submission:
n=input()
s=""
a=""
sd,ad=0,0
for i in range(len(n)):
  if i%2:
    s+="1"
    a+="0"
  else:
    s+="0"
    a+="1"
for i in range(len(n)):
  if n[i]!=a[i]:ad+=1
  if n[i]!=s[i]:sd+=1
print(min(ad,sd))
Buggy python submission (verdict: Runtime Error):
l=[int(input()) for i in range(5)]
a,c=min(l),max(l)
k=int(input())
print("Yay!") if (a-b)**2<=k**2 else print(":(")

Fixed submission:
l=[int(input()) for i in range(5)]
a,c=min(l),max(l)
k=int(input())
print("Yay!") if (a-c)**2<=k**2 else print(":(")
Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k=map(int,input().split())
a,b,c=[list(map(int,input().split())) for i in range(3)]
l=sorted([bb+cc for bb in b for cc in c],reverse=1)[:k]
t=sorted([ll+aa for aa in a for ll in l],reverse=1)
for i in range(k):
    print(t[i])

Fixed submission:
x,y,z,k=map(int,input().split())
a,b,c=[list(map(int,input().split())) for i in range(3)]
l=sorted([bb+cc for bb in b for cc in c],reverse=1)[:k]
t=sorted([ll+aa for aa in a for ll in l],reverse=1)
for i in range(k):
    print(t[i])
Buggy python submission (verdict: Runtime Error):
print(input().lower().replace("a","T").replace("t","A")replace("c","G")replace("g","C"))

Fixed submission:
print({"A":"T","T":"A","G":"C","C":"G"}[input()])
Buggy python submission (verdict: Runtime Error):
from math import log2 as log
a,b=map(int,input().split())
r,l=int(log(a))+1,int(log(b))
if a==b:print(a);exit()
ans=pow(2,l)+int(r==1)
for i in range(a,pow(2,r)):
  ans^=i
for i in range(pow(2,l)+1,b+1):
  ans^=i
print(ans)

Fixed submission:
a,b=map(int,input().split())
c,d=0,0
if a!=0:
  a-=1
  m=(-(-a//2))%2
  c=m if a%2 else m^a
m=m=(-(-b//2))%2
d=m if b%2 else m^b
print(c^d)
Buggy python submission (verdict: Runtime Error):
a,s=map(int,input().spit())
if s%a:
  print(s-a)
else:
  print(a+s)

Fixed submission:
a,s=map(int,input().split())
if s%a:
  print(s-a)
else:
  print(a+s)
Buggy python submission (verdict: Runtime Error):
print('YNEOS'[len({*map(int,input().split())for i in range(3)})!=4::2])

Fixed submission:
l=[list(map(int,input().split()))for i in range(3)]
from itertools import permutations as pe
for i in pe(l,r=None):
    #rは長さ、Noneでiteraterの長さ
    for j in range(2):
        now=i[0][j]
        seen=set([now])
        for a,b in i:

            if b!=now and now!=a:break
            now=b+a-now
            seen.add(now)
        else:
            if len(seen)==4:print('YES');exit()

print("NO")
Buggy python submission (verdict: Runtime Error):
a,s=map(int,input().split())
print(a/b)

Fixed submission:
a,s=map(int,input().split())
print(a/s)

Buggy python submission (verdict: Runtime Error):
a,s=input().split()
print(a/s)

Fixed submission:
a,s=map(int,input().split())
print(a/s)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=sorted(list(map(int,input().split())))
s=[]
for i ,x in zip(l,l[1::]):
    s.append(x-i)
ans=l[-1]-l[0]
s.sort()
for i in range(n-1):
    ans-=s[-i-1]
print(ans)

Fixed submission:
koma,spot=map(int,input().split())
if koma>=spot:print(0);exit()
l=list(map(int,input().split()))
l.sort()
k=[l[i+1]-l[i]for i in range(spot-1)]
k.sort()
print(sum(k[:spot-koma]))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[]
c=len(bin(max(l)))-2
for i in range(c):
    a=sum((j>>i)%2 for j in l)
    dp.append([n-a,a])
z=0

for x in range(k+1):
    ans=((x>>c)<<c)*n
    now=1
    for f in range(c):
        ans+=now*dp[f][1-(x>>f)%2]
        now*=2
    z=max(z,ans)
print(z)

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
m=max(l)
table=[[0,0]for i in range(m.bit_length())]
now=0
su=0
cor=1<<(m.bit_length()-1)
for i in range(m.bit_length()):
    p=[0,0]
    for j in range(n):
        p[l[j]%2]+=1
        l[j]//=2
    table[i][0]=p[0]
    table[i][1]=p[1]
if k.bit_length()>m.bit_length():
    now+=k>>m.bit_length()<<m.bit_length()
    su+=now*n
for i in range(m.bit_length()-1,-1,-1):
    p=table[i]
    if p[1]<=p[0] and now+cor<=k:
        su+=p[0]*cor
        now+=cor
    else:
        su+=cor*p[1]
    cor//=2
print(su)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[]
c=len(bin(max(l)))-2
for i in range(c):
    a=sum((j>>i)%2 for j in l)
    dp.append([n-a,a])
z=0

for x in range(k+1):
    ans=((x>>c)<<c)*n
    now=1
    for f in range(c):
        ans+=now*dp[f][1-(x>>f)%2]
        now*=2
    z=max(z,ans)
print(z)

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
m=max(l)
table=[[0,0]for i in range(m.bit_length())]
now=0
su=0
cor=1<<(m.bit_length()-1)
for i in range(m.bit_length()):
    p=[0,0]
    for j in range(n):
        p[l[j]%2]+=1
        l[j]//=2
    table[i][0]=p[0]
    table[i][1]=p[1]
if k.bit_length()>m.bit_length():
    now+=k>>m.bit_length()<<m.bit_length()
    su+=now*n
for i in range(m.bit_length()-1,-1,-1):
    p=table[i]
    if p[1]<=p[0] and now+cor<=k:
        su+=p[0]*cor
        now+=cor
    else:
        su+=cor*p[1]
    cor//=2
print(su)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
dp=[10**4*n]*n
l=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
  dp[i]=min(dp[i-j]+abs(l[i-j]-l[i]) for j in range(1,min(i,k)+1))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
dp=[10**10]*n
h=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,1+min(k,i)))

print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
dp=[10**4*n]*n
l=list(map(int,input().split()))
dp[0]=0
for i in range(n):
  dp[i]=min(dp[j]+abs(l[j]-l[i]) for j in range(min(i,k)))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
dp=[10**10]*n
h=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,1+min(k,i)))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
dp=[10**10]*n
h=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,1+min(k,i)))

print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
dp=[10**10]*n
h=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,1+min(k,i)))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
dp=[float("INF")]*n
h=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,1+min(k,i)))

print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
dp=[10**10]*n
h=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,1+min(k,i)))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[0 for t in range(n)]
if k+1>=n:
  print(abs(l[-1]-l[0]))
  exit()
for i in range(n)[1:]:
  a=float('inf')
  for d in range(min(i,k)+1)[1:]:
    a=min(a,dp[i-d]+abs(l[i]-l[i-d]))
  dp[i]=a
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
dp=[10**10]*n
h=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,1+min(k,i)))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=list(map(int,input().split()))
dp=[0 for t in range(n)]
if k+1>=n:
  print(abs(l[-1]-l[0]))
  exit()
for i in range(n)[1:]:
  dp[i]=min([dp[i-d]+abs(l[i]-l[i-d]) for d in range(min(i,k)+1)[1:]])
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
dp=[10**10]*n
h=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
    dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]) for j in range(1,1+min(k,i)))

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
dp=[0]*(w+1)
for i in range(n):
    wi,vi=map(int,input().split())
    for j in range(w-wi,-1,-1):
        dp[j+wi]=max(dp[j+wi],dp[j]+vi)
print(dp[-1])

Fixed submission:
n,w=map(int,input().split())
dp=[0]*(w+1)
for i in range(n):
    wi,vi=map(int,input().split())
    for j in range(w-wi,-1,-1):
        dp[j+wi]=max(dp[j+wi],dp[j]+vi)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,w=map(int,input().split())
d,f=map(int,input().split())
if n==1:print(f if d<=w else 0);exit()
dp=[[0,0],[d,f]]#w,v
dp_=[]
for i in range(1,n):
  d,f=map(int,input().split())
  if dp_==[]:
    for x,c in dp:
      if x+d<=w:dp_.append([x+d,c+f])
    dp_+=dp
    dp=[]
  else:
    for x,c in dp_:
      if x+d<=w:dp.append([x+d,c+f])
    dp+=dp_
    dp_=[]
print(max(sum(dp+dp_,[])[1::2]))

Fixed submission:
n,w=map(int,input().split())
dp=[0]*(w+1)
for i in range(n):
    wi,vi=map(int,input().split())
    for j in range(w-wi,-1,-1):
        dp[j+wi]=max(dp[j+wi],dp[j]+vi)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
v=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  v[a-1].append(b-1)

memo=[-1]*n
def dp(x):
  if memo[x]!=-1:return memo[x]
  r=0
  for i in v[x]:
    r=max(r,dp(i)+1)
  memo[x]=r
  return r
print(max(dp(i) for i in range(n)))

Fixed submission:
import sys
sys.setrecursionlimit(2000000000)
n,m=map(int,input().split())
v=[[] for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  v[a-1].append(b-1)

memo=[-1]*n
def dp(x):
  if memo[x]!=-1:return memo[x]
  r=0
  for i in v[x]:
    r=max(r,dp(i)+1)
  memo[x]=r
  return r
print(max(dp(i) for i in range(n)))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
from decimal import Decimal as d
l=list(map(d,input().split()))
k=[0]*(n+1)
k[0]=1
for p in l:
    for j in range(n,-1,-1):
        k[j]*=(1-p)
        if j!=0:k[j]+=k[j-1]*p

print(sum(k[n//2+1:]))

Fixed submission:
n=int(input())

l=list(map(float,input().split()))
k=[0]*(n+1)
k[0]=1
for p in l:
    for j in range(n,-1,-1):
        k[j]*=(1-p)
        if j!=0:k[j]+=k[j-1]*p

print(sum(k[n//2+1:]))
Buggy python submission (verdict: Runtime Error):
print("Christmas", "Eve"*(25-int(input()))

Fixed submission:
print("Christmas", *["Eve"]*(25-int(input())))
Buggy python submission (verdict: Runtime Error):
l=input()
b=list()
for i in range(l)
    a=int(input())
    b.append(a)
print(sum(b)-max(b)/2)

Fixed submission:
l=int(input())
b=[int(input()) for i in range(l)]
print(sum(b)-max(b)//2)

Buggy python submission (verdict: Runtime Error):
l=input()
b=[]
for i in range(l)
    a=int(input())
    b.append(a)
print(sum(b)-max(b)/2)

Fixed submission:
l=int(input())
b=[int(input()) for i in range(l)]
print(sum(b)-max(b)//2)

Buggy python submission (verdict: Runtime Error):
N=input()
b={}
for i in range(N)
    a=int(input())
    b.append(a)
print(sum(b)-max(b)/2)

Fixed submission:
l=int(input())
b=[int(input()) for i in range(l)]
print(sum(b)-max(b)//2)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=sorted(list(map(int,input().split())))
ret=float("inf")
print(min([abs(l[i]-l[i+k]) for i in range(n-k)]))

Fixed submission:
n,k=map(int,input().split())
l=sorted([int(input()) for i in range(n)])
print(min([abs(l[i]-l[i+k-1]) for i in range(n-k+1)]))
Buggy python submission (verdict: Runtime Error):
print("YNEOS"[1-input()in"357"::2])

Fixed submission:
print("YES"if input()in"357"else"NO")

Buggy python submission (verdict: Runtime Error):
print("YES"if input()in"357"else"NO")
print("YNEOS"[1-input()in"357"::2])

Fixed submission:
print("YES"if input()in"357"else"NO")
Buggy python submission (verdict: Runtime Error):
#C-ID
n,m=map(int,input().split())
L={}
lp=[[] for _ in range(n)]#preごとのまとめの準備
for cn in range(m):
  p,y=map(int,input().split())
  lp[p-1].append([y,cn])
  lp[p-1]=sorted(lp[p-1])
for pre in range(n):
  k=len(lp[pre])
  if k>0:
    for d in range(k):
      cn=lp[pre][k][1]
      ans="0"*(6-len(str(pre)))+str(pre)+"0"*(6-len(str(d+1)))+str(d+1)
      L[cn]=ans
for h in range(m):
  print(L[h])

Fixed submission:
#C-ID
n,m=map(int,input().split())
L={}
lp=[list() for _ in range(n)]#preごとのまとめの準備
for cn in range(m):
  p,y=map(int,input().split())
  lp[p-1].append([y,cn])
for pre in range(n):
  k=len(lp[pre])
  if k>0:
    sd=lp[pre]
    asd=sorted(sd)
    for d in range(k):
      cn=asd[d][1]
      ans="0"*(6-len(str(pre+1)))+str(pre+1)+"0"*(6-len(str(d+1)))+str(d+1)
      L[cn]=ans
for h in range(m):
  print(L[h])