#K67737. Split Balanced Substrings

    ID: 32709 Type: Default 1000ms 256MiB

Split Balanced Substrings

Split Balanced Substrings

Given a string composed solely of the characters 'L' and 'R', split it into the maximum number of balanced substrings. A substring is considered balanced if it contains an equal number of 'L' and 'R' characters. Formally, for any balanced substring, if ( n_L ) is the number of 'L's and ( n_R ) is the number of 'R's, then we require ( n_L = n_R ).

It is guaranteed that the input string can be partitioned into valid balanced substrings. Your task is to compute the maximum number of balanced substrings into which the input string can be split.

inputFormat

The input consists of a single line containing a non-empty string composed only of the characters 'L' and 'R'.

outputFormat

Output a single integer representing the maximum number of balanced substrings that the input string can be partitioned into.## sample

RLRRLLRLRL
4