Video Game Club has begun a Pokemon Nuzlocke, and they're stuck on a particularly hard Pokemon of type . Because of this, the club has come to you for help.
Luckily for you, they're playing a simplified modded version of the game! In their mod, Pokemon can have moves, each with two attributes: an integer base damage
and a type
. Their mod also only has Fire, Water, and Grass type moves and Pokemon.
In their mod, Fire type moves deal double their base damage to Grass type Pokemon, half their base damage rounded down to Water type Pokemon, and exactly their base damage (neutral) to Fire type Pokemon. Similarly, Water type moves deal double their base damage to Fire type Pokemon, half rounded down to Grass type Pokemon, and neutral (exactly the base damage) to other Water type Pokemon. Grass type moves deal double damage to Water types, half rounded down to Fire types, and neutral (exactly the base damage) to other Grass types.
Can you determine the maximum damage they can deal to the enemy Pokemon with a single move?
Constraints
Subtask 1 [25%]
Subtask 2 [25%]
All moves are the same type as .
Subtask 3 [50%]
No additional constraints.
Input Specification
The first line contains the string (either
FIRE
, WATER
, or GRASS
).
The second line contains the integer .
The next lines contain the integer
and the string
(either
FIRE
, WATER
, or GRASS
) for move , separated by a space.
Output Specification
The output consists of one integer, the maximum damage any single move can deal to the enemy Pokemon.
Sample Input
FIRE
5
3 FIRE
2 WATER
6 GRASS
3 GRASS
4 FIRE
Sample Output
4
Explanation for Sample
The second and fifth moves each deal damage to a Fire type Pokemon, the maximum possible damage using a single move. The following table contains the damage each move will deal to the opposing Pokemon:
Index | Base Damage | Dealt Damage |
---|---|---|
1 | 3 | 3 |
2 | 2 | 4 |
3 | 6 | 3 |
4 | 3 | 1 |
5 | 4 | 4 |
Comments