This year, so many contestants signed up for the CCC that the ICS classrooms were completely filled! Thus, to accomodate everyone, Josh and some of his classmates were moved to the Engineering Room (118E) to write the contest.

Unfortunately, Josh barely practiced for the CCC, and he knows that he has no chance of obtaining a good score!

Thankfully, upon entering and looking around the Engineering Room, Josh realizes that he can use the seating arrangement of tables of to his advantage: Josh devises a plan to cheat off the screens of his classmates!

Attached below is a diagram of the TEJ classroom.

From each seat, there are some other seats where their screens are within its field of view. Specifically, anyone sitting at a table (, , or ) can see any of the other seats at the table's screens. Additionally, those sitting on the boundary of where two tables meet can also see the two seats behind them. These are drawn in purple in the diagram.

There are people in the room in total, including Josh. The th person has a coding skill of . Josh's skill is , but for every person whose screens he can see, he can cheat off their screen and his own coding skill level increases by .

Some people have already taken a seat, but Josh and some others have not picked seats yet.

Josh wants to know what the maximum he can achieve is amongst all of possible seating arrangements.

#### Constraints

#### Input Specifications

The input will consist of lines, each representing one of his classmates.

Each line will be either of the form `s v`

or `s v p`

.

`s`

is the name of one of Josh's classmates (no longer than characters), and `v`

is an integer representing .

If there is a `p`

parameter, it will be a string consisting of one letter (`A`

, `B`

, or `C`

) and one integer from to , which represents the seat that this person has sat down at, as shown on the diagram.

#### Output Specifications

Amongst all the people who have not sat down and Josh himself, calculate the maximum that Josh can attain throughout all possible seatings.

Output this integer on its own line.

#### Sample Input 1

```
joshanahitadoshita 94
joshathan 34 C7
joshourangutan 75
joshalekseimitri 52 B7
joshishwajeetswapriyaditya 20 A1
jay-el-pockalypse 33 C6
josholessandrogiuseppina 27
joshinderella 44 B4
frank 100
joshalegrabov 92 B2
joshallacraguetta 17 A5
joshamseulgug 25 C2
joshathanatthew 38 A8
josh-terminator-3000 52 C8
joshatotheta 66 B3
josulius-caesar 86 C5
joshuette 64
joshanne 39 A3
joshabdulahita 21
joshiah 9 B8
joshorbarlomew 45
josharutobakuyamiotanna 46 C4
josh-mersenne-twister 30 A7
```

#### Sample Output 1

`487`

#### Sample Explanation 1

A possible solution would be for Josh to sit at , where he can see `joshallacraguette`

, `joshamseulgug`

, `josharutobakuyamiotanna`

, `josulius-caesar`

, `jay-el-pockalypse`

, `joshathan`

, and `josh-terminator-3000`

. Additionally, one such arrangement where Josh's coding skill is maximized is when `joshanahitadoshita`

sits at and `frank`

sits at .

## Comments