#C2895. Maximizing 'b' Count

    ID: 46261 Type: Default 1000ms 256MiB

Maximizing 'b' Count

Maximizing 'b' Count

You are given a string s of length N consisting only of the characters 'a' and 'b'. You are allowed to perform at most one operation: select a contiguous substring of 'a' characters and change all of them to 'b'. Your goal is to maximize the total count of 'b' in the string after this operation.

Formally, if the original string has T occurrences of 'b', and you can convert a contiguous block of 'a's of length L to 'b's (if beneficial), then the final count becomes T + L, subject to the constraint that the total count cannot exceed the length of the string (i.e. you cannot have more than N 'b' characters). Write a program to compute this maximum possible count.

Note: If you do not perform any operation (or if converting does not help), the answer is simply the original count of 'b'.

Example:

Input:  aabba
Output: 4

Explanation: The original string "aabba" contains 2 'b's. Converting the substring "aa" at the beginning results in "bbbba" which has 4 'b's. No better result is possible.

</p>

inputFormat

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

Constraints:

  • 1 ≤ |s| ≤ 10^5

outputFormat

Output a single integer --- the maximum possible count of 'b' characters in the string after performing at most one conversion of a contiguous substring of 'a' into 'b'. The output should be printed on a new line.

## sample
aabba
4