/*

Name: Annie Abraham

Thomas Jefferson High School for the Science and Technology

Junior Division

Contest #1 2012-2013

AA_TimeSheet

 */

   import java.util.*;

   import java.text.*;

   import java.io.*;

             

   public class AA_TimeSheet

   {

      public static void main (String[] args)

      {

         String input;

         String inp[];

         int location;

         double start= 0;

         double end =0;

         double worked;

         double paid ;

         double salary = 0;

         DecimalFormat df = new DecimalFormat("$#.00");

         Scanner sc;

         try

         {

            sc = new Scanner(new File("timesheet.in"));

            System.setOut(new PrintStream(new FileOutputStream("timesheet.out")));

         }

            catch(Exception e)

            {

               System.out.println("file not found");

               return;

            }

           

         for (int j=0;j<=3;j++)

         {     

            input = sc.nextLine();

            inp = input.split(",");

            inp[0] = inp[0].trim();

            inp[1] = inp[1].trim();

            inp[2] = inp[2].trim();

            location=Integer.parseInt(inp[0]);

        

            if(inp[1].equals("1"))

               start = 9;

            else if(inp[1].equals("2"))

               start = 9.5;

            else if(inp[1].equals("3"))

               start = 10;

            else if(inp[1].equals("4"))

               start = 10.5;

            else if(inp[1].equals("5"))

               start = 11;

            else if(inp[1].equals("6"))

               start = 11.5;

            else if(inp[1].equals("7"))

               start = 12;

            else if(inp[1].equals("8"))

               start = 12.5;

            else if(inp[1].equals("9"))

               start = 13;

            else if(inp[1].equals("A"))

               start = 13.5;

            else if(inp[1].equals("B"))

               start = 14;

            else if(inp[1].equals("C"))

               start = 14.5;

            else if(inp[1].equals("D"))

               start = 15;

            else if(inp[1].equals("E"))

               start = 15.5;

            else if(inp[1].equals("F"))

               start = 16;

            else if(inp[1].equals("G"))

               start = 16.5;

            else if(inp[1].equals("H"))

               start = 17;

                       

            if(inp[2].equals("1"))

               end = 9;

            else if(inp[2].equals("2"))

               end = 9.5;

            else if(inp[2].equals("3"))

               end = 10;

            else if(inp[2].equals("4"))

               end = 10.5;

            else if(inp[2].equals("5"))

               end = 11;

            else if(inp[2].equals("6"))

               end = 11.5;

            else if(inp[2].equals("7"))

               end = 12;

            else if(inp[2].equals("8"))

               end = 12.5;

            else if(inp[2].equals("9"))

               end = 13;

            else if(inp[2].equals("A"))

               end = 13.5;

            else if(inp[2].equals("B"))

               end = 14;

            else if(inp[2].equals("C"))

               end = 14.5;

            else if(inp[2].equals("D"))

               end = 15;

            else if(inp[2].equals("E"))

               end = 15.5;

            else if(inp[2].equals("F"))

               end = 16;

            else if(inp[2].equals("G"))

               end = 16.5;

            else if(inp[2].equals("H"))

               end = 17;

              

            worked = end-start;

           

            if( location <= 9)

               paid = worked * 10;

              

            else if( location >= 10 && location <= 19 )

            {

               if (worked>4)

               {

                  worked = worked - 4;

                  paid = 32;

                  paid += worked * 12;

               }

               else

                  paid = worked * 8;

            }

            else

            {

               if(worked<=4)

               {

                  paid = worked * 12;

               }

               else

               {

                  worked = worked - 4;

                  paid = 48;

                  paid += worked * 24;

               }

            } 

            System.out.println(df.format(paid));

            salary = salary + paid;

         }

         System.out.println(df.format(salary));

      }

   }