Under construction

Still being built. Things may change

Three Boxes

Time limit2sMemory limit1024 MB

Summary
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 SS of length NN is given. Each character of SS 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 NN operations on the boxes and the ball, starting from this state.

The ii-th operation (1≤i≤N1 \le i \le N) is performed as follows.

  • Let box xx be the box that contains the ball, and take the ball out of box xx. Then, depending on the ii-th character of SS, do one of the following.
    • If the ii-th character of SS is L, put the ball into box x−1x-1. If xx is 1, put the ball into box 1.
    • If the ii-th character of SS is R, put the ball into box x+1x+1. If xx is 3, put the ball into box 3.

Print the number of times the ball was put into box 3 over the NN 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 NN operations.

Constraints

  • 1≤N≤1001 \le N \le 100.
  • SS is a string of length NN.
  • Each character of SS is L or R.
  • NN is an integer.

Examples3

  1. Example 1

    Input
    4
    LRRR
    
    Expected output
    2
    
  2. Example 2

    Input
    3
    LRL
    
    Expected output
    0
    
  3. Example 3

    Input
    7
    LRLRRRL
    
    Expected output
    2