I’ve tried to debug, but my code still only passes on test cases 1,5, and 6.

problem link: USACO

My method is to simulate through Farmer John’s log after sorting it, and if we change the pictures, increment answer by 1. This works for the sample test case and 2 other cases, but doesn’t pass all other test cases.

Am I miscalculating the number of adjustments Farmer John has to make?

here’s the code:

```
N = int(input())
log = []
milks = [7,7,7] #Bessie,Elsie,Mildred
#read inputs
for _ in range(N):
day, name, milk = map(str,input().split())
day,milk = int(day),int(milk)
log.append([day,name,milk])
#sort Farmer John's log/notes
log.sort(key=lambda x: x[0])
cnt = 0
ans= 0 #answer
curCowMax = ["Bessie","Elsie","Mildred"] #current pictures of cows
for i in range(N):
cnt = 0
#update milk amounts
if log[i][1] == "Bessie":
milks[0] += log[i][2]
elif log[i][1] == "Elsie":
milks[1] += log[i][2]
else: #Mildred
milks[2] += log[i][2]
maxAmt = max(milks)
for j in range(3): #I did something wrong here, but idk what went wrong
if (milks[j] == maxAmt and log[j][1] not in curCowMax):
curCowMax.append(log[j][1])
cnt += 1
if (milks[j] < maxAmt and log[j][1] in curCowMax):
curCowMax.remove(log[j][1])
cnt += 1
if cnt!= 0: #if farmer john has to change the pics
ans += 1
print(ans)
```

Thanks!