Buggy python submission (verdict: Time Limit Exceeded):
n,ma,mb = (int(i) for i in input().split())
dp = [[[float("inf") for i in range(10*n+1)] for i in range(10*n+1)] for i in range(n+1)]
dp[0][0][0],ans = 0,float("inf")
for i in range(1,n+1):
	x,y,c = (int(l) for l in input().split())
	for j in range(10*(i-1)+1):
		for k in range(10*(i-1)+1):
			if dp[i-1][j][k]!=float("inf"):
				dp[i][j][k] = min(dp[i-1][j][k],dp[i][j][k])
				dp[i][j+x][k+y] = min(dp[i][j+x][k+y],dp[i-1][j][k]+c)
for i in range(ma,10*n+1,ma):
	if i*mb//ma<=10*n: ans=min(ans,dp[n][i][i*mb//ma])
if ans==float("inf"): print(-1)
else: print(ans)

Fixed submission:
n, ma, mb = map(int, input().split())
INF = float("inf")
dp = [[[INF for i in range(10*n+1)] for i in range(10*n+1)] for i in range(n+1)]
dp[0][0][0],ans = 0,INF
for i in range(1,n+1):
    a,b,c = (int(l) for l in input().split())
    for j in range(10*(i-1)+1):
        for k in range(10*(i-1)+1):
            if dp[i-1][j][k] != INF:
              dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k])
              dp[i][j+a][k+b] = min(dp[i][j+a][k+b], dp[i-1][j][k]+c)
for i in range(ma,10*n+1,ma):
	if i*mb//ma<=10*n: ans=min(ans,dp[n][i][i*mb//ma])
if ans==INF: print(-1)
else: print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,ma,mb = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
dp = [[[float("inf") for i in range(10*n+1)] for i in range(10*n+1)] for i in range(n+1)]
dp[0][0][0],ans = 0,float("inf")
for i in range(1,n+1):
	for j in range(10*(i-1)+1):
		for k in range(10*(i-1)+1):
			dp[i][j][k] = min(dp[i-1][j][k],dp[i][j][k])
			dp[i][j+x[i-1][0]][k+x[i-1][1]] = min(dp[i][j+x[i-1][0]][k+x[i-1][1]],dp[i-1][j][k]+x[i-1][2])
for i in range(1,10*n+1):
	for j in range(1,10*n+1):
		if i*mb==j*ma: ans = min(ans,dp[n][i][j])
if ans==float("inf"): print(-1)
else: print(ans)

Fixed submission:
n, ma, mb = map(int, input().split())
INF = float("inf")
dp = [[[INF for i in range(10*n+1)] for i in range(10*n+1)] for i in range(n+1)]
dp[0][0][0],ans = 0,INF
for i in range(1,n+1):
    a,b,c = (int(l) for l in input().split())
    for j in range(10*(i-1)+1):
        for k in range(10*(i-1)+1):
            if dp[i-1][j][k] != INF:
              dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k])
              dp[i][j+a][k+b] = min(dp[i][j+a][k+b], dp[i-1][j][k]+c)
for i in range(ma,10*n+1,ma):
	if i*mb//ma<=10*n: ans=min(ans,dp[n][i][i*mb//ma])
if ans==INF: print(-1)
else: print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,ma,mb = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
dp = [[[float("inf") for i in range(10*n+1)] for i in range(10*n+1)] for i in range(n+1)]
dp[0][0][0],ans = 0,float("inf")
for i in range(1,n+1):
	for j in range(10*(n-1)+1):
		for k in range(10*(n-1)+1):
			dp[i][j][k] = min(dp[i-1][j][k],dp[i][j][k])
			dp[i][j+x[i-1][0]][k+x[i-1][1]] = min(dp[i][j+x[i-1][0]][k+x[i-1][1]],dp[i-1][j][k]+x[i-1][2])
for i in range(1,10*n+1):
	for j in range(1,10*n+1):
		if i*mb==j*ma: ans = min(ans,dp[n][i][j])
if ans==float("inf"): print(-1)
else: print(ans)

Fixed submission:
n, ma, mb = map(int, input().split())
INF = float("inf")
dp = [[[INF for i in range(10*n+1)] for i in range(10*n+1)] for i in range(n+1)]
dp[0][0][0],ans = 0,INF
for i in range(1,n+1):
    a,b,c = (int(l) for l in input().split())
    for j in range(10*(i-1)+1):
        for k in range(10*(i-1)+1):
            if dp[i-1][j][k] != INF:
              dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k])
              dp[i][j+a][k+b] = min(dp[i][j+a][k+b], dp[i-1][j][k]+c)
for i in range(ma,10*n+1,ma):
	if i*mb//ma<=10*n: ans=min(ans,dp[n][i][i*mb//ma])
if ans==INF: print(-1)
else: print(ans)