 # USACO 2019 February Contest, Bronze Problem 3. Measuring Traffic

I’ve been working on this problem for a while, but my code can only pass the first two test cases. I downloaded the test data for the problem, but anything I change will make my code give the wrong answer for the first two test cases.
here is my (python) code:
“”"
ID: yayaliu1
LANG: PYTHON3
“”"

fin = open(r"traffic.in", ‘r’)
fout = open(r"traffic.out",‘w’)

def find(M):
for i in M:
if i == 0:
return int(M.index(i))

def after(ramp, tracked, first):
return [first+ramptracked,first+ramptracked]

def ramp(ramp):
if ramp == ‘on’:
return 1
elif ramp == ‘off’:
return -1
else:
return 0

def before(ramp, tracked, first):
return [first-ramptracked,first-ramptracked]

M = []
for i in range(int(N)):
for i in M:
i = ramp(i)

M = [[int(i) for i in q] for q in M]
print(M)

q = -1
low = -float(‘inf’)
high = float(‘inf’)
M.reverse()
for i in M:
if i==0:
low = max(low,i)
high = min(high,i)
else:
high+=q*ii
low+=q
i*i
low = max(0,low)
print(i,low,high)
fout.write(str(low)+’ ‘+str(high)+’\n’)
M.reverse()
q = 1
low = -float(‘inf’)
high = float(‘inf’)
for i in M:
if i==0:
low = max(low,i)
high = min(high,i)
else:
high+=i*i
low+=i*i
low = max(0,low)
print(i,low,high)
fout.write(str(low)+’ ‘+str(high)+’\n’)

fin.close()
fout.close()