Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import fractions
a,b,c,d=map(int,input().split())

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
s=b//(c*d//fractions.gcd(c,d))-(a-1)//(c*d//fractions.gcd(c,d))


print((b-(a-1)-(cc+dd-s)))

Fixed submission:
a=list(input())

ans=0
for i in range(int(len(a))-1):
    if a[i]==a[i+1]:
        ans+=1
    else:
        ans+=0

if ans==0:
    print('Good')
else:
    print('Bad')
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
s=b//(c*d/math.gcd(c,d))-(a-1)//(c*d/math.gcd(c,d))


print(int((b-(a-1)-(cc+dd-s))))

Fixed submission:
import fractions
a,b,c,d=map(int,input().split())

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
s=b//(c*d//fractions.gcd(c,d))-(a-1)//(c*d//fractions.gcd(c,d))


print((b-(a-1)-(cc+dd-s)))

Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d=map(int,input().split())

ans=0

for i in range(a,b+1):
    if i%c!=0 and i%d!=0:
        ans+=1
    else:
        ans+=0

print(ans)

Fixed submission:
import fractions
a,b,c,d=map(int,input().split())

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
s=b//(c*d//fractions.gcd(c,d))-(a-1)//(c*d//fractions.gcd(c,d))


print((b-(a-1)-(cc+dd-s)))
Buggy python submission (verdict: Runtime Error):
import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
b1=bisect.bisect_left(a,0)
b2=bisect.bisect_right(a,0)
l=[]
#print(a,b1,b2)
if a[0]>0 or b1==1 or (b1==0 and b2>=1):
    l.append([a[0],a[1]])
    ans=l[0][0]-l[0][1]
    for i in range(1,n-1):
        if i!=n-2:
            l.append([l[-1][0]-l[-1][1],a[i]])
        else:
            l.append([a[-1],l[-1][0]-l[-1][1]])
        ans=l[i][0]-l[i][1]
    print(ans)
elif a[-1]<0 or n-b2==1 or (b2==n and b1<=n-1):
    l.append([a[-1],a[-2]])
    ans=l[0][0]-l[0][1]
    for i in range(n-2,0,-1):
        if i!=1:
            l.append([a[i],l[-1][0]-l[-1][1]])
        else:
            l.append([l[-1][0]-l[-1][1],a[0]])
        ans=l[i][0]-l[i][1]
    print(ans)
else:
    l.append([a[-1],a[1]])
    ans_1=l[0][0]-l[0][1]
    for i in range(b1,2,-1):
        l.append([a[i],l[-1][0]-l[-1][1]])
        ans_1=l[i][0]-l[i][1]
    l.append([a[0],a[-2]])
    ans_2=l[-1][0]-l[-1][1]
    for i in range(b1+1,n-1):
        l.append([l[-1][0]-l[-1][1],a[i]])
        ans_2=l[i][0]-l[i][1]
    l.append([ans_1,ans_2])
    ans=l[i][0]-l[i][1]
    print(ans)
for i in range(n-1):
    print(*l[i])








Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
l=[a[0]]
r=[a[-1]]
for i in range(1,n-1):
    if a[i]<=0:
        r.append(a[i])
    else:
        l.append(a[i])
r.sort()
l.sort()
if len(r)==1:
    X=r[0]
    p=[]
else:
    p=[[r[-1],r[-2]]]
    for i in range(len(r)-3,-1,-1):
        p.append([p[-1][0]-p[-1][1],r[i]])
    X=p[-1][0]-p[-1][1]
if len(l)==1:
    Y=l[0]
    q=[]
else:
    q=[[l[0],l[1]]]
    for i in range(2,len(l)):
        q.append([q[-1][0]-q[-1][1],l[i]])
    Y=q[-1][0]-q[-1][1]
print(X-Y)
if p and q:
    for i in range(len(p)):
        print(*p[i])
    for i in range(len(q)):
        print(*q[i])
    print(X,Y)
elif p:
    for i in range(len(p)):
        print(*p[i])
    print(X,Y)
