Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
d=input().split()
while 1:
    t=0
    p=list(str(n))
    q=len(p)
    for c in range(q):
        if t==1:
            break
        for b in range(k):
            if p[c]==d[b]:
                n=n+10**c
                t=1
                break
    if t==0:
        break
print(n)

Fixed submission:
n,k=map(int,input().split())
d=input().split()
while 1:
    t=0
    p=list(str(n))
    q=len(p)
    for c in range(q):
        if t==1:
            break
        for b in range(k):
            if p[c]==d[b]:
                n=n+1
                t=1
                break
    if t==0:
        break
print(n)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ct = 0
for a in range(1, N):
    for b in range(1, N):
        if a*b >= N:
            break
        ct += 1
        
print(ct)

Fixed submission:
N = int(input())

ct = 0
for i in range(1, N):
    if i * i >= N:
        break
    x = int((N - 1)/i)
    ct += (x - i)*2 + 1
print(ct)
Buggy python submission (verdict: Runtime Error):
import math

A, B, H, M = map(int, input().split())

H_angle = 30*H + 0.5*M # (360/(12*60)) * ((60*H)+M)
M_angle = 6*M          # 360/60 * H
HM_angle = abs(H_angle - M_angle)

if HM_angle == 0:
    print(abc(A-B))
elif HM_angle == 180:
    print(A+B)
else:
    if HM_angle > 180 :
        HM_angle -= 180
    print((A**2 + B**2 - 2*A*B*math.cos(math.radians(HM_angle)))**0.5)

Fixed submission:
import math

A, B, H, M = map(int, input().split())

H_angle = 30*H + 0.5*M # (360/(12*60)) * ((60*H)+M)
M_angle = 6*M          # 360/60 * H
HM_angle = abs(H_angle - M_angle)

if HM_angle == 0:
    print(abs(A-B))
elif HM_angle == 180:
    print(A+B)
else:
    print((A**2 + B**2 - 2*A*B*math.cos(math.radians(HM_angle)))**0.5)
Buggy python submission (verdict: Runtime Error):
import collections

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

v1 = v[::2]
v2 = v[1::2]

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)

if v1 == v2 and len(c1.most_common()) == 1
    print(len(v1))
elif c1.most_common()[0][0] != c2.most_common()[0][0]:
    print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[0][1])
else:
    if c1.most_common()[1][1] < c2.most_common()[1][1]:
        print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[1][1])
    else:
        print(len(v1) - c1.most_common()[1][1] + len(v2) - c2.most_common()[0][1])

Fixed submission:
import collections

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

v1 = v[::2]
v2 = v[1::2]

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)

if (v1 == v2 and len(c1.most_common()) == 1):
    print(len(v1))
elif c1.most_common()[0][0] != c2.most_common()[0][0]:
    print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[0][1])
else:
    if c1.most_common()[1][1] < c2.most_common()[1][1]:
        print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[1][1])
    else:
        print(len(v1) - c1.most_common()[1][1] + len(v2) - c2.most_common()[0][1])
Buggy python submission (verdict: Runtime Error):
S=int(input())
a = [0]*(S+1)
a[3]=1
for i in range(4, S+1):
  a[i] = a[i-3] + a[i-1]
mod=10**9+7
print(a[S]%mod)

Fixed submission:
S=int(input())
a = [0]*(2000+1)
a[3]=1
for i in range(4, S+1):
  a[i] = a[i-3] + a[i-1]
mod=10**9+7
print(a[S]%mod)
Buggy python submission (verdict: Runtime Error):
import sys
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

for i in range(1,n):
  a[i] += a[i-1]
for i in range(1,m):
  b[i] += b[i-1]
a_max = 0
for i in range(n, 0, -1)
  if a[i-1] <= k:
    a_max = i
    break
b_max = 0
for i in range(m, 0, -1)
  if a[i-1] <= k:
    b_max = i
    break
    
ans = 0
for i in range(a_max, 0, -1):
  p = 0
  q = 0
  if a[i-1] <= k:
    p = a[i-1]
    q = i
  for j in range(b_max, 0, -1):
    if p + b[j-1] <= k:
      ans = max(ans, q + j)
    
print(ans)

