#54995: python寫法


xmlinjerry@gmail.com (Xm)


#http://zerojudge.tw/ShowProblem?problemid=c297
acts = []
for _ in range(9):
    acts.append(list(map(str,input().split())))
k=int(input())
#掃描位置
i=0
j=1
#球場
court=[0,0,0]
#紀錄出局數
total_out=0
out=0
score=0
while True:
    act = acts[i][j]
    #出局
    if act=="FO" or act=="GO" or act=="SO":
        #更新出局數
        out+=1
        total_out+=1
        #達到目標局數
        if total_out==k:
            print(score)
            break
        #三出局清空球場
        if out==3:
            out=0
            court=[0,0,0]
    #全壘打    
    elif act=="HR":
        #score+場上人數+全磊大的那個人
        score+=(1+sum(court))
        #清空球場
        court = [0,0,0]
    #安打
    else:
        #計算要推幾次
        time = int(act[0])
        for x in range(time):
            #最後一格如果有人被推掉,表示得分
            if court[2]==1:
                score+=1
            #前推一格
            court[2]=court[1]
            court[1]=court[0]
            #第一次要推入一個人進壘包
            court[0]=1 if x==0 else 0
    #更新掃描
    i+=1
    if i==9:
        i=0
        j+=1


#54996: Re: python寫法


xmlinjerry@gmail.com (Xm)


_