Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=m

l=list()
c=2
while m>1:
  if m%c==0:
    l.append(c)
    m = m/c
  else:
    c+=1

e=[[x,l.count(x)] for x in set(l)]    

l2=[1]
for i in range(len(e)):
  for j in range(len(l2)):
    for k in range(e[i][1]):
      l2.append(l2[j]*e[i][0]**(k+1))

l2.sort()
m=1
for i in range(len(l2)):
  if a//n>=l2[i]:
    m=max(l2[i],m)

print(m)


Fixed submission:
n,m=map(int,input().split())

d=list()
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    d.append(i)
    if i!=m//i:
      d.append(m//i)

d.sort()

c=1
for i in range(len(d)):
  if m//d[i]>=n:
    c=max(d[i],c)

print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=m

l=list()
c=2
while m>1:
  if m%c==0:
    l.append(c)
    m = m//c
  else:
    c+=1

e=[[x,l.count(x)] for x in set(l)]    

l2=[1]
for i in range(len(e)):
  for j in range(len(l2)):
    for k in range(e[i][1]):
      l2.append(l2[j]*e[i][0]**(k+1))

l2.sort()
m=1
for i in range(len(l2)):
  if a//n>=l2[i]:
    m=max(l2[i],m)

print(m)


Fixed submission:
n,m=map(int,input().split())

d=list()
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    d.append(i)
    if i!=m//i:
      d.append(m//i)

d.sort()

c=1
for i in range(len(d)):
  if m//d[i]>=n:
    c=max(d[i],c)

print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=m

l=list()
c=2
while m>1:
  if m%c==0:
    l.append(c)
    m = m//c
  else:
    c+=1

e=[[x,l.count(x)] for x in set(l)]    

l2=[1]
for i in range(len(e)):
  for j in range(len(l2)):
    for k in range(e[i][1]):
      l2.append(l2[j]*e[i][0]**(k+1))

l2.sort()
m=1
for i in range(len(l2)):
  if a/l2[i]>=n:
    m=max(l2[i],m)

print(m)


Fixed submission:
n,m=map(int,input().split())

d=list()
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    d.append(i)
    if i!=m//i:
      d.append(m//i)

d.sort()

c=1
for i in range(len(d)):
  if m//d[i]>=n:
    c=max(d[i],c)

print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())

t=0
v=2*n//k

for apb in range(k,k*(v+1),k):
  for bpc in range(k,k*(v+1),k):
    for cpa in range(k,apb+bpc,k):
      if (apb+bpc+cpa)%2:
        continue
      a = (apb+bpc+cpa - 2*bpc)//2
      b = (apb+bpc+cpa - 2*cpa)//2
      c = (apb+bpc+cpa - 2*apb)//2
      if 0 < a and a <= n and 0 < b and b<=n and 0 < c and c <= n:
        t += 1

print(t)



Fixed submission:
n,k=map(int,input().split())

x = n//k
y = x if k%2 else n//(k//2)

print(x**3+(y-x)**3)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())

t=0
v=2*n//k

for apb in range(k,k*(v+1),k):
  for bpc in range(k,k*(v+1),k):
    for cpa in range(k,k*(v+1),k):
      if (apb+bpc+cpa)%2:
        continue
      a = (apb+bpc+cpa - 2*bpc)//2
      b = (apb+bpc+cpa - 2*cpa)//2
      c = (apb+bpc+cpa - 2*apb)//2
      if 0 < a and a <= n and 0 < b and b<=n and 0 < c and c <= n:
        t += 1

print(t)


Fixed submission:
n,k=map(int,input().split())

x = n//k
y = x if k%2 else n//(k//2)

print(x**3+(y-x)**3)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(x) for x in input().split()]
b=[0 for x in range(n+1)]

for i in range(1,n+1):
  b[i]=b[i-1]+a[i-1]

c=0
for i in range(1,n+1):
  for j in range(n-i+1):
    if (b[j+i]-b[j])%m == 0:
      c += 1

print(c)


Fixed submission:
n,m=map(int,input().split())
a=[int(x) for x in input().split()]
b=[0 for x in range(n+1)]
l=list([0])

for i in range(1,n+1):
  b[i]=b[i-1]+a[i-1]

for i in range(1,n+1):
  l.append(b[i]%m)

d=list()
l.sort()
t,c=0,1
for i in range(1,n+1):
  if l[i]==l[i-1]:
    c+=1
  else:
    if c!=1:
      t += c*(c-1)//2
      c=1

