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
#include <bits/stdc++.h>

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define repd(i,k) for(ll i=k;i>=0;i--)
#define rep(i,k) for(ll i=0;i<k;i++)
#define repn(i,k1,k2) for(ll i=k1;i<=k2;i++)

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ee6 (ll)1000001
#define ee5 (ll)100001
#define read(type) readInt<type>()
#define tt ll t;cin>>t; while(t--)
typedef long long int ll;

typedef pair<ll, ll> pr;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pr> vpr;
typedef vector<vpr>vvpr;
typedef vector<vi> vvi;
typedef map<ll,ll> MPII;
typedef set<ll> SETI;
typedef multiset<ll> MSETI;

int a[5001],b[5001];
int main()
{
	#if !ONLINE_JUDGE
	freopen("C:/Users/hp/Desktop/CPP/PRACTICE/data.txt","r",stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;cin>>s;int n=s.length();
	
	rep(i,n)
	{
		if(s[i]=='a'){
		a[i]=i>0?a[i-1]+1:1;
		b[i]=i>0?b[i-1]:0;}
		else{
		a[i]=i>0?a[i-1]:0;
		b[i]=i>0?b[i-1]+1:1;}
		
		
	}
	int mini=INF;
	
	for(int i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)
		{
			int cnt=0;
			cnt+=(a[j]-((i>0)?a[i-1]:0));
			cnt+=(i>0?b[i-1]:0);
			cnt+=b[n-1]-b[j];
			mini=min(mini,cnt);
		}
	}
	mini=min(mini,b[n-1]);
	cout<<n-mini;
	
	
}
