Dr. Anne Anderson Coding Contest 1 P2 - Pokemon Battles

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Video Game Club has begun a Pokemon Nuzlocke, and they're stuck on a particularly hard Pokemon of type E. 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 N moves, each with two attributes: an integer base damage Xi and a type Ti. 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

1N2×105

1Xi109

Subtask 1 [25%]

Xi=1

Subtask 2 [25%]

All moves are the same type as E.

Subtask 3 [50%]

No additional constraints.

Input Specification

The first line contains the string E (either FIRE, WATER, or GRASS).

The second line contains the integer N.

The next N lines contain the integer Xi and the string Ti (either FIRE, WATER, or GRASS) for move i, 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

Copy
FIRE
5
3 FIRE
2 WATER
6 GRASS
3 GRASS
4 FIRE

Sample Output

Copy
4

Explanation for Sample

The second and fifth moves each deal 4 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

There are no comments at the moment.