#C7147. Minimum Length after Replacements

    ID: 50986 Type: Default 1000ms 256MiB

Minimum Length after Replacements

Minimum Length after Replacements

Given a string ( S ) consisting only of the letters 'a' and 'b', you are allowed to repeatedly perform the following operation: replace any occurrence of the substring ( ab ) with ( b ). Determine the minimum possible length of the string after no further operations can be applied. In other words, the final length is equal to the number of 'b' characters in the original string.

For example, consider the string "abbab":

  • The count of 'b's is 3, so the final length is 3 ( (\text{ans} = 3) ).

inputFormat

The input consists of a single line containing the string ( S ) (with ( 0 \le |S| \le 10^5 )), where each character is either 'a' or 'b'.

outputFormat

Output a single integer representing the minimum possible length of the string after applying the replacement operation repeatedly.## sample

abbab
3