elif q:
    for i in range(len(q)):
        print(*q[i])
    print(X,Y)
else:
    print(X,Y)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
y=[list(map(int,input().split()))[::-1] for i in range(m)]
y.sort()
y=y[::-1]
#print(y)

l=[]
for i in range(m):
    l+=[y[i][0]]*y[i][1]
#print(l)
l=l[:n]
ans=0
#print(a,l)
for i in range(n):
    if i<=len(l)-1:
        ans+=max(a[i],l[i])
    else:
        ans+=a[i]

print(ans)

Fixed submission:
import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
y=[list(map(int,input().split()))[::-1] for i in range(m)]
y.sort()
y=y[::-1]
#print(y)

l=[]
w=0
for i in range(m):
    w+=y[i][1]
    l+=[y[i][0]]*y[i][1]
    if w>=n:
        break

#print(l)
l=l[:n]
ans=0
#print(a,l)
for i in range(n):
    if i<=len(l)-1:
        ans+=max(a[i],l[i])
    else:
        ans+=a[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
l=[]
for i in range(m):
    b,c=map(int,input().split())
    l+=[c]*b
l.sort()
l=l[::-1]
ans=0
#print(a,l)
for i in range(n):
    if i<=len(l)-1:
        ans+=max(a[i],l[i])
    else:
        ans+=a[i]

print(ans)

Fixed submission:
import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
y=[list(map(int,input().split()))[::-1] for i in range(m)]
y.sort()
y=y[::-1]
#print(y)

l=[]
w=0
for i in range(m):
    w+=y[i][1]
    l+=[y[i][0]]*y[i][1]
    if w>=n:
        break

#print(l)
l=l[:n]
ans=0
#print(a,l)
for i in range(n):
    if i<=len(l)-1:
        ans+=max(a[i],l[i])
    else:
        ans+=a[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
l=[]
for i in range(m):
    b,c=map(int,input().split())
    l+=[c]*b
l.sort()
l=l[::-1]
ans=0
#print(a,l)
for i in range(n):
    if i<=len(l)-1:
        ans+=max(a[i],l[i])
    else:
        ans+=a[i]

print(ans)

Fixed submission:
import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
y=[list(map(int,input().split()))[::-1] for i in range(m)]
y.sort()
y=y[::-1]
#print(y)

l=[]
w=0
for i in range(m):
    w+=y[i][1]
    l+=[y[i][0]]*y[i][1]
    if w>=n:
        break

#print(l)
l=l[:n]
ans=0
#print(a,l)
for i in range(n):
    if i<=len(l)-1:
        ans+=max(a[i],l[i])
    else:
        ans+=a[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())

ans=0
for i in range(n//r+1):
    for j in range(n//g+1):
        if (n-(i*r+j*g))%b==0 and (n-(i*r+j*g))>=0:
            #print(n-(i*r+j*g))
            ans+=1
print(ans)

Fixed submission:
r,g,b,n=map(int,input().split())

ans=0
for i in range(n//r+1):
    for j in range(n//g+1):
        if (n-(i*r+j*g))%b==0 and (n-(i*r+j*g))>=0:
            #print(n-(i*r+j*g))
            ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import copy
h,w=map(int,input().split())
a=[list("."*(w+2))]+[list("."+input()+".") for i in range(h)]+[list("."*(w+2))]
b=copy.deepcopy(a) 
#print(a,b)
for k in range(h+w-2):
    for i in range(1,h+1):
        for j in range(1,w+1):
            if a[i][j]=='#':
                b[i-1][j]='#'
                b[i+1][j]='#'
                b[i][j-1]='#'
                b[i][j+1]='#'
    #print(a,b)
    if a==b:
        break
    else:
        a=copy.deepcopy(b) 
print(k-1)


Fixed submission:
from collections import deque
h,w=map(int,input().split())
p=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
q=deque([])
for i in range(1,h+1):
	for j in range(1,w+1):
		if p[i][j]=='#':
			p[i][j]=0
			q.append([i,j])
d=[(1,0),(-1,0),(0,1),(0,-1)]
while q:
	x,y=q.popleft()
	for dx,dy in d:
		if p[x+dx][y+dy]==".":
			p[x+dx][y+dy]=p[x][y]+1
			q.append([x+dx,y+dy])
ans=0
for i in range(1,h+1):
	for j in range(1,w+1):
		ans=max(ans,p[i][j])
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=str(input())


a=s.find('#');b=s.rfind('.')

if a<b:
    c=s[a:b+1].count('#');d=s[a:b+1].count('.')
    ans=min(c,d)
else:
    ans=0

l=[]
for i in range(n):
    if s[i]=='.':
        l.append(i)

y=s[l[0]+1:].count('.')
for i in range(len(l)):
    x=s[:l[i]].count('#')
    ans=min(ans,x+y)
    y-=1
print(ans)

Fixed submission:
n=int(input())
s=str(input())
a=0
b=s.count('.')
l=[b]
for i in range(n):
    if s[i]=='#':
        a+=1
    if s[i]=='.':
        b-=1
    l.append(a+b)
print(min(l))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=str(input())

l=[]
i=n
aa=s.rfind('.')
bb=s.find('.')
ans=min(s[:aa+1].count('.'),s[:aa+1].count('#'))
while i>=0:
    a=s[:i].rfind('.')
    ans=min(ans,(1+min(s[:a+1].count('.'),s[:a+1].count('#'))))
    #print(ans,a)
    i=a
    if a==bb:
        break

print(ans)



Fixed submission:
n=int(input())
s=str(input())
a=0
b=s.count('.')
l=[b]
for i in range(n):
    if s[i]=='#':
        a+=1
    if s[i]=='.':
        b-=1
    l.append(a+b)
print(min(l))
Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
n=len(s)

a=0
b=0
for i in range(n):
        if i%2==0:
                a+=2**i
        elif i%2==1:
                b+=2**i
a=format(a,'b').zfill(n)
b=format(b,'b').zfill(n)

c=0
d=0
for j in range(n):
        if s[j]==a[j]:
                c+=1
        else:
                d+=1
print(min(c,d))

Fixed submission:
s=str(input())
n=len(s)

a=''
for i in range(n):
        if i%2==0:
                a+='1'
        else:
                a+='0'
c=0
d=0
for j in range(n):
        if s[j]==a[j]:
                c+=1
        else:
                d+=1
print(min(c,d))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=list(str(input()))
r=[]
l=[]
c=0
d=1
for i in range(n):
	if s[i]=='1' and d==1:
		r.append(i)
		c=1
		d=0
	elif s[i]=='0' and c==1:
		l.append(i-1)
		c=0
		d=1
if c>0:
	l.append(i)
if len(r)<=k+1:
	r=[0]*(k+1-len(r))+r+[n-1]*(k+1-len(r))
	l=[0]*(k+1-len(l))+l+[n-1]*(k+1-len(l))
ans=0
for i in range(k+1):
	ans=max(ans,l[i+k]-r[i]+1)
print(ans)

Fixed submission:
n,k=map(int,input().split())
s=list(str(input()))
r=[]
l=[]
c=0
d=1
for i in range(n):
	if s[i]=='1' and d==1:
		r.append(i)
		c=1
		d=0
	elif s[i]=='0' and c==1:
		l.append(i-1)
		c=0
		d=1
if c>0:
	l.append(i)
if len(r)<=k+1:
	r=[0]*(k+1-len(r))+r+[n-1]*(k+1-len(r))
	l=[0]*(k+1-len(l))+l+[n-1]*(k+1-len(l))
r=[0]+r+[n-1]
l=[0]+l+[n-1]
ans=0
for i in range(len(r)-k):
	ans=max(ans,l[i+k]-r[i]+1)
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=list(str(input()))
l=[]
c=0
for i in range(n):
	if s[i]=='1' and c==0:
		l.append(i)
		c=1
	elif s[i]=='0':
		c=0
for i in range(n-1,-1,-1):
	if s[i]=='1':
		a=i
		break
else:
	a=n-1
l=[0]+l[1:-1]+[a]
#print(l)
m=len(l)
r=[]
for i in range(m-k):
	r.append(l[i+k]-l[i]+1)
print(max(r))

Fixed submission:
n,k=map(int,input().split())
s=list(str(input()))
r=[]
l=[]
c=0
d=1
for i in range(n):
	if s[i]=='1' and d==1:
		r.append(i)
		c=1
		d=0
	elif s[i]=='0' and c==1:
		l.append(i-1)
		c=0
		d=1
if c>0:
	l.append(i)
if len(r)<=k+1:
	r=[0]*(k+1-len(r))+r+[n-1]*(k+1-len(r))
	l=[0]*(k+1-len(l))+l+[n-1]*(k+1-len(l))
r=[0]+r+[n-1]
l=[0]+l+[n-1]
ans=0
for i in range(len(r)-k):
	ans=max(ans,l[i+k]-r[i]+1)
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=list(str(input()))
l=[]
c=0
for i in range(n):
	if s[i]=='1' and c==0:
		l.append(i)
		c=1
	elif s[i]=='0':
		c=0
for i in range(n):
	if s[i]=='1':
		a=i
l=[0]+l[1:-1]+[a]
#print(l)
m=len(l)
r=[]
for i in range(m-k):
	r.append(l[i+k]-l[i]+1)
print(max(r))

Fixed submission:
n,k=map(int,input().split())
s=list(str(input()))
r=[]
l=[]
c=0
d=1
for i in range(n):
	if s[i]=='1' and d==1:
		r.append(i)
		c=1
		d=0
	elif s[i]=='0' and c==1:
		l.append(i-1)
		c=0
		d=1
if c>0:
	l.append(i)
if len(r)<=k+1:
	r=[0]*(k+1-len(r))+r+[n-1]*(k+1-len(r))
	l=[0]*(k+1-len(l))+l+[n-1]*(k+1-len(l))
r=[0]+r+[n-1]
l=[0]+l+[n-1]
ans=0
for i in range(len(r)-k):
	ans=max(ans,l[i+k]-r[i]+1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n=int(input())
s=str(input())
a=Counter(s)
aa=list(a.values())
aa.sort()
aa=aa[::-1]
m=len(aa)
ans=0
#print(aa)
for i in range(1,2**m):
    z=format(i,'b').zfill(m)
    #print(z)
    ans1=1
    for j in range(m):
        if aa[j]==1:
            ans+=ans1%(10**9+7)
            break
        if int(z[j])>0:
            ans1*=aa[j]*int(z[j])%(10**9+7)
    else:
        ans+=ans1%(10**9+7)
print(ans%(10**9+7))

Fixed submission:
from collections import Counter
n=int(input())
s=str(input())
a=Counter(s)
aa=list(a.values())
#print(aa)
ans=1
for i in aa:
    ans*=(i+1)%(10**9+7)
print((ans-1)%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from itertools import product
n=int(input())
s=str(input())
a=Counter(s)
aa=list(a.values())
aa.sort()
aa=aa[::-1]
m=len(aa)
ans=0
#print(aa)
for i in range(1,2**m):
    z=format(i,'b').zfill(m)
    #print(z)
    ans1=1
    for j in range(m):
        if int(z[j])>0:
            ans1*=aa[j]*int(z[j])%(10**9+7)
    ans+=ans1%(10**9+7)
print(ans%(10**9+7))

Fixed submission:
from collections import Counter
n=int(input())
s=str(input())
a=Counter(s)
aa=list(a.values())
#print(aa)
ans=1
for i in aa:
    ans*=(i+1)%(10**9+7)
print((ans-1)%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

a,b=map(int,input().split())
ans=int(0)
for i in range(a,b+1):
        ans=ans^i
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
import heapq
import fractions
a,b=map(int,input().split())

if a%2==0 and b%2==1:
        if (b-a+1)%4==0:
                print(0)
        else:
                print(1)
elif a%2==0 and b%2==0:
        if (b-1-a+1)%4==0:
                print(b)
        else:
                print(1^b)
elif a%2==1 and b%2==1:
        if (b-1-a+1)%4==0:
                print(a)
        else:
                print(1^a)
elif a%2==1 and b%2==0:
        if (b-1-a)%4==0:
                print(a^b)
        else:
                print(a^b^1)
Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
c=len(s)

for _ in range(10000):
        s=s.replace('01','')
        s=s.replace('10','')
        d=s.count('01')
        e=s.count('10')
        if d==0 and e==0:
                break
print(c-len(s))

Fixed submission:
s=str(input())

a=s.count('0')
b=s.count('1')
print(min(a,b)*2)

Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
c=len(s)

for _ in range(10000):
        s=s.replace('01','')
        s=s.replace('10','')
print(c-len(s))

Fixed submission:
s=str(input())

a=s.count('0')
b=s.count('1')
print(min(a,b)*2)

Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
c=len(s)

for _ in range(10**5):
        s=s.replace('01','')
        s=s.replace('10','')
print(c-len(s))

Fixed submission:
s=str(input())

a=s.count('0')
b=s.count('1')
print(min(a,b)*2)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq 
import copy
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
r=copy.deepcopy(l)

for i in range(n):
    l[i][0],l[i][1]=-l[i][0],-l[i][1]
    r[i][0],r[i][1]=-r[i][1],-r[i][0]
heapq.heapify(l)
heapq.heapify(r)
ans=0
for i in range(n):
    if i%2==0:
        ans-=l[0][0]*((-1)**i)
        r.remove(l[0][::-1])
        minimum=heapq.heappop(l)
    else:
        ans-=r[0][0]*((-1)**i)
        l.remove(r[0][::-1])
        minimum=heapq.heappop(r)
print(ans)

Fixed submission:
n=int(input())
l=[]
c=0
for i in range(n):
    a,b=map(int,input().split())
    c-=b
    l.append(a+b)
l.sort()
l=l[::-1]
for i in range(0,n,2):
    c+=l[i]
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
imput=sys.stdin.readline
import heapq 
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    l[i][0],l[i][1]=-l[i][0],-l[i][1]
heapq.heapify(l)
ans=0
for i in range(n):
    ans-=l[0][0]*((-1)**i)
    minimum=heapq.heappop(l)
    for j in range(n-i-1):
        l[j][0],l[j][1]=l[j][1],l[j][0]
    #print(l)
print(ans)

Fixed submission:
n=int(input())
l=[]
c=0
for i in range(n):
    a,b=map(int,input().split())
    c-=b
    l.append(a+b)
l.sort()
l=l[::-1]
for i in range(0,n,2):
    c+=l[i]
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq 
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    l[i][0],l[i][1]=-l[i][0],-l[i][1]
heapq.heapify(l)
ans=0
for i in range(n):
    ans-=l[0][0]*((-1)**i)
    minimum=heapq.heappop(l)
    for j in range(n-i-1):
        l[j][0],l[j][1]=l[j][1],l[j][0]
    #print(l)
print(ans)



Fixed submission:
n=int(input())
l=[]
c=0
for i in range(n):
    a,b=map(int,input().split())
    c-=b
    l.append(a+b)
l.sort()
l=l[::-1]
for i in range(0,n,2):
    c+=l[i]
print(c)

Buggy python submission (verdict: Runtime Error):
import heapq
import numpy as np 
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    l[i][0],l[i][1]=-l[i][0],-l[i][1]
heapq.heapify(l)
ans=0
for i in range(n):
    ans-=l[0][0]*((-1)**i)
    minimum=heapq.heappop(l)
    for j in range(n-i-1):
        l[j][0],l[j][1]=l[j][1],l[j][0]
    #print(l)
print(ans)



Fixed submission:
n=int(input())
l=[]
c=0
for i in range(n):
    a,b=map(int,input().split())
    c-=b
    l.append(a+b)
l.sort()
l=l[::-1]
for i in range(0,n,2):
    c+=l[i]
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    l=[]
    for j in range(max(0,i-k),i):
        l.append(dp[j]+abs(h[i]-h[j]))
    dp[i]=min(l)
    #print(l)
print(dp[-1])


Fixed submission:
import sys
input = sys.stdin.readline
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    l=[]
    for j in range(max(0,i-k),i):
        l.append(dp[j]+abs(h[i]-h[j]))
    dp[i]=min(l)
    #print(l)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,w=map(int,input().split())
dp=[[0]*(w+1) for _ in range(n)]
l=[0]*n
for i in range(n):
    l[i]=list(map(int,input().split()))
#print(l)
for i in range(w+1):
    if i>=l[0][0]:
        dp[0][i]=l[0][1]
for i in range(w+1):
    for j in range(n-1):
        if i<l[j+1][0]:
            dp[j+1][i]=dp[j][i]
        else:
            dp[j+1][i]=max(dp[j][i-l[j+1][0]]+l[j+1][1],dp[j][i])


print(dp[-1][-1])

Fixed submission:
n,w=map(int,input().split())
dp=[[0]*(w+1) for _ in range(n)]
l=[0]*n
for i in range(n):
    l[i]=list(map(int,input().split()))
#print(l)
for i in range(w+1):
    if i>=l[0][0]:
        dp[0][i]=l[0][1]
for i in range(w+1):
    for j in range(n-1):
        if i<l[j+1][0]:
            dp[j+1][i]=dp[j][i]
        else:
            dp[j+1][i]=max(dp[j][i-l[j+1][0]]+l[j+1][1],dp[j][i])


print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
n,w=map(int,input().split())
dp=[[0]*(w+1) for _ in range(n)]
l=[0]*n
for i in range(n):
    l[i]=list(map(int,input().split()))
#print(l)
for i in range(w+1):
    if i>=l[0][0]:
        dp[0][i]=l[0][1]
for i in range(w+1):
    for j in range(n-1):
        if i<l[j+1][0]:
            dp[j+1][i]=dp[j][i]
        else:
            dp[j+1][i]=max(dp[j][i-l[j+1][0]]+l[j+1][1],dp[j][i])


print(dp[-1][-1])

Fixed submission:
n,w=map(int,input().split())
l=[list(map(int, input().split())) for i in range(n)]
c=0
d=0
for i in range(n):
    c+=l[i][1];d+=l[i][0]
dp=[[0]*(c+1) for _ in range(n)]
for i in range(1,l[0][1]+1):
    dp[0][i]=l[0][0]
for i in range(l[0][1]+1,c+1):
    dp[0][i]=d
for i in range(1,n):
    for j in range(1,c+1):
        if j<=l[i][1]:
            dp[i][j]=min(dp[i-1][j],l[i][0])
        else:
            dp[i][j]=min(dp[i-1][j],dp[i-1][j-l[i][1]]+l[i][0])
#print(dp)
for i in range(c,0,-1):
    if dp[-1][i]<=w:
        print(i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


n,m=map(int,input().split())
l=[[0,0] for _ in range(m)]
p=[[] for _ in range(n)]

for i in range(m):
        l[i][0],l[i][1]=map(int,input().split())
        p[l[i][0]-1].append(l[i][1])
for i in range(n):
        p[i].sort()
for i in range(m):
        for j in range(len(p[l[i][0]-1])):
                if p[l[i][0]-1][j]==l[i][1]:
                        c=j+1
                        print(str(l[i][0]).zfill(6)+str(c).zfill(6))
                        break

Fixed submission:
import sys
input = sys.stdin.readline


n,m=map(int,input().split())
p=[[] for _ in range(n)]

for i in range(m):
        a,b=map(int,input().split())
        p[a-1].append([b,i])

for i in range(n):
        p[i].sort()
ans=[""]*m
for i in range(n):
        for j in range(len(p[i])):
                ans[p[i][j][1]]=str(i+1).zfill(6)+str(j+1).zfill(6)

for i in range(m):
        print(ans[i])
Buggy python submission (verdict: Runtime Error):
import fractions
n,m=map(int,input().split())
s=str(input())
t=str(input())
f=fractions.gcd(n,m)
f2=n*m//f
#print(f2)
for i in range(f2,n*m+1,f2):
    z2=(i//n)*(i//m)//fractions.gcd(i//n,i//m)
    #print(i,z2)
    for j in range(1,i+1,z2):
        if s[j//(i//n)]!=t[j//(i//m)]:
            break
    else:
        print(i)
        break
else:
    print(-1)

Fixed submission:
import fractions
n,m=map(int,input().split())
s=str(input())
t=str(input())
f=fractions.gcd(n,m)
f2=n*m//f
#print(f2)
for i in range(f2,n*m+1,f2):
    z2=(i//n)*(i//m)//fractions.gcd(i//n,i//m)
    for j in range(1,i+1,z2):
        #print(i,j)
        if s[-(-j//(i//n))-1]!=t[-(-j//(i//m))-1]:
            break
    else:
        print(i)
        break
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[[0,0,0] for _ in range(n)]
for i in range(n):
    l[i][0],l[i][1],l[i][2]=map(int,input().split())
p=[]
for i in range(n):
    for cx in range(101):
        for cy in range(101):
            if l[i][2]>0:
                H=l[i][2]+abs(l[i][0]-cx)+abs(l[i][1]-cy)
                p.append([cx,cy,H])

p.sort()
ans=0
for i in range(101*101*n-1):
    if p[i]==p[i+1]:
        ans+=1
        if ans==n-1:
            print(' '.join(map(str,p[i])))
            break
    else:
        ans=0


Fixed submission:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(101):
    for j in range(101):
        H=[]
        for k in range(n):
            if l[k][2]>0:
                H.append(l[k][2]+abs(l[k][0]-i)+abs(l[k][1]-j))
            else:
                continue
        if len(set(H))==1:
            for k in range(n):
                if l[k][2]==0:
                    if H[0]-abs(l[k][0]-i)-abs(l[k][1]-j)>0:
                        break
            else:
                print(i,j,H[0])
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
n,m=map(int,input().split())
if m%n==0:
    print(int(m/n))
else:
    ans=1
    for i in range(2,m//n+1):
        c=fractions.gcd(i,m-i*n)
        if c>ans:
            ans=c
    print(ans)




Fixed submission:
n, m = map(int, input().split())
l = []
for i in range(1, int(m**(1/2)) + 1):
	if m % i == 0:
		l.append(i)
		l.append(m // i)
l.sort()
l=l[::-1]
for i in l:
    if m//n>=i:
        print(i)
        break
Buggy python submission (verdict: Runtime Error):
n=int(input())
v=list(map(int,input().split()))


A=[0]*(10**1)
B=[0]*(10**1)


for i in range(n):
    if i%2==0:
        A[v[i]-1]+=1
    else:
        B[v[i]-1]+=1
x=n//2-max(A)
y=n//2-max(B)
AA=''.join(map(str,A))
BB=''.join(map(str,B))
a=AA.find(str(max(A)))
b=BB.rfind(str(max(B)))
if a!=b:
    print(x+y)




Fixed submission:
n=int(input())
v=list(map(int,input().split()))
import collections

if len(set(v))==1:
    print(n//2)
else:
    a=[]
    b=[]
    for i in range(n):
        if i%2==0:
            a.append(v[i])
        else:
            b.append(v[i])
    a=collections.Counter(a)
    a0=a.most_common()[0]
    b=collections.Counter(b)
    b0=b.most_common()[0]
    if a0[0]!=b0[0]:
        print(n-a0[1]-b0[1])
    elif a0[0]==b0[0]:
        if a0[1]>b0[1]:
            print(n-a0[1]-b.most_common()[1][1])
        elif a0[1]<b0[1]:
            print(n-b0[1]-a.most_common()[1][1])
        elif a0==b0:
            if b.most_common()[1][1]>=a.most_common()[1][1]:
                print(n-a0[1]-b.most_common()[1][1])
            elif b.most_common()[1][1]<=a.most_common()[1][1]:
                print(n-b0[1]-a.most_common()[1][1])