#P2697. Longest Stable Gemstone Substring

    ID: 15962 Type: Default 1000ms 256MiB

Longest Stable Gemstone Substring

Longest Stable Gemstone Substring

You are given a string consisting of gemstones represented by two characters: G for green gemstones and R for red gemstones. A gemstone substring is considered stable if and only if the number of green gemstones is equal to the number of red gemstones.

Your task is to find the length of the longest contiguous stable substring that can be obtained from the given string. If there is no stable substring, output 0.

Note: In the problem, the green gemstone is denoted by \(\texttt{G}\) and the red gemstone by \(\texttt{R}\).

inputFormat

The input consists of a single line containing a non-empty string which only contains the characters G and R.

outputFormat

Output a single integer representing the number of gemstones in the longest stable substring.

sample

GRGR
4