Halloween has finally arrived and the ghosts on your street have decided to volunteer at your local haunted houses. Each of the
- spook
- hide
- creep
- float
Each move has an associated scare factor,
In addition, the ghosts are separated into groups based on the sum of the digits of their number. All ghosts who have the same sum of digits are in the same group. In order to keep the group happy, at least half of the ghosts in that group must be assigned to the same haunted house.
On Halloween night, each ghost will arrive at their assigned haunted house in the order of their number. They will ask the other ghosts inside the house if any of them are currently planning on performing any of the same moves as them in their routine. To avoid their routines being too similar, all of these ghosts that are currently inside the house (but not outside) will agree to remove that move from their routine.
Once all the ghosts have arrived, the haunted house will open, and the ghosts will perform their routines. Each move a ghost performs contributes to the scariness of the haunted house. The scariness of a haunted house is the sum of the scare factors of all moves performed by any ghost inside the house.
You will be asked
Constraints
Input Specification
The first line of input contains
The next spook
, hide
, creep
, or float
. Each move will only appear once in a ghost's routine.
The next line of input contains
The next
Output Specification
This problem is graded with an identical
checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n
character and that there are no trailing spaces.
Output
Sample Input
3 1
2 spook float
3 creep spook float
2 hide creep
10 5 7 8
19 41
Sample Output
40
Sample Explanation
There are
Comments
What is "their number" here? Sum of digits of i?