'''

Daniel Nguyen

Enloe

Sen5

Potter

November 27,2012

'''

tcode={'1':0, '2':0.5, '3':1, '4':1.5, '5':2, '6':2.5, '7':3, '8':3.5,

           '9':4, 'A':4.5, 'B':5, 'C':5.5, 'D':6, 'E':6.5, 'F':7, 'G':7.5, 'H':8}

 

for programstart in range(5):

        inp=''

        fin=0

        totime=0

        hours=[]

        inp=raw_input()

        loc1=int(inp[:inp.index(',')])

        inp=inp[inp.index(',')+1:]

        for days in range(7):

            times=inp[:3]

            # print times

            hours.append(tcode[times[2]]-tcode[times[0]])

            totime=totime+tcode[times[2]]-tcode[times[0]]

            inp=inp[4:]

           

        if (loc1>=100)and(loc1<=199):

            if totime<=30: fin=fin+10*totime

            if totime>30: totime=totime-30; fin=fin+15*totime+300

 

        if (loc1>=200)and(loc1<=299):

            if totime<=40: fin=fin+7.5*totime

            if totime>40: totime=totime-40; fin=fin+7.5*40+15*totime

 

        if (loc1>=300)and(loc1<=399):

            if totime<=20: fin=fin+9.25*totime

            if totime>20: totime=totime-20; fin=fin+20*9.25+10.5*totime

 

        if (loc1>=400)and(loc1<=499):

           time=hours[0]+hours[6]

           fin=fin+time*13.5+(totime-time)*6.75

 

        if (loc1>=500)and(loc1<=599):

            for day in range(7):

                if hours[day]<=6: fin=fin+8*hours[day]

                else: hours[day]=hours[day]-6; fin=fin+48+12*hours[day]

        fin=round(fin,2)

        print "$%.2f" % fin