Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def ans(self):
        print(len(set(self.par))-1)

n,m=map(int,input().split())
uf=UnionFind(n)

for i in range(m):
    a,b,c=map(int,input().split())
    uf.union(a,b)
a=1
b=1
c=0
for i in range(3,n+1):
    if uf.same_check(1,i):
        a+=1
    elif uf.same_check(2,i):
        b+=1
    else:
        c+=1
if a>b:
    a+=c
else:
    b+=c
print(a*(a-1)//2+b*(b-1)//2-m)


Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def ans(self):
        print(len(set(self.par))-1)

n,m=map(int,input().split())
uf=UnionFind(n)

for i in range(m):
    a,b=map(int,input().split())
    uf.union(a,b)
a=1
b=1
c=0
for i in range(3,n+1):
    if uf.same_check(1,i):
        a+=1
    elif uf.same_check(2,i):
        b+=1
    else:
        c+=1
if a>b:
    a+=c
else:
    b+=c
print(a*(a-1)//2+b*(b-1)//2-m)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[0]*n

l[0]=2
l[1]=1

for i in range(n-2):
    l[i+2]=l[i+1]+l[i]
print(l[-1])

Fixed submission:
n=int(input())
l=[0]*(n+1)

l[0]=2
l[1]=1

for i in range(n-1):
    l[i+2]=l[i+1]+l[i]
print(l[-1])
Buggy python submission (verdict: Runtime Error):
x,y,z=map(int,input().split())
n=x//y+1
ans-i
for i in range(1,n+1):
    if i*y+(i-1)*z<=x:
        ans=i
print(ans)

Fixed submission:
x,y,z=map(int,input().split())
n=x//y+1
ans=0
for i in range(1,n+1):
    if i*y+(i+1)*z<=x:
        ans=i
print(ans)
Buggy python submission (verdict: Runtime Error):
s=list(input())
t=list(input())
n=len(s)
m=len(t)
if m>n:
    print('UNRESTORABLE')
    exit()
af=0
for i in range(n-m+1):
    k=s[n-m-i:n-i]
    f=0
    for j in range(m):
        if k[i]=='?' or k[i]==t[i]:
            f+=1
    if f==m:
        af+=1
        s[n-m-i:n-i]=t
        break
if af>0:
    ans=''
    for i in range(n):
        if s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]
    print(ans)
else:
    print('UNSTORABLE')
        

Fixed submission:
s=list(input())
t=list(input())
n=len(s)
m=len(t)
if m>n:
    print('UNRESTORABLE')
    exit()
af=0
for i in range(n-m+1):
    k=s[n-m-i:n-i]
    f=0
    for j in range(m):
        if k[j]=='?' or k[j]==t[j]:
            f+=1
    if f==m:
        af+=1
        s[n-m-i:n-i]=t
        break
if af>0:
    ans=''
    for i in range(n):
        if s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]
    print(ans)
else:
    print('UNRESTORABLE')
Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
d.sort()
t.sort()
di=0
f=0
for ti in range(m):
    if di<n:
        while d[di]!=t[ti]:
            di+=1
            if d[di]>t[ti]:
                f=1
                break
    if f==1:
        break
if f==1:
    print('NO')
else:
    print('YES')

Fixed submission:
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
d.sort()
t.sort()
di=0
f=0
for ti in range(m):
    if di<n:
        while d[di]!=t[ti]:
            if d[di]>t[ti]:
                f=1
                break
            di+=1
        di+=1
    if f==1:
        break
if f==1:
    print('NO')
else:
    print('YES')

Buggy python submission (verdict: Runtime Error):
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
d.sort()
t.sort()
di=0
f=0
for ti in range(m):
    if di<n:
    	while d[di]!=t[ti]:
        	di+=1
        	if d[di]>t[ti]:
            	f=1
            	break
    if f==1:
        break
if f==1:
    print('NO')
else:
    print('YES')

