One day Nikita found the string containing letters "a" and "b" only. 

Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".

Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
It the first sample the string is already beautiful.

In the second sample he needs to delete one of "b" to make it beautiful.
abba
4
bab
2
bbabbbaabbbb
9
bbabbbbbaaba
10
bbabbbababaa
9
aabbaababbab
8
a
1
b
1
ab
2
ba
2
bb
2
aa
2
babbbaab
6
abaaaa
6
aaa
3
import random, math
from copy import deepcopy as dc

# To Genrate Random Number for Test-Cases
def randomNumber(s, e):
	return random.randint(s, e)

# To Generate Random Array for Test-Cases
def randomArray(s, e, s_size, e_size):
	size = random.randint(s_size, e_size)
	arr = [randomNumber(s, e) for i in range(size)]
	return arr

# To Generate Question Specific Test-Cases
def testcase():
	pass

# Brute Force Approach to check Solution
def brute():
	pass

# Efficient Approach for problem
def effe():
	pass


# Function to call the actual solution
def solution(s):
    sa = 0
    mb = 0
    ea = 0
    cur_b = 0
    cur_a = 0
    n = len(s)
    for i in range(n):
        if s[i] == 'a' and not mb:
            sa += 1
        elif s[i] == 'a' and mb:
            ea += 1
        elif s[i] == 'b' and not ea:
            mb += 1
        elif s[i] == 'b' and ea:
            cur_b += 1
            if cur_b >= ea:
                ea = 0
                mb += cur_b
                cur_b = 0
    # print(sa+mb+ea)
    return sa + mb +ea

# Function to take input
def input_test():
	s = input()
	out = solution(s)
	print(out)

# Function to check test my code
def test():
	pass


input_test()
# test()