Zuma 2.0: The Return of the Idol Frog
Time limit5sMemory limit1024 MB
Given a circle of up to 20 letters, find the fewest balls left after repeatedly removing two equal letters or three vowels within any five consecutive balls.
- Level
Medium6 of 10
- Topics
- Dynamic programming, String
- Solved
- No attempts yet
Statement
In the eleventh grade, Vitya discovered the game Zuma, and it took over his mind. For a whole week he came home from school and clicked his mouse until one in the morning, destroying chains of colored balls. He cheered loudly when the last ball disappeared and despaired when he failed to escape in time.
Fortunately, final exams came soon, the game was forgotten, and it was lost during a system update. Vitya put his free time to good use. He passed his exams with good and excellent grades, entered university, and six years later, after defending his master's thesis, became a lead programmer.
Trouble came from an unexpected direction. A new version of the game, Zuma 2.0, was released recently. The story is more varied in this version, and different levels follow different rules. The game captured Vitya again... sorry, now Viktor Sergeyevich. Viktor Sergeyevich knows he must finish the game as fast as possible to return to his professional duties. The second-to-last level has been defeating him, so he asks you for help.
At the start of the level, there are balls arranged in a circle. Each ball has an uppercase Latin letter written on it. The player can make shots that destroy several balls. Specifically, if at least five balls remain on the level, the player can choose any five consecutive balls and perform one of two actions:
- Destroy any two balls with the same letter.
- Destroy any three balls with vowel letters, namely A, E, I, O, U, Y (see the hint).
After a shot, the remaining balls close the gap and form a circle again.
If fewer than five balls remain, the player earns points: the fewer balls remain, the more points the player receives. If five or more balls remain and no shot is possible, the level is not passed.
Input
The input file contains a string . Its length is between 5 and 20 characters. The string consists of uppercase Latin letters.
Output
Print the answer to the problem to the output file.
Hint
There is no consensus on whether Y should count as a vowel or a consonant. English uses Y as a vowel in tycoon, salary, and rhythm, and as a consonant in year, coyote, and way. To resolve this, this problem treats Y as a vowel.