Fixed submission:
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
d.sort()
t.sort()
di=0
f=0
for ti in range(m):
    if di<n:
        while d[di]!=t[ti]:
            if d[di]>t[ti]:
                f=1
                break
            di+=1
        di+=1
    if f==1:
        break
if f==1:
    print('NO')
else:
    print('YES')
Buggy python submission (verdict: Runtime Error):
n=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        if (n*i*j)%(4*i*j-n*i-n*j)==0:
            w=(n*i*j)//(4*i*j-n*i-n*j)
            print(i,j,w)
            exit()

Fixed submission:
n=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        if (4*i*j-n*i-n*j)>0 and (n*i*j)%(4*i*j-n*i-n*j)==0:
            w=(n*i*j)//(4*i*j-n*i-n*j)
            print(i,j,w)
            exit()
Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,f=map(int,input().split())
w=set([])
for i in range(31):
    for j in range(31):
        x=a*i*100+b*j*100
        if 0<x<=f:
            w.add(x)
s=set([])
for i in range(3001):
    for j in range(3001):
        y=c*i+d*j
        if y<=f:
            s.add(y)
tmpn=0
for i in w:
    for j in s:
        if i+j<=f and i//100*e>=j:
            if tmpn<j/(1.0*(i+j)):
                tmpn=j/(1.0*(i+j))
                ans=[i,j]
print(*ans)


Fixed submission:
a,b,c,d,e,f=map(int,input().split())
w=set([])
for i in range(31):
    for j in range(31):
        x=a*i*100+b*j*100
        if 0<x<=f:
            w.add(x)
s=set([])
for i in range(3001):
    for j in range(3001):
        y=c*i+d*j
        if y<=f:
            s.add(y)
tmpn=-1
ans=[0,0]
for i in w:
    for j in s:
        if i+j<=f and i//100*e>=j:
            if tmpn<j/(1.0*(i+j)):
                tmpn=j/(1.0*(i+j))
                ans=[i+j,j]
print(*ans)

Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,f=map(int,input().split())
w=set([])
for i in range(31):
    for j in range(31):
        x=a*i*100+b*j*100
        if x<=f:
            w.add(x)
s=set([])
for i in range(3001):
    for j in range(3001):
        y=c*i+d*j
        if y<=f:
            s.add(y)
tmpn=0
for i in w:
    for j in s:
        if i+j<=f and i//100*e>=j:
            if tmpn<j/(1.0*(i+j)):
                tmpn=j/(1.0*(i+j))
                ans=[i,j]
print(*ans)

Fixed submission:
a,b,c,d,e,f=map(int,input().split())
w=set([])
for i in range(31):
    for j in range(31):
        x=a*i*100+b*j*100
        if 0<x<=f:
            w.add(x)
s=set([])
for i in range(3001):
    for j in range(3001):
        y=c*i+d*j
        if y<=f:
            s.add(y)
tmpn=-1
ans=[0,0]
for i in w:
    for j in s:
        if i+j<=f and i//100*e>=j:
            if tmpn<j/(1.0*(i+j)):
                tmpn=j/(1.0*(i+j))
                ans=[i+j,j]
print(*ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
l.sort()

ans=0
c=0
for i in range(n-1):
    if len(l)>0 and l[c]==l[c+1]:
        l.pop(c)
        l.pop(c)
    else:
        c+=1
if len(l)==n:
    print(n)
else:
    print(len(l))

Fixed submission:
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
l.sort()
l.append(10000000000000000000000)
f=1
ans=0
for i in range(n):
    if l[i]==l[i+1]:
        f+=1
    else:
        ans+=f%2
        f=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
l.sort()

ans=0
c=0
for i in range(n-1):
    if len(a)>0 and a[c]==a[c+1]:
        a.pop(0)
        a.pop(0)
    else:
        c+=1
print(len(a))

Fixed submission:
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))
l.sort()
l.append(10000000000000000000000)
f=1
ans=0
for i in range(n):
    if l[i]==l[i+1]:
        f+=1
    else:
        ans+=f%2
        f=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n,m,r=map(int,input().split())