Fixed submission:
import sys
n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(n):
  a.append(a[i] + A[i])
for i in range(m):
  b.append(b[i] + B[i])

ans = 0
j = m
for i in range(n + 1):
  if a[i] > k:
    break
  while a[i] + b[j] > k:
      j -= 1
  ans = max(ans, i + j)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b=list(map(int, input()))
print((a-1)/(2*b + 1)/1)

Fixed submission:
a, b=list(map(int, input().split()))
print(int((a-1)/(2*b + 1))+1)
Buggy python submission (verdict: Runtime Error):
import math
import sys

n = input()
a = list(map(int, input().split()))
b = sorted(a)
c = set(b)
if len(c) == 1:
  print(c[0])
  sys.exit()
pl = []
ql = []
for i in b[1:]:
  pl.append(math.gcd(b[0], i))
for i in b[2:]:
  ql.append(math.gcd(b[1], i))
pls = sorted(pl)
qls = sorted(ql)
if len(qls) == 0:
  print(pls[min(1, len(pls) - 1)])
else:
  print(max(pls[min(1, len(pls) - 1)], qls[0]))

Fixed submission:
import math
import itertools

n = int(input())
a = list(map(int, input().split()))
pf = [0]*(n+1)
pb = [0]*(n+1)
p = a[0]
for i in range(n):
  p = math.gcd(p, a[i])
  pf[i+1] = p
p = a[-1]
for i in range(-1, -n-1, -1):
  p = math.gcd(p, a[i])
  pb[i-1] = p
ans = [0]*n
for i in range(n):
  ans[i] = math.gcd(pf[i], pb[i+1])
print(max(ans))

Buggy python submission (verdict: Runtime Error):
import math
import sys

n = input()
a = list(map(int, input().split()))
b = sorted(set(a))
if len(b) == 1:
  print(b[0])
  sys.exit()
pl = []
ql = []
for i in b[1:]:
  pl.append(math.gcd(b[0], i))
for i in b[2:]:
  ql.append(math.gcd(b[1], i))
pls = sorted(pl)
qls = sorted(ql)
print(max(pls[1], qls[min(1, len(qls) - 1)]))


Fixed submission:
import math
import itertools

n = int(input())
a = list(map(int, input().split()))
pf = [0]*(n+1)
pb = [0]*(n+1)
p = a[0]
for i in range(n):
  p = math.gcd(p, a[i])
  pf[i+1] = p
p = a[-1]
for i in range(-1, -n-1, -1):
  p = math.gcd(p, a[i])
  pb[i-1] = p
ans = [0]*n
for i in range(n):
  ans[i] = math.gcd(pf[i], pb[i+1])
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N,Ma,Mb=map(int, input().split())
A = []
B = []
C = []
for i in range(N):
  a,b,c=map(int, input().split())
  A.append(a)
  B.append(b)
  C.append(c)
sa = sum(A)
sb = sum(B)

dp = [[[10000]*(sb+1) for _ in range(sa+1)] for _ in range(N+1)]
dp[0][0][0] = 0

ta = 0
tb = 0
for i in range(N):
  a = A[i]
  b = B[i]
  for j in range(sa):
    for k in range(sb):
      if j - a >= 0 and k - b >= 0:
        dp[i+1][j][k] = min(dp[i][j-a][k-b]+C[i], dp[i][j][k])
      else:
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])

dnp = dp[N]
ans = 10000
for i in range(sa):
  for j in range(sb):
    if Ma * (j+1) == Mb * (i+1):
      ans = min(ans, dnp[i+1][j+1])
if ans == 10000:
  ans = -1
print(ans)

Fixed submission:
N,Ma,Mb=map(int, input().split())
A = []
B = []
C = []
for i in range(N):
  a,b,c=map(int, input().split())
  A.append(a)
  B.append(b)
  C.append(c)
sa = sum(A)
sb = sum(B)

dp = [[[10000]*(sb+1) for _ in range(sa+1)] for _ in range(N+1)]
dp[0][0][0] = 0

ta = 0
tb = 0
for i in range(N):
  a = A[i]
  b = B[i]
  for j in range(sa):
    for k in range(sb):
      if j - a >= 0 and k - b >= 0:
        dp[i+1][j][k] = min(dp[i][j-a][k-b]+C[i], dp[i][j][k])
      else:
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])