if c!=1:
  t += c*(c-1)//2  

print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]
 
for i in range(n):
  a[i] -= i+1
 
a.sort()
 
if n%2:
  s=0
  for i in range(n):
    s += abs(a[i]-a[n//2])
  print(s)
else:
  m=10**14
  for i in range(a[n//2-1],a[n//2]+1):
    s = 0
    for j in range(n):
      s += abs(a[j]-i)
    m = min(m,s)
  print(m)


Fixed submission:
n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]
 
for i in range(n):
  a[i] -= i+1
 
a.sort()
 
s = 0
for j in range(n):
  s += abs(a[j]-a[n//2])
print(s)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]
 
for i in range(n):
  a[i] -= i+1
 
a.sort()
 
if n%2:
　s=0
  for i in range(n):
    s += abs(a[i]-a[n//2])
  print(s)
else:
  m=10**14
  for i in range(a[n//2-1],a[n//2]+1):
    s = 0
    for j in range(n):
      s += abs(a[j]-i)
    m = min(m,s)
  print(s)


Fixed submission:
n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]
 
for i in range(n):
  a[i] -= i+1
 
a.sort()
 
s = 0
for j in range(n):
  s += abs(a[j]-a[n//2])
print(s)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]
 
for i in range(n):
  a[i] -= i+1
 
a.sort()
 
s=0
if s%2:
  for i in range(n):
    s += abs(a[i]-a[n//2])
  print(s)
else:
  m=10**14
  v=(a[n//2-1]+a[n//2])//2
  for i in range(v,v+2):
    s = 0
    for j in range(n):
      s += abs(a[j]-i)
    m = min(m,s)
  print(s)
n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]

for i in range(n):
  a[i] -= i+1

a.sort()

if n%2:
  s=0
  for i in range(n):
    s += abs(a[i]-a[n//2])
  print(s)
else:
  m=10**14
  v=(a[n//2-1]+a[n//2])//2
  for i in range(a[n//2-1],a[n//2]+1):
    s = 0
    for j in range(n):
      s += abs(a[j]-i)
    m = min(m,s)
  print(s)


Fixed submission:
n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]
 
for i in range(n):
  a[i] -= i+1
 
a.sort()
 
s = 0
for j in range(n):
  s += abs(a[j]-a[n//2])
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]

for i in range(n):
  a[i] -= i+1

a.sort()

s=0
if s%2:
  for i in range(n):
    s += abs(a[i]-a[n//2])
  print(s)
else:
  m=10**14
  for i in range(a[n//2-1], a[n//2]+1):
    s = 0
    for j in range(n):
      s += abs(a[j]-i)
    m = min(m,s)
  print(s)


Fixed submission:
n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]
 
for i in range(n):
  a[i] -= i+1
 
a.sort()
 
s = 0
for j in range(n):
  s += abs(a[j]-a[n//2])
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N,C=map(int,input().split())
D=[[int(x) for x in input().split()] for y in range(C)]
c=[[int(x)-1 for x in input().split()] for y in range(N)]

a=10**9
for c0 in range(C):
  for c1 in range(c0+1,C):
    for c2 in range(c1+1,C):
      s1,s2,s3=0,0,0
      for i in range(N):
        for j in range(N):
          m = (i+j+2)%3
          if m==0:
            s1 += D[c[i][j]][c0]
            s2 += D[c[i][j]][c1]
            s3 += D[c[i][j]][c2]
          elif m==1:
            s1 += D[c[i][j]][c1]
            s2 += D[c[i][j]][c2]
            s3 += D[c[i][j]][c0]
          else:
            s1 += D[c[i][j]][c2]
            s2 += D[c[i][j]][c0]
            s3 += D[c[i][j]][c1]
      a=min(a,s1,s2,s3)
print(a)


Fixed submission:
N,C=map(int,input().split())
D=[[int(x) for x in input().split()] for y in range(C)]
c=[[int(x)-1 for x in input().split()] for y in range(N)]

d=[[0 for x in range(C)] for y in range(3)]
for i in range(N):
  for j in range(N):
    d[(i+j)%3][c[i][j]] += 1

a=10**9
for c0 in range(C):
  for c1 in range(c0+1,C):
    for c2 in range(c1+1,C):
      s1,s2,s3,s4,s5,s6=0,0,0,0,0,0
      for c in range(C):
        s1 += d[0][c]*D[c][c0]+d[1][c]*D[c][c1]+d[2][c]*D[c][c2]
        s2 += d[0][c]*D[c][c0]+d[1][c]*D[c][c2]+d[2][c]*D[c][c1]
        s3 += d[0][c]*D[c][c1]+d[1][c]*D[c][c0]+d[2][c]*D[c][c2]
        s4 += d[0][c]*D[c][c1]+d[1][c]*D[c][c2]+d[2][c]*D[c][c0]
        s5 += d[0][c]*D[c][c2]+d[1][c]*D[c][c0]+d[2][c]*D[c][c1]
        s6 += d[0][c]*D[c][c2]+d[1][c]*D[c][c1]+d[2][c]*D[c][c0]
      a=min(a,s1,s2,s3,s4,s5,s6)
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[int(x) for x in input().split()]

b=[0]*20
c,l,r=0,0,0
for l in range(N):
  r=l
  b=[0]*20
  while r<N:
    for i in range(20):
      b[i]+=1 if (A[r]&2**i)!=0 else 0
    if max(b)<2:
      r+=1
      c+=1
    else:
      break
print(c)


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

r,S,R=0,0,0

for l in range(N):
  while r<N:
    if S&A[r]==0:
      S|=A[r]
      r+=1
    else:
      break
  R+=r-l
  S&=~A[l]

print(R)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[0]+[int(x) for x in input().split()]
B=[0 for i in range(N+1)]

for i in range(N):
  B[i+1]=A[i+1]^B[i]
  A[i+1]=A[i+1]+A[i]

c=0
for l in range(1,N+1):
  for r in range(l,N+1):
    if A[r]-A[l-1] == B[r]^B[l-1]:
      c += 1

print(c)


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

r,S,R=0,0,0

for l in range(N):
  while r<N:
    if S&A[r]==0:
      S|=A[r]
      r+=1
    else:
      break
  R+=r-l
  S&=~A[l]

print(R)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
e=[int(x)-1 for x in input().split()]
p=[i for i in range(N)]
r=[0]*N

def find(x):
	if p[x]!=x:
		p[x]=find(p[x])
	return p[x]

def unite(x,y):
	x=find(x)
	y=find(y)
	if x==y:
		return

	if r[x]<r[y]:
		p[x]=y
	else:
		p[y]=x
		if r[x]==r[y]:
			r[x]+=1

def same(x,y):
	return find(x)==find(y)

for i in range(M):
	x,y=map(int,input().split())
	unite(x-1,y-1)

c=0
for i in range(N):
	if same(i,e[i]):
		c+=1

print(c)


Fixed submission:
a,b,c,d=map(int,input().split())
print('Yes' if abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d) else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
e=[int(x)-1 for x in input().split()]
p=[i for i in range(N)]
r=[0]*N

def find(x):
	if p[x]!=x:
		p[x]=find(p[x])
	return p[x]

def unite(x,y):
	x=find(x)
	y=find(y)
	if x==y:
		return

	if r[x]<r[y]:
		p[x]=y
	else:
		p[y]=x
		if r[x]==r[y]:
			r[x]+=1

def same(x,y):
	return find(x)==find(y)

for i in range(M):
	x,y=map(int,input().split())
	unite(x-1,y-1)

l=list()
for i in range(N):
	f=False	
	for j in l:
		if j[0]==find(i):
			j[1].add(i)
			f=True
			break
	if not f:
		l.append([find(i),set([i])])

c=0
for i in l:
	for j in i[1]:
		if e[j] in i[1]:
			c+=1

print(c)


Fixed submission:
N,M=map(int,input().split())
e=[int(x)-1 for x in input().split()]
p=[i for i in range(N)]
r=[0]*N

def find(x):
	if p[x]!=x:
		p[x]=find(p[x])
	return p[x]

def unite(x,y):
	x=find(x)
	y=find(y)
	if x==y:
		return

	if r[x]<r[y]:
		p[x]=y
	else:
		p[y]=x
		if r[x]==r[y]:
			r[x]+=1

def same(x,y):
	return find(x)==find(y)

for i in range(M):
	x,y=map(int,input().split())
	unite(x-1,y-1)

c=0
for i in range(N):
	if same(i,e[i]):
		c+=1

print(c)
Buggy python submission (verdict: Time Limit Exceeded):
H,W,D=map(int,input().split())

def main():
  A=list()
  for h in range(H):
    for w,a in enumerate(map(int,input().split())):
      A.append([a,h,w])

  A=sorted(A, key=lambda x:x[0])

  Q=int(input())
  for q in range(Q):
    l,r=map(int,input().split())
    t,i=0,~-l  
    for j in range((r-l)//D):
      t+=abs(A[i][1]-A[i+D][1])+abs(A[i][2]-A[i+D][2])
      i+=D
    print(t)

main()


Fixed submission:
H,W,D=map(int,input().split())

def main():
  A=list()
  for h in range(H):
    for w,a in enumerate(map(int,input().split())):
      A.append([a,h,w])

  A=sorted(A, key=lambda x:x[0])

  B=[0]*(H*W)
  for i in range(D):
    while i+D<W*H:
      B[i+D]=B[i]+abs(A[i][1]-A[i+D][1])+abs(A[i][2]-A[i+D][2])
      i+=D

  for q in range(int(input())):
    l,r=map(int,input().split())
    print(B[~-r]-B[~-l])

main()

Buggy python submission (verdict: Time Limit Exceeded):
H,W,D=map(int,input().split())

A=list()
for h in range(H):
  for w,a in enumerate(map(int,input().split())):
    A.append([a,h,w])

A=sorted(A, key=lambda x:x[0])

Q=int(input())
for q in range(Q):
  l,r=map(int,input().split())
  t,i=0,~-l  
  for j in range((r-l)//D):
    t+=abs(A[i][1]-A[i+D][1])+abs(A[i][2]-A[i+D][2])
    i+=D
  print(t)


Fixed submission:
H,W,D=map(int,input().split())

def main():
  A=list()
  for h in range(H):
    for w,a in enumerate(map(int,input().split())):
      A.append([a,h,w])

  A=sorted(A, key=lambda x:x[0])

  B=[0]*(H*W)
  for i in range(D):
    while i+D<W*H:
      B[i+D]=B[i]+abs(A[i][1]-A[i+D][1])+abs(A[i][2]-A[i+D][2])
      i+=D

  for q in range(int(input())):
    l,r=map(int,input().split())
    print(B[~-r]-B[~-l])

main()
Buggy python submission (verdict: Runtime Error):
s = input()
if s[-1] == 's':
  print(s + 'es')
else:
  print(s + 's')


Fixed submission:
s = input()
if s[-1] == 's':
  print(s + 'es')
else:
  print(s + 's')
Buggy python submission (verdict: Runtime Error):
s = input()
if s[3] == s[4] and s[5] == s[6]:
  print('Yes')
else:
  print('No')

Fixed submission:
s = input()
if s[2] == s[3] and s[4] == s[5]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a >= 13 :
  print(b)
elif a >= 6 :
  print(b//2)
else :
  print(0)

Fixed submission:
a, b = map(int, input().split())
if a >= 13 :
  print(b)
elif a >= 6 :
  print(b//2)
else :
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
r,b,g,m = map(int,input().split())
ans = 0
for i in range(3001):
  for j in range(3001):
    if m >= r*i+b*j and (m-r*i-b*j)%g == 0:
      ans += 1
print(ans)

Fixed submission:
r,b,g,m = map(int,input().split())
ans = 0
for i in range(3001):
  for j in range(3001):
    if m >= r*i+b*j and (m-r*i-b*j)%g == 0:
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(string,input().split())
if a[-1] == b[0] and b[-1] == c[0]:
  print('YES')
else :
  print('NO')

Fixed submission:
a,b,c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
  print('YES')
else :
  print('NO')
Buggy python submission (verdict: Runtime Error):
S = input()

even = set({})
odd = set({})
for i in range(len(S)):
    if i % 2 == 0:
        even.add(S[i])
    else:
        odd.add(S[i])
print(even, odd)

if (not "R" in odd) and (not "L" in even):
    print("Yes")
else:
    print("No"

Fixed submission:
S = input()

even = set({})
odd = set({})
for i in range(len(S)):
    if i % 2 == 0:
        even.add(S[i])
    else:
        odd.add(S[i])
#print(even, odd)

if (not "R" in odd) and (not "L" in even):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n % 9 == 0:
    print("Yes")
else:
    pritn("No")

Fixed submission:
n = int(input())
if n % 9 == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
a = input()
l = list(map(int,input().split()))
ans = 1

for i in l:
    ans *= i
if ans > 10**18:
    ans=-1
print(ans)

Fixed submission:

a = input()
l = list(map(int,input().split()))
ans = 1
if 0 in l:
    print(0)
    exit()
for i in l:
    ans *= i
    if ans>10**18:
        print(-1)
        exit()
if ans > 10**18:
    ans=-1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())

l = list(map(int,input().split()))
ans = 1

for i in l:
    ans *= i
if ans > 10**18:
    ans=-1
print(ans)

Fixed submission:

a = input()
l = list(map(int,input().split()))
ans = 1
if 0 in l:
    print(0)
    exit()
for i in l:
    ans *= i
    if ans>10**18:
        print(-1)
        exit()
if ans > 10**18:
    ans=-1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
A = list(map(int,input().split()))
dp = [0] * (n+1)
B = []
f = 1
c = 0
for e,i in enumerate(A,1):
    if dp[f-1] or i == 1:
        ans = e-dp[f-1]
        bal = dp[f-1]
        break
    else:
        dp[f-1]+=c
        B.append(A[f-1])
        f = A[f-1]
        c+=1
k-= bal
# print(bal,ans)
B = B[bal:ans+1]
# print(dp)
k = (k%ans+1)%ans
print(B[k])

Fixed submission:
n,k = map(int,input().split())
A = list(map(int,input().split()))
dp = [-1] * (n+1)
B = []
f = 1
c = 0
ans = n
bal = 0
while dp[f-1] == -1:
    dp[f-1] =c
    B.append(f)
    f = A[f-1]
    c +=1
t = B.index(f)
if k>t:
    k -= t
    B = B[B.index(f):]
    k%=len(B)
    print(B[k])
else:
    print(B[k])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = 0
for e,i in enumerate(a):
    c = 1
    for f,j in enumerate(a[e+1:]):
        if c == i+j:
            # print(e,f,i,j)
            ans +=1
        # print(e,f,i,j)
        c+=1
print(ans)


Fixed submission:
n = int(input())
from collections import defaultdict
a = list(map(int,input().split()))
ans = 0
dp = defaultdict(int)
for e,i in enumerate(a,1):
    if  e - i>= 0 :ans += dp[e-i]
    dp[i+e]+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
    if a%b == 0:
        return b
    else :
        return gcd(b,a%b)

k = int(input())

ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for h in range(1,k+1):
            t = gcd(i,j)
            t = gcd(t,h)
            ans += t
print(ans)


Fixed submission:
def gcd(a,b):
    if a%b == 0:
        return b
    else :
        return gcd(b,a%b)

k = int(input())

ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for h in range(1,k+1):
            t = gcd(i,j)
            t = gcd(t,h)
            ans += t
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())

for i in range(n):
    t = list(map(str,input().split()))
    if t[0] == '1':
        s = s[::-1]
    else:
        if t[1] == '1':
            s = s[::-1] + t[2]
            s = s[::-1]
        else:
            s = s + t[2]
            
print(s)

Fixed submission:
s = input()
T = ""
n = int(input())
for i in range(n):
    # print(s,T)
    t = list(map(str,input().split()))
    if t[0] == "1":
        s,T = T,s
    else:
        if t[1] == "1":
            T += t[2]
        else:
            s += t[2]

print(T[::-1]+s)
Buggy python submission (verdict: Time Limit Exceeded):
H,N =map(int, input().split())
a = [] 
M = 0 
for i in range(N):
	t = list(map(int, input().split()))
	a.append(t)
	M = max(M,t[0])
dp = [100000000]*(H+1+M)
dp[0] = 0
for i in range(H):
	for j,k in a:
		dp[i+j] = min(dp[i+j],dp[i]+k)

print(min(dp[H:]))

Fixed submission:
H,N =map(int, input().split())
a = [] 
M = 0 
for i in range(N):
	t = list(map(int, input().split()))
	a.append(t)
	M = max(M,t[0])
dp = [100000000]*(H+1+M)
dp[0] = 0
for i in range(H):
	for j,k in a:
		dp[i+j] = min(dp[i+j],dp[i]+k)

print(min(dp[H:]))

Buggy python submission (verdict: Runtime Error):
H,N =map(int, input().split())
a = [] 
M = 0 
for i in range(N):
	t = list(map(int, input().split()))
	a.append(t)
	M = max(M,t[0])
dp = [10000]*(H+1)
dp[0] = 0
for i in range(1,H+M):
	for j,k in a:
		dp[i+j] = min(dp[i+j],dp[i]+k)

print(min(dp[H:]))

Fixed submission:
H,N =map(int, input().split())
a = [] 
M = 0 
for i in range(N):
	t = list(map(int, input().split()))
	a.append(t)
	M = max(M,t[0])
dp = [100000000]*(H+1+M)
dp[0] = 0
for i in range(H):
	for j,k in a:
		dp[i+j] = min(dp[i+j],dp[i]+k)

print(min(dp[H:]))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline
    from fractions import gcd
    a = int(input())
    l = list(map(int,input().split()))



    def lcm(a,b):
        return a*b//gcd(a,b)

    MOD = 10**9+7
    ans = 0
    t = 1
    for i in l:
        t = lcm(t,i)

    for i in l:
        ans +=t//i
        ans %=MOD
    print(ans)
main()

Fixed submission:
def main():
    from fractions import gcd
    a = int(input())
    l = list(map(int,input().split()))



    def lcm(a,b):
        return a*b//gcd(a,b)
    A= 1
    MOD = 10**9+7
    ans = 0
    t = 1
    for i in l:
        t = t* i //gcd(t,i)
    for i in l:
        ans +=t//i
    ans %=MOD
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):

a = int(input())
l = list(map(int,input().split()))

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a


def lcm(a,b):
    return a*b//gcd(a,b)

MOD = 10**9+7
ans = 0
t = 1
for i in l:
    t = lcm(t,i)

for i in l:
    ans +=t//i
    ans %=MOD
print(ans)

Fixed submission:
def main():
    from fractions import gcd
    a = int(input())
    l = list(map(int,input().split()))



    def lcm(a,b):
        return a*b//gcd(a,b)
    A= 1
    MOD = 10**9+7
    ans = 0
    t = 1
    for i in l:
        t = t* i //gcd(t,i)
    for i in l:
        ans +=t//i
    ans %=MOD
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):

a = int(input())
l = list(map(int,input().split()))

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a


def lcm(a,b):
    return a*b//gcd(a,b)

MOD = 10**9+7
ans = 0
t = 1
for i in l:
    t = lcm(t,i)

for i in l:
    ans +=t//i
    ans %=MOD
print(ans)

Fixed submission:
def main():
    from fractions import gcd
    a = int(input())
    l = list(map(int,input().split()))



    def lcm(a,b):
        return a*b//gcd(a,b)
    A= 1
    MOD = 10**9+7
    ans = 0
    t = 1
    for i in l:
        t = t* i //gcd(t,i)
    for i in l:
        ans +=t//i
    ans %=MOD
    print(ans)
main()
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
dp = [0]*(100010)
qp = [0]*(100010)
for i in range(b):
    ta,tb = map(str,input().split())
    ta = int(ta)
    if qp[ta] == 0 :
        if tb == 'WA':dp[ta]+=1
        else qp[ta]=1
print(sum(qp),sum(dp))

Fixed submission:

a,b = map(int,input().split())
dp = [0]*(100010)
qp = [0]*(100010)
for i in range(b):
    ta,tb = map(str,input().split())
    ta = int(ta)
    if qp[ta] == 0 :
        if tb == 'WA':
            dp[ta]+=1
        else :
            qp[ta]=1
ANS = 0
for i, j in zip(dp,qp):
    ANS += i*j
print(sum(qp),ANS)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())

if c<a:
    print(a-c,b)
else:
    print(0,b+a-c)

Fixed submission:
a,b = map(str,input().split())
print(b+a)
Buggy python submission (verdict: Runtime Error):
if (b-a)%2==0:
    print((b-a)//2) 
else:
    m = min(b-1,n-a)
    M = min(a-1,n-b)+(b-a-1)//2
    print(min(m,M))

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

if (b-a)%2==0:
    print((b-a)//2) 
else:
    m = min(b-1,n-a)
    M = min(a-1,n-b)+(b-a-1)//2+1
    print(min(m,M))
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int a,b,c;
	cin >> a >> b >> c;
	string ans = "win";
	if (a+b+c>21) ans = "bust";
  cout << ans << endl;
}


Fixed submission:

l = list(map(int,input().split()))
if sum(l) <= 21:
    print('win')
else:
    print('bust')