rr=list(map(int,input().split()))
inf=10000000000
g=[[inf for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    g[a-1][b-1]=c
    g[b-1][a-1]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j]=min(g[i][j],g[i][k]+g[k][j])


ans=10**10
for i in itertools.permutations(range(0,r),r):
    kai=0
    for j in range(r-1):
        kai+=g[rr[i[j]]-1][rr[i[j+1]]-1]
    ans=min(ans,kai)
print(ans)

Fixed submission:
import itertools
n,m,r=map(int,input().split())
rr=list(map(int,input().split()))
inf=10000000000
g=[[inf for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    g[a-1][b-1]=c
    g[b-1][a-1]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j]=min(g[i][j],g[i][k]+g[k][j])


ans=10**10
for i in itertools.permutations(range(0,r),r):
    kai=0
    for j in range(r-1):
        kai+=g[rr[i[j]]-1][rr[i[j+1]]-1]
    ans=min(ans,kai)
print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import permutations
n,m,r=map(int,input().split())
rr=list(map(int,input().split()))
inf=10000000000
g=[[inf for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    g[a-1][b-1]=c
    g[b-1][a-1]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j]=min(g[i][j],g[i][k]+g[k][j])


ans=10**10
for i in permutations(range(0,n),n):
    kai=0
    for j in range(n-1):
        kai+=g[rr[i[j]]][rr[i[j+1]]]
    ans=min(ans,kai)
print(ans)

Fixed submission:
import itertools
n,m,r=map(int,input().split())
rr=list(map(int,input().split()))
inf=10000000000
g=[[inf for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    g[a-1][b-1]=c
    g[b-1][a-1]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j]=min(g[i][j],g[i][k]+g[k][j])


ans=10**10
for i in itertools.permutations(range(0,r),r):
    kai=0
    for j in range(r-1):
        kai+=g[rr[i[j]]-1][rr[i[j+1]]-1]
    ans=min(ans,kai)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(input())
b=list(input())
ans=1
i=0
f=0
mod=1000000007
while k!=n:
    if i==0:
        if a[i]==b[i]:
            i+=1
            ans*=3
            ans%=mod
            f=1
        else:
            i+=2
            ans*=6
            ans%=mod
            f=2
    else:
        if a[i]==b[i] and f==1:
            i+=1
            ans*=2
            ans%=mod
            f=1
        elif a[i]==b[i] and f==2:
            i+=1
            f=1
        elif a[i]!=b[i] and f==1:
            i+=2
            ans*=2
            ans%=mod
            f=2
        else:
            i+=2
            ans*=2
            ans%=mod
            f=2
print(ans%mod)
            
        

Fixed submission:
n=int(input())
a=list(input())
b=list(input())
ans=1
i=0
f=0
mod=1000000007
while i!=n:
    if i==0:
        if a[i]==b[i]:
            i+=1
            ans*=3
            ans%=mod
            f=1
        else:
            i+=2
            ans*=6
            ans%=mod
            f=2
    else:
        if a[i]==b[i] and f==1:
            i+=1
            ans*=2
            ans%=mod
            f=1
        elif a[i]==b[i] and f==2:
            i+=1
            f=1
        elif a[i]!=b[i] and f==1:
            i+=2
            ans*=2
            ans%=mod
            f=2
        else:
            i+=2
            ans*=3
            ans%=mod
            f=2
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
k=[[0]*m for i in range(n)]
for i in range(n):
    k[i]=list(map(int,input().split()))
ans=1000
for i in range(m-1):
    ma=[0]*m
    mi=-1
    for j in range(n):
        ma[k[j][0]]+=1
    if ans>max(ma):
        ans=max(ma)
    mi=ma.index(max(ma))+1
    for j in range(n):
        k[j].remove(mi)
print(ans)
        


Fixed submission:
n,m=map(int,input().split())
k=[[0]*m for i in range(n)]
for i in range(n):
    k[i]=list(map(int,input().split()))
ans=1000
for i in range(m-1):
    ma=[0]*m
    mi=-1
    for j in range(n):
        ma[k[j][0]-1]+=1
    if ans>max(ma):
        ans=max(ma)
    mi=ma.index(max(ma))+1
    for j in range(n):
        k[j].remove(mi)
if m==1:
    print(n)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
ans=[]
for i in range(n):
    ans.append(l[i])
    ans.reverse()
for i in range(n-1):
    print(ans[i],end=" ")
print(ans[n-1])

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
ans=[-1]*n
l.reverse()
for i in range(n):
    if i%2==0:
        ans[i//2]=l[i]
    else:
        ans[n-1-((i-1)//2)]=l[i]


for i in range(n-1):
    print(ans[i],end=" ")
print(ans[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
ans=[]
for i in range(n):
    ans.append(l[i])
    ans.reverse()
for i in range(n-1):
    print(ans[i],end=" ")
print(ans[n-1])

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
ans=[-1]*n
l.reverse()
for i in range(n):
    if i%2==0:
        ans[i//2]=l[i]
    else:
        ans[n-1-((i-1)//2)]=l[i]


for i in range(n-1):
    print(ans[i],end=" ")
print(ans[n-1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[0]*n
for i in range(n):
    l[i]=int(input())

vi=[0]*n
vi[0]=1
ans=1
st=l[0]
f=0
while vi[1]==0:
    vi[st]+=1
    if vi[st]>1:
        f=1
        break
    st=l[st-1]
    ans+=1
if f==0:
    print(ans)
else:
    print(-1)
    
    
  
  
    

Fixed submission:
n=int(input())
l=[0]*n
for i in range(n):
    l[i]=int(input())

vi=[0]*n
vi[0]=1
ans=0
st=l[0]
f=0
while vi[1]==0:
    vi[st-1]+=1
    if vi[st-1]>1:
        f=1
        break
    st=l[st-1]
    ans+=1
if f==0:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input())
if 100*a+10*b+c%4==0:
    print('YES')
else:
    print('NO')

Fixed submission:
a,b,c=map(int,input().split())
if (100*a+10*b+c)%4==0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split()))

if a+b<10:
    print(a+b)
else:
    print('error')

Fixed submission:
a,b=map(int,input().split())

if a+b<10:
    print(a+b)
else:
    print('error')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
dp=[0]
for i in range(n):
    for d in dp:
        dp.append(d+a[i])
dp=list(set(dp))
ans=0
for i in range(len(dp)):
    if dp[i]%10!=0:
        ans=max(ans,dp[i])
print(ans)

Fixed submission:
n=int(input())
a=[0]*n
for i in range(n):
    a[i]=int(input())
dp=[0]*10001
dp[0]=1
for i in range(n):
    for j in range(10000,-1,-1):
        if dp[j]>0:
            dp[j+a[i]]+=1
f=0
for i in range(10000,-1,-1):
    if dp[i]>0 and i%10!=0:
        print(i)
        f=1
        break
if f==0:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,k=map(int,input().split())
a=[]
for i in range(n):
    p=int(input())
    a.append(p-k)
d=[0]
for i in range(n):
    d.append(d[-1]+a[i])
d.reverse()
ans=0
b=[d[0]]
for i in range(n):
    bi=bisect.bisect_left(b,d[i+1])
    ans+=(i+1)-bi
    bisect.insort(b,d[i+1])
print(ans)

Fixed submission:
import bisect
#####segfunc######                                                              
def segfunc(x,y):
    return x+y

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built                                                                      
    for i in range(num-2,-1,-1):
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])
    
def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
        k=(k-1)//2
        seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
        if p&1==0:
            res=segfunc(res,seg[p])
        if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
        p=p//2
        q=(q-1)//2
    if p==q:
        res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele=0
n,k=map(int,input().split())
num=2**(n).bit_length()
seg=[ide_ele]*2*num
a=[]
for i in range(n):
    p=int(input())
    a.append(p-k)
d=[0]
for i in range(n):
    d.append(d[-1]+a[i])
b=sorted(d)
a=[]
for i in d:
    p=bisect.bisect_left(b,i)
    a.append(p)
#init(p)
ans=0
a.reverse()
update(a[0],1)
for i in range(n):
    ans+=query(a[i+1],1+n)
    update(a[i+1],query(a[i+1],a[i+1]+1)+1)
print(ans)
#query(0,i)

exit()
Buggy python submission (verdict: Runtime Error):
import heapq
n=int(input())
l=list(map(int,input().split()))
q=[]
for i in range(n):
    heapq.heappush(q,l[i])
a1=[0]*(n+1)
a1[0]=sum(l[:n])
for i in range(n):
    p=heapq.heappop(q)
    a1[i+1]=a1[i]-p+max(p,l[i+n])
    heapq.heappush(q,max(p,l[i+n]))
q=[]
l.reverse()
for i in range(n):
    heapq.heappush(q,-l[i])
a1.reverse()
a1[0]-=sum(l[:n])
z=sum(l[:n])
for i in range(n):
    p=heapq.heappop(q)
    z=z-min(-p,l[i+n])
    a1[i+1]-=z
    heapq.heappush(q,max(p,-l[i+n])
print(max(a1))

Fixed submission:
import heapq
n=int(input())
l=list(map(int,input().split()))
q=[]
for i in range(n):
    heapq.heappush(q,l[i])
a1=[0]*(n+1)
a1[0]=sum(l[:n])
for i in range(n):
    p=heapq.heappop(q)
    a1[i+1]=a1[i]-p+max(p,l[i+n])
    heapq.heappush(q,max(p,l[i+n]))
#print(a1)
q=[]
l.reverse()
for i in range(n):
    heapq.heappush(q,-l[i])
a1.reverse()
a1[0]-=sum(l[:n])
z=sum(l[:n])
for i in range(n):
    p=heapq.heappop(q)
    z=z+p+min(-p,l[i+n])
    a1[i+1]-=z
    heapq.heappush(q,max(p,-l[i+n]))
print(max(a1))
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a==b and b==c and a%2=0:
    print(-1)
else:
    ans=0
    while a%2==0 ans b%2==0 and c%2==0:
        tmp=a
        tmp2=b
        a=(b+c)//2
        b=(c+tmp)//2
        c=(tmp+tmp2)//2
        ans+=1
    print(ans)

Fixed submission:
a,b,c=map(int,input().split())
if a==b and b==c and a%2==0:
    print(-1)
else:
    ans=0
    while a%2==0 and b%2==0 and c%2==0:
        tmp=a
        tmp2=b
        a=(b+c)//2
        b=(c+tmp)//2
        c=(tmp+tmp2)//2
        ans+=1
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,w=map(int,input().split())
wv=[]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    wv.append([a,b])
    v.append(b)
v.sort(reverse=True)
ans=0
w0=wv[0][0]
for i in range(1,n+1):
    wp=w-w0*i
    if wp<0:
        continue
    elif wp>=3*i:
        ans=max(ans,sum(v[:i]))
    else:
        dp=[-1 for iii in range(wp+1)]
        dp[0]=0
        for j in range(n):
            for k in range(wp,-1,-1):
                if dp[k]>=0 and k+wv[i][0]-w0<=wp:
                    dp[k+wv[i][0]-w0]=max(dp[k]+wv[i][1],dp[k+wv[i][0]-w0])
        ans=max(max(dp),ans)
print(ans)


Fixed submission:
n,w=map(int,input().split())
wv=[]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    wv.append([a,b])
    v.append(b)
v.sort(reverse=True)
ans=0
w0=wv[0][0]
wp=3*n+1
dp=[[-1 for jjj in range(n+1)] for iii in range(3*n+1)]
dp[0][0]=0
for i in range(n):
    for jj in range(n-1,-1,-1):
        for k in range(wp-1,-1,-1):
            if dp[k][jj]>=0 and k+wv[i][0]-w0<=wp-1:
                dp[k+wv[i][0]-w0][jj+1]=max(dp[k][jj]+wv[i][1],dp[k+wv[i][0]-w0][jj+1])
for i in range(1,n+1):
    wp=w-w0*i
    if wp<0:
        continue
    elif wp>=3*i:
        ans=max(ans,sum(v[:i]))
    else:
        for j in range(i+1):
            for k in range(wp+1):
                ans=max(dp[k][j],ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
n,w=map(int,input().split())
wv=[]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    wv.append([a,b])
    v.append(b)
v.sort(reverse=True)
ans=0
w0=wv[0][0]
for i in range(1,n+1):
    wp=w-w0*i
    if wp<0:
        continue
    elif wp>=3*i:
        ans=max(ans,sum(v[:i]))
    else:
        dp=[-1 for iii in range(wp+1)]
        dp[0]=0
        for j in range(n):
            for k in range(wp,-1,-1):
                if dp[k]>=0:
                    dp[k+wv[i][0]-w0]=max(dp[k]+wv[i][1],dp[k+wv[i][0]-w0])
        ans=max(max(dp),ans)
print(ans)

Fixed submission:
n,w=map(int,input().split())
wv=[]
v=[]
for i in range(n):
    a,b=map(int,input().split())
    wv.append([a,b])
    v.append(b)
v.sort(reverse=True)
ans=0
w0=wv[0][0]
wp=3*n+1
dp=[[-1 for jjj in range(n+1)] for iii in range(3*n+1)]
dp[0][0]=0
for i in range(n):
    for jj in range(n-1,-1,-1):
        for k in range(wp-1,-1,-1):
            if dp[k][jj]>=0 and k+wv[i][0]-w0<=wp-1:
                dp[k+wv[i][0]-w0][jj+1]=max(dp[k][jj]+wv[i][1],dp[k+wv[i][0]-w0][jj+1])
for i in range(1,n+1):
    wp=w-w0*i
    if wp<0:
        continue
    elif wp>=3*i:
        ans=max(ans,sum(v[:i]))
    else:
        for j in range(i+1):
            for k in range(wp+1):
                ans=max(dp[k][j],ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
l.append(0)
a1=0
b1=0
a2=0
b2=0
for i in range(n):
    b1+=l[i]
    b2+=l[i]
    if i%2==0:
        if b1>=0:
            a1+=abs(-1-b1)
            b1=-1-l[i+1]
        if b2=<0:
            a2+=abs(1-b2)
            b2=1-l[i+1]
    else:
        if b1<=0:
            a1+=abs(1-b1)
            b1=1-l[i+1]
        if b2>=0:
            a2+=abs(-1-b2)
            b2=-1-l[i+1]
print(min(a1,a2))

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
ans1 = 0
ans2 = 0
S1 = 0
S2 = 0
for n in range(N):
    S1 += a[n]
    S2 += a[n]
    if n%2 == 0:
        if S1 >= -1:
            ans1 += S1 + 1
            S1 = -1
        if S2 <= 1:
            ans2 += 1 - S2
            S2 = 1
    if n%2 == 1:
        if S1 <= 1:
            ans1 += 1 - S1
            S1 = 1
        if S2 >= -1:
            ans2 += S2 + 1
            S2 = -1
print(min(ans1,ans2))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
if a+b>=24:
    print(a+b-24)
else:
    print(a+b)

Fixed submission:
a,b=map(int,input().split())
if a+b>=24:
    print(a+b-24)
else:
    print(a+b)