ans = 10000
for i in range(1, sa+1):
  for j in range(1, sb+1):
    if Ma * j == Mb * i:
      ans = min(ans, dp[N][i][j])
if ans == 10000:
  ans = -1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())

count=0
for a in range(1,n+1):
    for b in range(1,n//a+1):
        c=n-(a*b)
        if c>0:
            count+=1
        else:
            continue

print(count)

Fixed submission:
n=int(input())

count=0
for a in range(1,n+1):
    for b in range(a,n//a+1):
        c=n-(a*b)
        if c>0:
            if a==b:
                count+=1
            else:
                count+=2
        else:
            continue

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

x=[]
while N>0:
    x.append(N%10)
    N=N//10

sum=sum(x)
if sum%9==0:
    print("Yes")
else:
    print("No")


Fixed submission:
N=int(input())

result=sum(list(map(int, str(N))))
if result%9==0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(1,n):
    if x[i]<x[i-1]:
        t=x[i-1]-x[i]
        sum+=t
        x[i]=x[i-1]

print(sum)


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

sum=0
MaxNum=0
for i in range(N):
    MaxNum=max(MaxNum,A[i])
    B=MaxNum
    sum+=MaxNum-A[i]
    
print(sum)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(1,n):
    if x[i]<x[i-1]:
        t=x[i-1]-x[i]
        sum+=t

print(sum)

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

sum=0
MaxNum=0
for i in range(N):
    MaxNum=max(MaxNum,A[i])
    B=MaxNum
    sum+=MaxNum-A[i]
    
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

sum=0
while 1:
    max_A=max(A)
    max_index=np.argmax(A)
    A_new=A[max_index:]
    for a in A_new:
        sum+=max_A-a
    A=A[:max_index]
    if max_index==0:
        break

print(sum)

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

sum=0
MaxNum=0
for i in range(N):
    MaxNum=max(MaxNum,A[i])
    B=MaxNum
    sum+=MaxNum-A[i]
    
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

x=[0]
for i in range(N-1):
    if max(A[:i+1])<=A[i+1]:
        x.append(0)
    else:
        x.append(max(A[:i+1])-A[i+1])

print(sum(x))

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

sum=0
MaxNum=0
for i in range(N):
    MaxNum=max(MaxNum,A[i])
    B=MaxNum
    sum+=MaxNum-A[i]
    
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,M=map(int,input().split())
A=list([int(input()) for _ in range(M)])

mod=10**9+7

dp=np.zeros(N+1)
dp[0]=1
if 1 not in A:
    dp[1]=1
else:
    dp[1]=0

for i in range(2,N+1):
    if i in A:
        continue
    dp[i]=dp[i-1]+dp[i-2]
    dp[i]%=mod

print(int(dp[N]))

Fixed submission:
N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,M=map(int,input().split())
A=[]
for _ in range(M):
    A.append(int(input()))

mod=10**9+7

dp=[0]*(N+1)
dp[0]=1
if 1 not in A:
    dp[1]=1
else:
    dp[1]=0

for i in range(2,N+1):
    if i in A:
        continue
    dp[i]=dp[i-1]+dp[i-2]
    dp[i]%=mod

print(int(dp[N]))

Fixed submission:
N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,M=map(int,input().split())
A=[]
for _ in range(M):
    A.append(int(input()))

mod=10**9+7

dp=np.zeros(N+1)
dp[0]=1
if 1 not in A:
    dp[1]=1
else:
    dp[1]=0

for i in range(2,N+1):
    if i in A:
        continue
    dp[i]=dp[i-1]+dp[i-2]
    dp[i]%=mod

print(int(dp[N]))

Fixed submission:
N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,M=map(int,input().split())
A=[]
for _ in range(M):
    A.append(int(input()))

mod=10**9+7

dp=np.zeros(N+1)
dp[0]=1
for i in range(1,N+1):
    if i in A:
        dp[i]=0
    else:
        if i==1:
            dp[i]=dp[i-1]
        else:
            dp[i]=dp[i-1]+dp[i-2]
            dp[i]=dp[i]%mod
dp[N]=dp[N]%mod
print(int(dp[N]))

Fixed submission:
N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])
Buggy python submission (verdict: Runtime Error):
x,y = map(int,input().split())

