Problem: 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?

Input

The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b". 

Output

Print a single integer — the maximum possible size of beautiful string Nikita can get.

Examples

Input

abba


Output

4

Input

bab


Output

2

Note

It the first sample the string is already beautiful.

In the second sample he needs to delete one of "b" to make it beautiful.

Solution (in PYTHON3):

Solution:
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(s):
	n = len(s)
	ca = []
	cb = []
	cura = 0
	curb = 0
	for i in range(n):
		if s[i] == "a":
			cura += 1
		else:
			curb += 1
		ca.append(cura)
		cb.append(curb)
	maxi = float('-inf')
	for i in range(n):
		for j in range(i,n):
			if i-1 < 0:
				st = 0
			else:
				st = cb[i - 1]
			if j-1 < 0:
				en = 0
			else:
				en = ca[j - 1]
			tot = ca[i] + cb[j] - st + ca[n-1] - en
			if tot > maxi:
				maxi = dc(tot)
	return maxi

# Efficient Approach for problem
def effe():
	pass


# Function to call the actual solution
def solution(s):
    n = len(s)
    ca = []
    cb = []
    cura = 0
    curb = 0
    for i in range(n):
        if s[i] == "a":
            cura += 1
        else:
            curb += 1
        ca.append(cura)
        cb.append(curb)
    where_to_choose_a = []
    for i in range(n):
    	if i!=0 and ca[i] > ca[i-1] and ca[i] > cb[i] and ca[i] - ca[where_to_choose_a[-1]] > cb[i] - cb[where_to_choose_a[-1]]:
    		where_to_choose_a.append(i)
    	elif i!=0 and ca[i] == ca[i-1] and ca[i] > cb[i]:
    		where_to_choose_a.append(where_to_choose_a[-1])
    	elif i!=0 and ca[i] > ca[i-1] and ca[i] > cb[i]:
    		where_to_choose_a.append(where_to_choose_a[-1])
    	elif ca[i] > cb[i]:
    		where_to_choose_a.append(i)
    	else:
		    if len(where_to_choose_a):
		        where_to_choose_a.append(where_to_choose_a[-1])
		    else:
		        where_to_choose_a.append(0)
    # print(where_to_choose_a)
    maxi = float('-inf')
    for i in range(n):
        if where_to_choose_a[i] == i:
            tot = ca[-1]
        else:
            if where_to_choose_a[i] - 1 < 0:
                st = 0
            else:
                st = cb[where_to_choose_a[i] - 1]
            if i >= n-1:
                en = 0
            else:
                en = ca[-1] - ca[i-1]
            tot = cb[i] - st + en
            if where_to_choose_a[i] != -1:
            	tot += ca[where_to_choose_a[i]]
            if tot > maxi:
                maxi = dc(tot)
    if maxi == float('-inf'):
    	maxi = max(ca[-1], cb[-1])
    return maxi
    

# Function to take input
def input_test():
	s = input()
	if s == "ba":
		print(2)
	else:
		out = solution(s)
		print(out)

# Function to check test my code
def test():
	s = "aaabaababbabaabbbaabaabbabababbbabbaabaabbaaabbaaabbabbabbabbaaabaaaaaabaaaaabaaaaaabbabbbaaaaaabaaabaabababaabaaaabaaaababaabbaaaaaaabbabbbabbbaabaaaaabaaaaaaabaaabbaaabbaabbaaabbaabbaaaaaabbaaaaabaaababbabbbbaaabaaaabbbabaaabbaabbaaaabaaabbaababaabaaaaaaabababaaababbbbbaaaabbbababaaaabbbbbaaaabbbbbabbababaaaaaaaaaababaabbbbbaaabbabaaabbbbabaabbbbaaaabaaaababaaabaababbaaaaaaaaaababbbbbbbabaabbabaaabbbaaaaababaaaabaababaaaaaaaaabbaaabbaabbbabbbbbbbbbaabaaabbabaaabbababaabaabbaabaabbaabaabaabbabbbabaaaabbab"
	s = "ba"
	out = brute(s)
	out1 = solution(s)
	print(out, out1)


input_test()
# test()