Three Boxes
Time limit2sMemory limit1024 MB
Given a string of L and R moves, simulate a ball moving among three boxes starting at box 1 (clamped at the ends) and count how many times it enters box 3.
- Level
Easy1 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
A string of length is given. Each character of is L or R.
There is one ball and three boxes that can hold the ball. The boxes are numbered 1, 2, and 3.
Initially, the ball is in box 1.
Beaver Bitaro performed operations on the boxes and the ball, starting from this state.
The -th operation () is performed as follows.
- Let box be the box that contains the ball, and take the ball out of box . Then, depending on the -th character of , do one of the following.
- If the -th character of is L, put the ball into box . If is 1, put the ball into box 1.
- If the -th character of is R, put the ball into box . If is 3, put the ball into box 3.
Print the number of times the ball was put into box 3 over the operations.
Input
The input is given from Standard Input in the following format.
N
S
Output
Print the number of times the ball was put into box 3 over the operations.
Constraints
- .
- is a string of length .
- Each character of is L or R.
- is an integer.