for i in range(X):
  for j in range(X):
    if 2*i+4*j == Y:
      print("Yes")
      exit()

print("No")

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

for i in range(x+1):
  for j in range(x+1):
    if 2*i+4*j == y and i+j == x:
      print("Yes")
      exit()

print("No")
Buggy python submission (verdict: Runtime Error):
import math

A, B, H, M = map(int,input().split())


timeA = H + (M/60)
argA = (1/12)*timeA

argB = (1/60)*M


sitaA = 360*argA
sitaB = 360*argB



if argA == argB:
  print(abs(B-A))
elif argA > argB:
  c = math.sqrt(A**2 + B**2 - abs((2*A*B*math.cos(math.radians(sitaA-sitaB)))))
elif argA < argB:
  c = math.sqrt(A**2 + B**2 - abs((2*A*B*math.cos(math.radians(sitaB-sitaA)))))

print(c)  

Fixed submission:
import math

A, B, H, M = map(int,input().split())

c = 0
timeA = H + (M/60)
argA = (1/12)*timeA

argB = (1/60)*M


sitaA = 360*argA
sitaB = 360*argB



if abs(sitaA-sitaB) == 180:
  print(A+B)
  exit()



if sitaA == sitaB:
  print(abs(B-A))
  exit()
elif sitaA > sitaB:
  c = math.sqrt(A**2 + B**2 - (2*A*B*math.cos(math.radians(sitaA-sitaB))))
elif sitaA < sitaB:
  c = math.sqrt(A**2 + B**2 - (2*A*B*math.cos(math.radians(sitaB-sitaA))))

print(c)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

A =[]

for i in range(M):
  A.append(int(input().split()))

gokei = int(sum(A))

if N - gokei < 0:
  print('-1')

else:
  print(N - gokei)

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

A =[]

A = map(int,input().split())

gokei = int(sum(A))

if N - gokei < 0:
  print('-1')

else:
  print(N - gokei)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

A =[]

for i in range(M):
  A.append(input())

gokei = int(sum(A))

if N - gokei < 0:
  print('-1')

else:
  print(N - gokei)

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

A =[]

A = map(int,input().split())

gokei = int(sum(A))

if N - gokei < 0:
  print('-1')

else:
  print(N - gokei)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
c = 0
for i in range(1,N):
  for j in range(1,N):
    if i*j >= N:
      break
    c += 1
print(c)

Fixed submission:
N = int(input())
c = 0
for i in range(1,N):
  if i**2 >= N:
    break
  c += 1
for i in range(1,N):
  for j in range(i+1,N):
    if i*j >= N:
      break
    c += 2
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
c = 0

for i in range(1,N):
  for j in range(1,N):
    if i*j >= N:
      break
    else:
      c += 1
print(c)

Fixed submission:
N = int(input())
c = 0
for i in range(1,N):
  if i**2 >= N:
    break
  c += 1
for i in range(1,N):
  for j in range(i+1,N):
    if i*j >= N:
      break
    c += 2
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
c = 0

for C in range(1,N):
  NC = N-C
  for A in range(1,N-C+1):
    if (NC / A) % 1 == 0:
      #print(A,B,C)
      c += 1

print(c)

Fixed submission:
N = int(input())
c = 0
for i in range(1,N):
  if i**2 >= N:
    break
  c += 1
for i in range(1,N):
  for j in range(i+1,N):
    if i*j >= N:
      break
    c += 2
print(c)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
sum = 0

#累積和、二乗和の両方で1項ずつ求めてmodをとる
for x in A:
  sum += x
  sum %= (10**9+7)
#sum = A.sum() % (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)
#sum2 = (A**2).sum() % (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))


Fixed submission:
D, T, S = [int(i) for i in input().split()]

if(D/S <= T):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]
ans = 0

for i in range(len(A)):
  for j in range(i+1, len(A)):
    ans += A[i]*A[j]
    if ans > 10**9+7:
      ans %= 10**9+7
print(ans)


Fixed submission:
import numpy as np

