#P2697. 宝石串
宝石串
Description
There is a kind of gem string made of emeralds and rubies. The string is most stable and least likely to break only when the numbers of emeralds and rubies are equal. An An wants to know, from a given gem string, how many gems the longest stable substring contains. Please help him.
Emeralds are denoted by , and rubies are denoted by .
Input Format
One line, a string consisting of and .
Output Format
One line with an integer, the number of gems in the longest stable gem string.
GRGGRG
4
Hint
is the answer.
Constraints: the number of gems is at most .
Translated by ChatGPT 5
京公网安备 11011102002149号