from typing import List
def bill(a:List[str]):
    amount = 0
    beers = 0
    for i in a:
        if i[0] =="|":
            beers += i.count("|")
        else:
            lineAmount= i.count("|")
            c = 0
            line = ""
            while c < len(i)-1 and i[c] != ",":
                line += i[c]
                c+=1
            if lineAmount != 0:
                amount += int(line)*lineAmount
            else:
                amount += int(line)
    amount += beers *42
    return round(amount,-1)


a=[]
for i in range(1001):
    if input
    a.append(input())

print(bill(a))