N = int(input())
A = [int(i) for i in input().split()]
sum = 0
for x in A:
  sum += x
  sum %= (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]
ans = 0

for i in range(len(A)):
  for j in range(i+1, len(A)):
    ans += A[i]*A[j]
    if ans > 10**9+7:
      ans %= 10**9+7
print(ans)

Fixed submission:
import numpy as np

N = int(input())
A = [int(i) for i in input().split()]
sum = 0
for x in A:
  sum += x
  sum %= (10**9+7)

sum2 = 0
for x in A:
  sum2 += x*x
  sum2 %= (10**9+7)

ans = (sum**2 - sum2) % (10**9+7)
if ans < 0:
  ans += (10**9+7)
ans *= int((10**9+7+1)/2) 
ans %= (10**9+7)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
S = input()
max = 0
i = 0
m = 0
while(i != len(S)):
  if S[i] == "R":
    m += 1
  
  else:
    max = max(max,m)
    m = 0
    break
  i += 1

print(max)

Fixed submission:
s = input()
count = 0
ans = 0

for i in range(len(s)):
  if(s[i] == "R"):
    count += 1
  else:
    ans = max(count, ans)
    count = 0
ans = max(count, ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(a*b)

Fixed submission:
a, b = [int(i) for i in input().split()]
print(a*b)

Buggy python submission (verdict: Runtime Error):
a = input()
b = input() 
print(a*b)

Fixed submission:
a, b = [int(i) for i in input().split()]
print(a*b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]
product = 1

for i in range(n):
  product *= A[i]

if(product - 10**18 > 0):
    print("-1")
else:
  print(product)

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]
product = 1
A.sort()

for i in range(n):
  product *= A[i]
  if(product > 10**18):
    print("-1")
    break

if(product <= 10**18):
  print(product)
Buggy python submission (verdict: Runtime Error):
N, M, X = [int(i) for i in input().split()]
CA = []
for i in range(N):
    CA.append([int(j) for j in input().split()])
#print(CA)
mcost = 10**10


for i in range(2**N):
    learn = [0]*M
    cost = 0
    bn = str(bin(i))[2:].zfill(M)
    #print(bn)
    for j,b in enumerate(bn):
        if b == "1":
            cost += CA[j][0]
            for m in range(M):
                learn[m] += CA[j][m+1]
                
    learn.sort()
    if learn[0] >= X:
        mcost = min(mcost, cost)

if mcost == 10**10:
    mcost = -1

print(mcost)

Fixed submission:
N, M, X = [int(i) for i in input().split()]
CA = []
for i in range(N):
    CA.append([int(j) for j in input().split()])
#print(CA)
mcost = 10**10


for i in range(2**N):
    learn = [0]*M
    cost = 0
    bn = str(bin(i))[2:].zfill(N)
    #print(bn)
    for j,b in enumerate(bn):
        if b == "1":
            cost += CA[j][0]
            for m in range(M):
                learn[m] += CA[j][m+1]
                
    learn.sort()
    #print(learn)
    if learn[0] >= X:
        mcost = min(mcost, cost)

if mcost == 10**10:
    mcost = -1

print(mcost)
Buggy python submission (verdict: Runtime Error):
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
check = [0]*N
ima = 0
for i in range(K):
  if check[A[ima]-1] != 0:
    loopen = ima
    check[ima] = i+1
    looplen = check[ima] - check[A[ima]-1] + 1
    loopend = i
    break
  check[ima] = i+1
  ima = A[ima]-1
offset = (K-(i-looplen)-1)%looplen
ima = 0
for i in range(loopend-looplen+offset+1):
  ima = A[ima]-1
print(ima+1)


Fixed submission:
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
check = [0]*N
ima = 0

for i in range(K):
  if check[A[ima]-1] != 0:
    loopen = ima
    check[ima] = i+1
    looplen = check[ima] - check[A[ima]-1] + 1
    loopend = i
    break
  if i == K-1:
    print(A[ima])
    exit()
  check[ima] = i+1
  ima = A[ima]-1

offset = (K-(i-looplen)-1)%looplen
ima = 0
for i in range(loopend-looplen+offset+1):
  ima = A[ima]-1
