There are cups in a row. Cup contains units of either tea or coffee. A string describes their drinks: means tea, and means coffee.
In one operation, choose two adjacent cups containing different drinks. If their current amounts are and , drink units from each cup. Remove every cup that becomes empty, and close the gaps in the row.
Find the minimum number of cups that can remain after any number of operations.
For each test case, print the minimum number of cups that can remain.
Choose cups 2 and 3. Both become empty, leaving only cup 1. The initial row contains 2 more units of tea than coffee, so it cannot become empty.
Choose cups 1 and 2 and drink 1 unit from each. The remaining cups contain 2 units of tea and 2 units of coffee. One more operation empties both.
There is only one cup, so no operation is possible.
Using original cup numbers, first choose cups 3 and 4, emptying both. Next, choose cups 2 and 5, then cups 1 and 5. This leaves cups 6, 7, and 8. Four units of tea must remain. To keep only two cups, both cups 3 and 6 would have to remain with their full 2 units. But while cup 3 survives, the tea in cups 1 and 2 cannot reach any coffee. Thus two remaining cups are impossible.
Every cup contains tea, so no operation is possible and all four cups remain.