#C7464. Flower Planting and Removal

    ID: 51338 Type: Default 1000ms 256MiB

Flower Planting and Removal

Flower Planting and Removal

You are given an empty garden that is organized as a grid with \(R\) rows and \(C\) columns. You must simulate the process of planting and removing flowers following a sequence of instructions.

The instructions are provided as a string and can include the following characters:

  • \(P\): Plant a flower in the next available empty cell. The cells are filled in row-major order (left to right, then top to bottom).
  • \(R\): Remove a flower from the most recently planted cell (i.e. following a Last-In-First-Out order).
  • \(\.\): Do nothing.

The garden grid is initially empty. If you attempt to plant when the grid is full, or remove when there are no flowers, simply ignore the command.

Your task is to determine the total number of flowers remaining in the garden after executing all instructions.

inputFormat

The input is given via standard input (stdin) in the following format:

R C
instructions

Where:

  • \(R\) is an integer representing the number of rows of the garden.
  • \(C\) is an integer representing the number of columns of the garden.
  • instructions is a string consisting of characters 'P', 'R', and '.'.

outputFormat

Output via standard output (stdout) a single integer: the number of flowers remaining in the garden after all instructions have been executed.

## sample
3 3
P.PP.RP..P.RP
4

</p>