USACO Silver 2017 January - Hoof, Paper, Scissors

Problem Info

Name: Hoof, Paper, Scissors
Link: Hoof Paper Scissors, USCO Silver Link

My Work

fin = open("hps.in", "r")
fout = open("hps.out", "w")

n = int(fin.readline())

myH = [0]
myP = [0]
myS = [0]

#Reading in inputs, and then using prefix sums to store in 3 separate lists 
for i in range(n):
    myIn = str(fin.readline())

    myH.append(myH[-1])
    myP.append(myP[-1])
    myS.append(myS[-1])

    if myIn == 'H':
        myH[-1] += 1
    if myIn == 'P':
        myP[-1] += 1
    if myIn == 'S':
        myS[-1] += 1

maxi = 0

#Finding the max possible value 
for x in range(1, len(myH)):
    beforeWin = max(myH[x], myP[x], myS[x])
    afterWin = max(myH[-1] - myH[x], myP[-1] - myP[x], myS[-1] - myS[x])
    maxi = max(maxi, beforeWin + afterWin)

fout.write(str(maxi))

My code works with console, but not the grader system for some reason, and it gives out the wrong output???

How are you running your code? When I tried running your code locally I did not get the correct answer for the sample case.