Buggy python submission (verdict: Runtime Error):
n,ma,mb = map(int,input().split())
L = []
sa = 0
sb = 0
for i in range(n):
    a,b,c = map(int,input().split())
    sa += a
    sb += b
    L.append([a,b,c])
dp = [[[10000 for i in range(sa+1)] for i in range(sb+1)] for i in range(n+1)]
dp[0][0][0] = 0
for i in range(n):
    a = L[i][0]
    b = L[i][1]
    c = L[i][2]
    for j in range(sa+1):
        for k in range(sb+1):
            if j-a >= 0 and k-b >= 0:
                dp[i+1][j][k] = min(dp[i][j-a][k-b]+c,dp[i+1][j][k],dp[i][j][k])
            else:
                dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k])
k = max(ma,mb)
t = max(sa,sb)
cur = 1
ans = 10000
while k*cur <= t:
    ans = min(ans,dp[n][ma*cur][mb*cur])
    cur += 1
if ans == 10000:
    print(-1)
else:
    print(ans)


Fixed submission:
n,ma,mb = map(int,input().split())
L = []
sa = 0
sb = 0
for i in range(n):
    a,b,c = map(int,input().split())
    sa += a
    sb += b
    L.append([a,b,c])
dp = [[[10000 for i in range(sb+1)] for i in range(sa+1)] for i in range(n+1)]
dp[0][0][0] = 0
for i in range(n):
    a = L[i][0]
    b = L[i][1]
    c = L[i][2]
    for j in range(sa+1):
        for k in range(sb+1):
            if j-a >= 0 and k-b >= 0:
                dp[i+1][j][k] = min(dp[i][j-a][k-b]+c,dp[i+1][j][k],dp[i][j][k])
            else:
                dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k])
k = max(ma,mb)
t = min(sa,sb)
cur = 1
ans = 10000
while k*cur <= t:
    ans = min(ans,dp[n][ma*cur][mb*cur])
    cur += 1
if ans == 10000:
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
n,ma,mb = map(int,input().split())
L = []
for i in range(n):
    a,b,c = map(int,input().split())
    L.append([a,b,c])
dp = [[10**5]*401 for i in range(401)]
make = [[0,0],[L[0][0],L[0][1]]]
dp[L[0][0]][L[0][1]] = L[0][2]
dp[0][0] = 0
for i in range(1,n):
    a = L[i][0]
    b = L[i][1]
    c = L[i][2]
    for j in range(len(make)):
        t = make[j][0]
        u = make[j][1]
        dp[t+a][u+b] = min(dp[t][u]+c,dp[t+a][u+b])
        make.append([t+a, u+b])
    make = list(set(make))
if ma <= mb:
    cnt = 1
    ans = 10**5
    while mb*cnt <= 400:
        ans = min(ans, dp[ma*cnt][mb*cnt])
        cnt += 1
    if ans == 10**5:
        print(-1)
    else:
        print(ans)
else:
    cnt = 1
    ans = 10**5
    while ma*cnt <= 400:
        ans = min(ans, dp[ma*cnt][mb*cnt])
        cnt += 1
    if ans == 10**5:
        print(-1)
    else:
        print(ans)


Fixed submission:
n,ma,mb = map(int,input().split())
L = []
sa = 0
sb = 0
for i in range(n):
    a,b,c = map(int,input().split())
    sa += a
    sb += b
    L.append([a,b,c])
dp = [[[10000 for i in range(sb+1)] for i in range(sa+1)] for i in range(n+1)]
dp[0][0][0] = 0
for i in range(n):
    a = L[i][0]
    b = L[i][1]
    c = L[i][2]
    for j in range(sa+1):
        for k in range(sb+1):
            if j-a >= 0 and k-b >= 0:
                dp[i+1][j][k] = min(dp[i][j-a][k-b]+c,dp[i+1][j][k],dp[i][j][k])
            else:
                dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k])
k = max(ma,mb)
t = min(sa,sb)
cur = 1
ans = 10000
while k*cur <= t:
    ans = min(ans,dp[n][ma*cur][mb*cur])
    cur += 1
if ans == 10000:
    print(-1)
else:
    print(ans)