print(ima+1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
B.append(0)

ans = 0
for i in range(N+1):
  taosukazu1 = min(A[i],B[i])
  B[i] -= taosukazu1
  A[i] -= taosukazu1
  ans += taosukazu1
  print(A)
  print(B)
  if B[i] > 0:
    taosukazu2 = min(A[i+1],B[i])
    B[i] -= taosukazu2
    A[i] -= taosukazu2
    ans += taosukazu2
print(ans)

Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
B.append(0)

ans = 0
for i in range(N+1):
  taosukazu1 = min(A[i],B[i])
  B[i] -= taosukazu1
  A[i] -= taosukazu1
  ans += taosukazu1
  if B[i] > 0:
    taosukazu2 = min(A[i+1],B[i])
    B[i] -= taosukazu2
    A[i+1] -= taosukazu2
    ans += taosukazu2
print(ans)
Buggy python submission (verdict: Runtime Error):
HW = list(map(int, input().split))
hw = list(map(int, input().split))

print(HW[0]*HW[1] - hw[0]*HW[1] - HW[0]*hw[1] + hw[0]*hw[1])

Fixed submission:
HW = list(map(int, input().split()))
hw = list(map(int, input().split()))
 
print(HW[0]*HW[1] - hw[0]*HW[1] - HW[0]*hw[1] + hw[0]*hw[1])
Buggy python submission (verdict: Runtime Error):
abk = list(map(int,input().split()))

x=[]
for i in range(1,100):
    if(abk[0]%i==0 and abk[1]%i==0):
        x.append(i)

print(x[-2])

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

x=[]
for i in range(1,101):
    if(abk[0]%i==0 and abk[1]%i==0):
        x.append(i)
print(x[-abk[2]])
Buggy python submission (verdict: Time Limit Exceeded):
N,K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [10**10]*(N+1)
dp[1] = 0
dp[2] = abs(h[0] - h[1])

for i in range(3,N+1):
  Kl = max(1,i-K)
  dp[i] = min([dp[j]+abs(h[j-1] - h[i-1]) for j in range(Kl, i)])
print(dp[N])

Fixed submission:
N,K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [10**10]*(N+1)
dp[1] = 0
dp[2] = abs(h[0] - h[1])

for i in range(3,N+1):
  Kl = max(1,i-K)
  dp[i] = min([dp[j]+abs(h[j-1] - h[i-1]) for j in range(Kl, i)])
print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [10**10]*(N+1)
dp[1] = 0
dp[2] = abs(h[0] - h[1])

for i in range(3,N+1):
  Kl = max(1,i-K)
  #print(Kl,i-K,i)
  fr = [dp[j]+abs(h[j-1] - h[i-1]) for j in range(Kl,i)]
  #print(fr)
  dp[i] = min(fr)
print(dp[N])

Fixed submission:
N,K = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [10**10]*(N+1)
dp[1] = 0
dp[2] = abs(h[0] - h[1])

for i in range(3,N+1):
  Kl = max(1,i-K)
  dp[i] = min([dp[j]+abs(h[j-1] - h[i-1]) for j in range(Kl, i)])
print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = [int(i) for i in input().split()]
wv = []
for i in range(N):
  wv.append([int(i) for i in input().split()])
dp = [[0 for i in range(W+1)] for j in range(N+1)]
#print(wv)

for i in range(1,N+1):
  for w in range(W+1):
    #print(i,w)
    if w >= wv[i-1][0]:
      dp[i][w] = max(dp[i-1][w], dp[i-1][w-wv[i-1][0]] + wv[i-1][1])
    else:
      dp[i][w] = dp[i-1][w]
print(dp[N][W])


Fixed submission:
N, W = [int(i) for i in input().split()]
wv = []
for i in range(N):
  wv.append([int(i) for i in input().split()])
dp = [[0 for i in range(W+1)] for j in range(N+1)]
#print(wv)

for i in range(1,N+1):
  for w in range(W+1):
    #print(i,w)
    if w >= wv[i-1][0]:
      dp[i][w] = max(dp[i-1][w], dp[i-1][w-wv[i-1][0]] + wv[i-1][1])
    else:
      dp[i][w] = dp[i-1][w]
print(dp[N][W])