## Cheerio Contest 3 P2 - Double-O-Seven

View as PDF

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

Author:
Problem type

You are playing a game of "Double-O-Seven" with your friend. In the game, both players start with an ammo count and a score of . The game is played in rounds. In a round, both players simultaneously choose one of three actions:

1. R Reload: The player increases their ammo count by .

2. F Fire:

If the player's ammo count is , firing does nothing.

If the player's ammo count is greater than , then:

• Decrease the player's ammo count by .
• Decrease the opponent's score by .
• Increase the player's score by .
3. B Block: Restrict both players' score from increasing or decreasing this round.

Your friend is so confident that he could beat you, that he will tell you all his actions beforehand. What is the maximum score you could get, knowing your opponent's actions?

#### Constraints

2 points The opponent never fires
3 points None
10 points None

#### Input Specification

The first line contains a single integer .

The second line contains a string of length consisting of the characters RFB. The th character in the string indicates the action your friend will make on the th round of the game.

#### Output Specification

Output the maximum possible score you can obtain if you played optimally.

#### Sample Input 1

3
RFF

#### Sample Output 1

1

#### Explanation for Sample Output 1

A possible sequence of actions that obtains this score is RBF.

On the first round, both players reload and have an ammo count of .

On the second round, your friend fires and decreases their ammo count to . Since you blocked, both players still have a score of .

On the third round, your friend does nothing as they fired with an ammo count of . Since you fired, you now have a score of and an ammo count of .

#### Sample Input 2

9
RBFFFBRRF

#### Sample Output 2

3

#### Explanation for Sample Output 2

A possible sequence of actions that obtains this score is RRBFFRFFB.