#C5972. Balanced Strings Count

    ID: 49680 Type: Default 1000ms 256MiB

Balanced Strings Count

Balanced Strings Count

Given a string consisting solely of the characters \(L\) and \(R\), your task is to determine the maximum number of balanced substrings that can be formed by splitting the string into contiguous segments. A substring is defined as balanced if it contains an equal number of \(L\) and \(R\) characters.

The process should be executed in a single scan from the beginning to the end of the string. Every time a balance is reached (i.e. the difference between the count of \(L\) and \(R\) becomes zero), it counts as one balanced substring.

Note: The splitting of the string does not require the substrings to be of equal length; they only need to be balanced.

inputFormat

The input consists of a single line containing a non-empty string composed only of the characters L and R. This input is provided through standard input (stdin).

outputFormat

Output a single integer representing the maximum number of balanced substrings that can be obtained from the input string. The result should be written to standard output (stdout).

## sample
RLRRLLRLRL
4