Buggy python submission (verdict: Runtime Error):
# ABC54 D
n,ma,mb = map(int, input().split())
a = []
b = []
c = []
for i in range(N):
    ai,bi,ci = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    
max_sum = n * 10
max_cost = 100000000
dp = [[[max_cost for k in range(max_sum+1)] for j in range(max_sum+1)] for i in range(n+1)]

dp[0][0][0] = 0
for i in range(n):
    for ca in range(max_sum+1):
        for cb in range(max_sum+1):
            if(dp[i][ca][cb] == max_cost):
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])

ans = max_cost
for ca in range(1,max_sum+1):
    for cb in range(1,max_sum+1):
        if(ca*mb == cb*ma):
            ans = min(ans, dp[n][ca][cb])

if(ans == max_cost):
    print(-1)
else:
    print(ans)

Fixed submission:
# ABC54 D
n,ma,mb = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
    ai,bi,ci = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    
max_sum = n * 10
max_cost = 100000000
dp = [[[max_cost for k in range(max_sum+1)] for j in range(max_sum+1)] for i in range(n+1)]

dp[0][0][0] = 0
for i in range(n):
    for ca in range(max_sum+1):
        for cb in range(max_sum+1):
            if(dp[i][ca][cb] == max_cost):
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])

ans = max_cost
for ca in range(1,max_sum+1):
    for cb in range(1,max_sum+1):
        if(ca*mb == cb*ma):
            ans = min(ans, dp[n][ca][cb])

if(ans == max_cost):
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
# ABC54 D
n,ma,mb = map(int, input().split())
a = []
b = []
c = []
for i in range(N):
    ai,bi,ci = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    
max_sum = n * 10
max_cost = 100000000
dp = [[[max_cost for k in range(n+1)] for j in range(max_sum+1)] for i in range(max_sum+1)]

dp[0][0][0] = 0
for i in range(n):
    for ca in range(max_sum+1):
        for cb in range(max_sum+1):
            if(dp[i][ca][cb] == max_cost):
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])

ans = max_cost
for ca in range(max_sum+1):
    for cb in range(max_sum+1):
        if(ca*mb == cb*ma):
            ans = min(ans, dp[n][ca][cb])

if(ans == max_cost):
    print(-1)
else:
    print(ans)

Fixed submission:
# ABC54 D
n,ma,mb = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
    ai,bi,ci = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    
max_sum = n * 10
max_cost = 100000000
dp = [[[max_cost for k in range(max_sum+1)] for j in range(max_sum+1)] for i in range(n+1)]

dp[0][0][0] = 0
for i in range(n):
    for ca in range(max_sum+1):
        for cb in range(max_sum+1):
            if(dp[i][ca][cb] == max_cost):
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])

ans = max_cost
for ca in range(1,max_sum+1):
    for cb in range(1,max_sum+1):
        if(ca*mb == cb*ma):
            ans = min(ans, dp[n][ca][cb])

if(ans == max_cost):
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
# ABC54 D
n,ma,mb = map(int, input().split())
a = []
b = []
c = []
for i in range(N):
    ai,bi,ci = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    
max_sum = n * 10
max_cost = 100000000
dp = [[[max_cost for k in range(n+1)] for j in range(max_sum+1)] for i in range(max_sum+1)]

dp[0][0][0] = 0
for i in range(n):
    for ca in range(max_sum+1):
        for cb in range(max_sum+1):
            if(dp[i][ca][cb] == max_cost):
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])

ans = max_cost
for ca in range(max_sum+1):
    for cb in range(max_sum+1):
        if(ca*mb == cb*ma):
            ans = min(ans, dp[n][ca][cb])

if(ans == max_cost):
    print(-1)
else:
    print(ans)

Fixed submission:
# ABC54 D
n,ma,mb = map(int, input().split())
a = []
b = []
c = []
for i in range(n):
    ai,bi,ci = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)
    
max_sum = n * 10
max_cost = 100000000
dp = [[[max_cost for k in range(max_sum+1)] for j in range(max_sum+1)] for i in range(n+1)]

dp[0][0][0] = 0
for i in range(n):
    for ca in range(max_sum+1):
        for cb in range(max_sum+1):
            if(dp[i][ca][cb] == max_cost):
                continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i])

ans = max_cost
for ca in range(1,max_sum+1):
    for cb in range(1,max_sum+1):
        if(ca*mb == cb*ma):
            ans = min(ans, dp[n][ca][cb])

if(ans == max_cost):
    print(-1)
else:
    print(ans)