Milk Mixing

Hi,

Can someone please help me figure out what’s wrong with this code? Its only working for test cases 1 and 3. Any help would be highly appreciated. Thanks.
(plz ignore the unindented part, it just doesn’t show indent here)

input_file = open(‘milkmix.in’, ‘r’)
output_file = open(‘milkmix.out’, ‘w’)

lst = []

for a in range(0,3):
list = input_file.readline().split()
lst.append(list)
for b in range(len(lst)):
if [] in lst:
lst.remove([])

for c in range(len(lst)):
for d in range(len(lst[c])):
lst[c][0] = int(lst[c][0])
lst[c][1] = int(lst[c][1])

for i in range(0,2):
for j in range(lst[i+1][0]):
if lst[i][1]>0 and lst[i+1][1]<=lst[i+1][0]:
lst[i][1] = lst[i][1] - 1
lst[i+1][1] = lst[i+1][1] + 1

for i in range(-1,1):
for j in range(lst[i+1][0]):
if lst[i][1]>0 and lst[i+1][1]<=lst[i+1][0]:
lst[i][1] = lst[i][1] - 1
lst[i+1][1] = lst[i+1][1] + 1

milky = []
for s in range(len(lst)):
milky.append(lst[s][1])
for r in range(len(milky)):
milky[r] = str(milky[r])
for v in range(len(milky)):
output_file.write(milky[v] + ‘\n’)

input_file.close()
output_file.close()

https://forum.usaco.guide/t/how-to-ask-for-help-on-a-problem/338/2