#include <iostream>

using namespace std;
bool arr[100001];
int main()
{
    int n,k,kc,i,j,aa=0,ab=0;
    char c;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='b')
            arr[i]=1;
    }
    kc=k;
    for(i=0,j=0;i<n;i++)
    {
        while(kc&&j<n)
        {
            if(arr[j]&&kc)
                kc--;
            j++;
        }
        while(j<n&&!arr[j])
            j++;
        if(j-i>aa)
            aa=j-i;
        if(j==n)
            break;
        if(arr[i])
        {
            while(arr[i]&&i<j)
            {
                if(kc<k)
                    kc++;
                i++;
            }
            if(kc)
                i--;
        }
    }
    kc=k;
    for(i=0,j=0;i<n;i++)
    {
        while(kc&&j<n)
        {
            if(!arr[j]&&kc)
                kc--;
            j++;
        }
        while(j<n&&arr[j])
            j++;
        if(j-i>ab)
            ab=j-i;
        if(j==n)
            break;
        if(!arr[i])
        {
            while(!arr[i]&&i<j)
            {
                if(kc<k)
                    kc++;
                i++;
            }
            if(kc)
                i--;
        }
    }
    if(aa>ab)
        cout<<aa;
    else
        cout<<ab;
    return 0;
}
/*char c[100001];
int solve(int n,int k,char a)
{
    int i,j=0,kc=k;
    for(i=0;i<n;i++)
    {
        while(j<=i&&k<0)
        {
            if()
        }
    }
}
int main()
{
    int n,k;
    cin>>n>>k>>c;

    return 0;
}*/


#include <iostream>

using namespace std;
bool arr[100001];
int main()
{
    int n,k,kc,i,j,aa=0,ab=0;
    char c;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='b')
            arr[i]=1;
    }
    kc=k;
    for(i=0,j=1;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(!arr[j]&&j<n)
                j++;
            while(arr[j]&&j<n&&kc)
                j++,kc--;
        }
        if(j-i>aa)
            aa=j-i;
        while(arr[i]&&i<n)
        {
            if(kc<k)
                kc++
            i++;
        }
    }
    kc=k;
    for(i=0,j=1;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(arr[j]&&j<n)
                j++;
            while(!arr[j]&&j<n&&kc)
                j++,kc--;
        }
        if(j-i>ab)
            ab=j-i;
        while(!arr[i]&&i<n)
        {
            if(kc<k)
                kc++
            i++;
        }
    }
    if(aa>ab)
        cout<<aa;
    else
        cout<<ab;
    return 0;
}


#include <iostream>

using namespace std;
bool arr[100001];
int main()
{
    int n,k,kc,i,j,aa=0,ab=0;
    char c;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='b')
            arr[i]=1;
    }
    kc=k;
    for(i=0,j=1;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(!arr[j]&&j<n)
                j++;
            while(arr[j]&&j<n&&kc)
                j++,kc--;
        }
        if(j-i>aa)
            aa=j-i;
        while(arr[i]&&i<n)
        {
            if(kc<k)
                kc++;
            i++;
        }
    }
    kc=k;
    for(i=0,j=1;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(arr[j]&&j<n)
                j++;
            while(!arr[j]&&j<n&&kc)
                j++,kc--;
        }
        if(j-i>ab)
            ab=j-i;
        while(!arr[i]&&i<n)
        {
            if(kc<k)
                kc++;
            i++;
        }
    }
    if(aa>ab)
        cout<<aa;
    else
        cout<<ab;
    return 0;
}


#include <iostream>

using namespace std;
bool arr[100001];
int main()
{
    int n,k,kc,i,j,aa=0,ab=0;
    char c;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='b')
            arr[i]=1;
    }
    kc=k;
    for(i=0,j=1;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(!arr[j]&&j<n)
                j++;
            while(arr[j]&&j<n&&kc)
                j++,kc--;
        }
        while(!arr[j]&&j<n)
            j++;
        if(j-i>aa)
            aa=j-i;
        if(j==n)
            break;
        while(arr[i]&&i<n)
        {
            if(kc<k)
                kc++;
            i++;
        }
    }
    kc=k;
    for(i=0,j=1;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(arr[j]&&j<n)
                j++;
            while(!arr[j]&&j<n&&kc)
                j++,kc--;
        }
        while(arr[j]&&j<n)
            j++;
        if(j-i>ab)
            ab=j-i;
        if(j==n)
            break;
        if(!arr[i])
        {
            while(!arr[i]&&i<n)
            {
                if(kc<k)
                    kc++;
                i++;
            }
            i--;
        }
    }
    if(aa>ab)
        cout<<aa;
    else
        cout<<ab;
    return 0;
}


#include <iostream>

using namespace std;
bool arr[100001];
int main()
{
    int n,k,kc,i,j,aa=0,ab=0;
    char c;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='b')
            arr[i]=1;
    }
    kc=k;
    for(i=0,j=1;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(!arr[j]&&j<n)
                j++;
            while(arr[j]&&j<n&&kc)
                j++,kc--;
        }
        while(!arr[j]&&j<n)
            j++;
        if(j-i>aa)
            aa=j-i;
        while(arr[i]&&i<n)
        {
            if(kc<k)
                kc++;
            i++;
        }
    }
    kc=k;
    for(i=0,j=1;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(arr[j]&&j<n)
                j++;
            while(!arr[j]&&j<n&&kc)
                j++,kc--;
        }
        while(arr[j]&&j<n)
            j++;
        if(j-i>ab)
            ab=j-i;
        while(!arr[i]&&i<n)
        {
            if(kc<k)
                kc++;
            i++;
        }
    }
    if(aa>ab)
        cout<<aa;
    else
        cout<<ab;
    return 0;
}


#include <iostream>

using namespace std;
bool arr[100001];
int main()
{
    int n,k,kc,i,j,aa=0,ab=0;
    char c;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='b')
            arr[i]=1;
    }
    kc=k;
    for(i=0,j=0;i<n;i++)
    {
        while(kc&&j<n)
        {
            if(arr[j]&&kc)
                kc--;
            j++;
        }
        while(j<n&&!arr[j])
            j++;
        if(j-i>aa)
            aa=j-i;
        if(j==n)
            break;
        if(arr[i])
        {
            while(arr[i]&&i<j)
            {
                if(kc<k)
                    kc++;
                i++;
            }
            i--;
        }
    }
    kc=k;
    for(i=0,j=0;i<n;i++)
    {
        while(kc&&j<n)
        {
            if(!arr[j]&&kc)
                kc--;
            j++;
        }
        while(j<n&&arr[j])
            j++;
        if(j-i>ab)
            ab=j-i;
        if(j==n)
            break;
        if(!arr[i])
        {
            while(!arr[i]&&i<j)
            {
                if(kc<k)
                    kc++;
                i++;
            }
            i--;
        }
    }
    if(aa>ab)
        cout<<aa;
    else
        cout<<ab;
    return 0;
}
/*char c[100001];
int solve(int n,int k,char a)
{
    int i,j=0,kc=k;
    for(i=0;i<n;i++)
    {
        while(j<=i&&k<0)
        {
            if()
        }
    }
}
int main()
{
    int n,k;
    cin>>n>>k>>c;

    return 0;
}*/


#include <iostream>

using namespace std;
bool arr[100001];
int main()
{
    int n,k,kc,i,j,aa=0,ab=0;
    char c;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='b')
            arr[i]=1;
    }
    kc=k;
    for(i=0,j=1;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(!arr[j]&&j<n)
                j++;
            while(arr[j]&&j<n&&kc)
                j++,kc--;
        }
        if(j-i>aa)
            aa=j-i;
        while(arr[i]&&i<n)
            k++,i++;
    }
    kc=k;
    for(i=0,j=1;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(arr[j]&&j<n)
                j++;
            while(!arr[j]&&j<n&&kc)
                j++,kc--;
        }
        if(j-i>ab)
            ab=j-i;
        while(!arr[i]&&i<n)
            k++,i++;
    }
    if(aa>ab)
        cout<<aa;
    else
        cout<<ab;
    return 0;
}


#include <iostream>

using namespace std;
bool arr[100001];
int main()
{
    int n,k,kc,i,j,aa=0,ab=0;
    char c;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='b')
            arr[i]=1;
    }
    kc=k;
    for(i=0,j=0;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(!arr[j]&&j<n)
                j++;
            while(arr[j]&&j<n&&kc)
                j++,kc--;
        }
        while(!arr[j]&&j<n)
            j++;
        if(j-i>aa)
            aa=j-i;
        if(j==n)
            break;
        while(arr[i]&&i<n)
        {
            if(kc<k)
                kc++;
            i++;
        }
    }
    kc=k;
    for(i=0,j=0;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(arr[j]&&j<n)
                j++;
            while(!arr[j]&&j<n&&kc)
                j++,kc--;
        }
        while(arr[j]&&j<n)
            j++;
        if(j-i>ab)
            ab=j-i;
        if(j==n)
            break;
        if(!arr[i])
        {
            while(!arr[i]&&i<n)
            {
                if(kc<k)
                    kc++;
                i++;
            }
            i--;
        }
    }
    if(aa>ab)
        cout<<aa;
    else
        cout<<ab;
    return 0;
}


#include <iostream>

using namespace std;
bool arr[100001];
int main()
{
    int n,k,kc,i,j,aa=0,ab=0;
    char c;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='b')
            arr[i]=1;
    }
    kc=k;
    for(i=0,j=0;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(!arr[j]&&j<n)
                j++;
            while(arr[j]&&j<n&&kc)
                j++,kc--;
        }
        while(!arr[j]&&j<n)
            j++;
        if(j-i>aa)
            aa=j-i;
        if(j==n)
            break;
        if(arr[i])
        {
            while(arr[i]&&i<n)
            {
                if(kc<k)
                    kc++;
                i++;
            }
            i--;
        }
    }
    kc=k;
    for(i=0,j=0;i<n;i++)
    {
        while(kc&&j<n)
        {
            while(arr[j]&&j<n)
                j++;
            while(!arr[j]&&j<n&&kc)
                j++,kc--;
        }
        while(arr[j]&&j<n)
            j++;
        if(j-i>ab)
            ab=j-i;
        if(j==n)
            break;
        if(!arr[i])
        {
            while(!arr[i]&&i<n)
            {
                if(kc<k)
                    kc++;
                i++;
            }
            i--;
        }
    }
    if(aa>ab)
        cout<<aa;
    else
        cout<<ab;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        b=0;
        c=0;
        s+='b';
        j=0;
        l=0;
        ll p=0;
        m=-1000000;
        ll q=0;
        bb[0]=0;
        for(i=0,j=0,l=0; i<s.size(); i++)
        {
            if(s[i]=='b')
            {

                p++;
                if(p==k)
                {
                    q=c;
                    if(j-k>=0)
                    q=c+j-bb[j-k];
                    m=max(m,q);
                    p--;
                }
                j++;
                bb[j]=c+j;
            }
            else
                c++;
        }
        if(m<0)
            cout<<max(c,j-1)<<endl;
        else
        cout<<m<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        c=0;
        queue<ll>q;
        l=0;
        v=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='b')
            {
                q.push(i);
                c++;
                if(c>k)
                {
                    c=1;
                    v=max(i-l,v);
                    l=q.front();
                    q.pop();

                }
            }

        }
        //cout<<v;
        v=max(i-1-l,v);
        c=0;
        queue<ll>qq;
        l=0;

        for(i=0; i<n; i++)
        {
            if(s[i]=='a')
            {//cout<<i<<endl;
                qq.push(i);
                c++;
                if(c>k)
                {
                    c=1;
                    v=max((i-l),v);
                    //cout<<i-l<<endl;
                    l=qq.front();
                    qq.pop();

                }
            }

        }
        v=max(i-l,v);
        cout<<v;

    }
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        c=0;
        queue<ll>q;
        l=0;
        v=0;
        r=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='b')
            {
                q.push(i);
                c++;
                if(c>k)
                {
                    r=1;
                    c=1;
                    v=max(i-l,v);
                    l=q.front();
                    q.pop();

                }
            }

        }
        //cout<<v;
        if(r==1)
            v=max(i-1-l,v);
        else
            v=max(i-l,v);
        c=0;
        queue<ll>qq;
        l=0;
        r=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='a')
            {
                //cout<<i<<endl;
                qq.push(i);
                c++;
                if(c>k)
                {
                    r=1;
                    c=1;
                    v=max((i-l),v);
                    //cout<<i-l<<endl;
                    l=qq.front();
                    qq.pop();

                }
            }

        }
        if(r==1)
            v=max(i-1-l,v);
        else
            v=max(i-l,v);
        cout<<v;

    }
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        b=0;
        c=0;
        s+='b';
        j=0;
        l=0;
        ll p=0;
        m=-1000000;
        ll q=0;
        bb[0]=0;
        for(i=0,j=0,l=0; i<s.size(); i++)
        {
            if(s[i]=='b')
            {

                p++;
                if(p==k)
                {
                    q=c;
                    if(j-k>=0)
                    q=c+j-bb[j-k];
                    m=max(m,q);
                    p--;
                }
                j++;
                bb[j]=c+j;
            }
            else
                c++;
        }
        cout<<m<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        c=0;
        queue<ll>q;
        l=0;
        v=0;
        r=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='b')
            {
                q.push(i);
                c++;
                if(c>k)
                {
                    r=1;
                    c-=1;
                    v=max(i-l,v);
                    l=q.front()+1;
                    q.pop();

                }
            }

        }
        //cout<<v;

            v=max(i-l,v);
        c=0;
       // cout<<v<<endl<<endl;
        queue<ll>qq;
        l=0;
        r=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='a')
            {
                //cout<<i<<endl;
                qq.push(i);
                c++;
                if(c>k)
                {
                    r=1;
                    c-=1;
                    v=max((i-l),v);
                   // cout<<i-l<<endl;
                    l=qq.front()+1;
                    qq.pop();

                }
            }

        }

            v=max(i-l,v);
        cout<<v;

    }
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        b=0;
        c=0;
        s+='b';
        j=0;
        l=0;
        ll p=0;
        m=-1000000;
        ll q=0;
        bb[0]=0;
        for(i=0,j=0,l=0; i<s.size(); i++)
        {
            if(s[i]=='b')
            {

                p++;
                if(p==k)
                {
                    q=c;
                    if(j-k>=0)
                    q=c+j-bb[j-k];
                    m=max(m,q);
                    p--;
                }
                j++;
                bb[j]=c+j;
            }
            else
                c++;
        }
        if(m<0)
            cout<<c<<endl;
        else
        cout<<m<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        c=0;
        queue<ll>q;
        l=0;
        v=0;
        r=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='b')
            {
                q.push(i);
                c++;
                if(c>k)
                {
                    r=1;
                    c=1;
                    v=max(i-l,v);
                    l=q.front()+1;
                    q.pop();

                }
            }

        }
        //cout<<v;
        if(r==1)
            v=max(i-1-l,v);
        else
            v=max(i-l,v);
        c=0;
        //cout<<v;
        queue<ll>qq;
        l=0;
        r=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='a')
            {
                //cout<<i<<endl;
                qq.push(i);
                c++;
                if(c>k)
                {
                    r=1;
                    c=1;
                    v=max((i-l),v);
                    //cout<<i-l<<endl;
                    l=qq.front()+1;
                    qq.pop();

                }
            }

        }
        if(r==1)
            v=max(i-1-l,v);
        else
            v=max(i-l,v);
        cout<<v;

    }
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        c=0;
        queue<ll>q;
        l=0;
        v=0;
        r=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='b')
            {
                q.push(i);
                c++;
                if(c>k)
                {
                    r=1;
                    c-=1;
                    v=max(i-l,v);
                    l=q.front();
                    q.pop();

                }
            }

        }
        //cout<<v;
        if(r==1)
            v=max(i-1-l,v);
        else
            v=max(i-l,v);
        c=0;
       // cout<<v<<endl<<endl;
        queue<ll>qq;
        l=0;
        r=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='a')
            {
                //cout<<i<<endl;
                qq.push(i);
                c++;
                if(c>k)
                {
                    r=1;
                    c-=1;
                    v=max((i-l),v);
                   // cout<<i-l<<endl;
                    l=qq.front();
                    qq.pop();

                }
            }

        }
        if(r==1)
            v=max(i-1-l,v);
        else
            v=max(i-l,v);
        cout<<v;

    }
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        c=0;
        queue<ll>q;
        l=0;
        v=0;
        r=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='b')
            {
                q.push(i);
                c++;
                if(c>k)
                {
                    r=1;
                    c-=1;
                    v=max(i-l,v);
                    l=q.front()+1;
                    q.pop();

                }
            }

        }
        //cout<<v;
        if(r==1)
            v=max(i-1-l,v);
        else
            v=max(i-l,v);
        c=0;
        //cout<<v;
        queue<ll>qq;
        l=0;
        r=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='a')
            {
                //cout<<i<<endl;
                qq.push(i);
                c++;
                if(c>k)
                {
                    r=1;
                    c-=1;
                    v=max((i-l),v);
                    //cout<<i-l<<endl;
                    l=qq.front()+1;
                    qq.pop();

                }
            }

        }
        if(r==1)
            v=max(i-1-l,v);
        else
            v=max(i-l,v);
        cout<<v;

    }
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        c=0;
        queue<ll>q;
        l=0;
        v=0;
        for(i=0; i<n; i++)
        {
            if(s[i]=='b')
            {
                q.push(i);
                c++;
                if(c>k)
                {
                    c=1;
                    v=max(i-l,v);
                    l=q.front();
                    q.pop();

                }
            }

        }
        //cout<<v;
        v=max(i-1-l,v);
        c=0;
        queue<ll>qq;
        l=0;

        for(i=0; i<n; i++)
        {
            if(s[i]=='a')
            {//cout<<i<<endl;
                qq.push(i);
                c++;
                if(c>k)
                {
                    c=1;
                    v=max((i-l),v);
                    //cout<<i-l<<endl;
                    l=qq.front();
                    qq.pop();

                }
            }

        }
        v=max(i-l-1,v);
        cout<<v;

    }
}


#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
#define     sf(n)        scanf("%lld",&n)
#define     pf(n)        printf("%lld\n",&n)
#define     ct(p)        cout<<p<<endl
#define     mem(a)       memset(a,0,sizeof a)
#define     yes          cout<<"YES"<<endl
#define     no           cout<<"NO"<<endl

ll a[10000000];
map<ll,ll,ll>mp;
map<ll,ll>mp1;
vector<pair<ll,ll> > vec;
///......................................///

int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,b,bv[1000],aa[1009],bb[1000],n,m,r,t,e,f;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3,ss[10000];
    while(cin>>n)
    {
        cin>>k;
        cin>>s;
        b=0;
        c=0;
        s+='b';
        j=0;
        l=0;
        ll p=0;
        m=-1000000;
        ll q=0;
        bb[0]=0;
        for(i=0,j=0,l=0; i<s.size(); i++)
        {
            if(s[i]=='b')
            {

                p++;
                if(p==k)
                {
                    q=c;
                    if(j-k>=0)
                    q=c+j-bb[j-k];
                    m=max(m,q);
                    p--;
                }
                j++;
                bb[j]=c+j;
            }
            else
                c++;
        }
        if(m<0)
            cout<<"0"<<endl;
        else
        cout<<m<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

    int main()
    {
        int n, k;
        string str;
        cin >> n >> k;
        cin >> str;
        int s = 0, sum = 0;
        int ans = 0;
        for (int i = 0; i < n; ++i)
        {
            if (str[i] == 'b')
                sum++;
            while (sum > k)
                if (str[s++] == 'b')
                    sum--;
            ans = max(ans, i - s + 1);
        }
        s = 0;
        sum = 0;
        for (int i = 0; i < n; ++i)
        {
            if (str[i] == 'a')
                sum++;
            while (sum > k)
                if (str[s++] == 'a')
                    sum--;
            ans = max(ans, i - s + 1);
        }
        cout << ans << endl;
    return 0;
    }


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll n,k,i,d=0,e=0,f=0,sum=0,sum1,to=0,to1;
	string s;
	cin>>n>>k>>s;
     vector<ll>v;
      vector<ll>u;

     for(i=0;i<s.length()-1;i++)
     {
        if(s[i]=='a')
        {
          d++;
           if(s[i+1]!='a')
           {
           	v.push_back(d);
           	d=0;
           }
        }
        else
        {
        	e++;
        	if(s[i+1]!='b')
        	{
        		v.push_back(e);
        		e=0;
        	}
        }

     }
     if(s[n-1]=='a')
     {
     	v.push_back(d+1);
     }
     if(s[n-1]=='b')
     	v.push_back(e+1);

     sum+=v[0];
     for(auto it1=v.begin(),it2=v.begin()+1;it2!=v.end();it2++)
      {
        if(f+*it2<=k)
        {
        	f+=*it2;
        	sum+=*it2;
        	it2++;
        	if(it2!=v.end())
        	sum+=*it2;
        }
        else
        {
        	sum1=sum;
        	sum-=*it1;
        	it1++;
        	f-=*it1;
        	it1++;

           sum=max(sum,sum1);
        }
      }
      f=0;
      to+=v[1];
     for(auto it3=v.begin()+1,it4=v.begin()+2;it4!=v.end();it4++)
      {
        if(f+*it4<=k)
        {
        	f+=*it4;
        	to+=*it4;
        	it4++;
        	if(it4!=v.end())
        	to+=*it4;
        }
        else
        {
        	to1=to;
        	to-=*it3;
        	it3++;
        	f-=*it3;
        	it3++;

           to=max(to,to1);
        }
      }

     cout<<max(sum,to);

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll i,j,n,k,l=0,sum=1,p=0,q=0;
  string s;
  cin>>n>>k;
   cin>>s;

  while(l<n)
  {
     for(j=l+1;p<=k &&  j<n;j++)
     {
      if(s[j]!=s[l])
        p++;
      sum++;
     }
     if(p>k)
      sum--;
     q=max(q,sum);
     sum=1;
     p=0;
     l++;
  }
  cout<<q;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll i,j,n,k,l=0,sum=1,p=0,q=0,t,r=0;
  string s;
  cin>>n>>k;
   cin>>s;

  while(l<n)
  {
     for(j=l+1;p<=k &&  j<n;j++)
     {
      if(s[j]!=s[l])
      {
        if(r==0)
        {
          t=j;
          r=1;
        }
        p++;
      }
      sum++;
     }
     if(p>k)
      sum--;
     q=max(q,sum);
     sum=1;
     p=0;
     r=0;
     l+=t+1;
  }
  cout<<q;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll i,j,n,k,l=0,sum=1,p=0,q=0,t,r=0,x=0,y;
  string s;
  cin>>n>>k;
   cin>>s;

  while(l<n)
  {
     for(j=l+1;p<=k &&  j<n;j++)
     {
      if(s[j]!=s[l])
      {
        if(r==0)
        {
          if(x==0)
          {
            y=j;
            x=1;
          }
          t=j;
          r=1;
        }
        p++;
      }
      sum++;
     }
     if(p>k)
      sum--;
     q=max(q,sum);
     sum=1;
     p=0;
     r=0;
     l+=t+1;
  }

   l=y;

  while(l<n)
  {
     for(j=l+1;p<k+1 &&  j<n;j++)
     {
      if(s[j]!=s[l])
      {
        if(r==0)
        {
          t=j;
          r=1;
        }
        p++;
      }
      sum++;
     }
      sum--;
     q=max(q,sum);
     sum=1;
     p=0;
     r=0;
     l+=t+1;
  }

  cout<<q;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll n,k,i,d=0,e=0,f=0,sum=0,sum1,to=0,to1;
	string s;
	cin>>n>>k>>s;
     vector<ll>v;
      vector<ll>u;

     for(i=0;i<s.length()-1;i++)
     {
        if(s[i]=='a')
        {
          d++;
           if(s[i+1]!='a')
           {
           	v.push_back(d);
           	d=0;
           }
        }
        else
        {
        	e++;
        	if(s[i+1]!='b')
        	{
        		v.push_back(e);
        		e=0;
        	}
        }

     }
     if(s[n-1]=='a')
     {
     	v.push_back(d+1);
     }
     if(s[n-1]=='b')
     	v.push_back(e+1);

     sum+=v[0];
     for(auto it1=v.begin(),it2=v.begin()+1;it2!=v.end();it2++)
      {
        if(f+*it2<=k)
        {
        	f+=*it2;
        	sum+=*it2;
        	it2++;
        	sum+=*it2;
        }
        else
        {
        	sum1=sum;
        	sum-=*it1;
        	it1++;
        	f-=*it1;
        	it1++;

           sum=max(sum,sum1);
        }
      }
      f=0;
      to+=v[1];
     for(auto it3=v.begin()+1,it4=v.begin()+2;it4!=v.end();it4++)
      {
        if(f+*it4<=k)
        {
        	f+=*it4;
        	to+=*it4;
        	it4++;
        	to+=*it4;
        }
        else
        {
        	to1=to;
        	to-=*it3;
        	it3++;
        	f-=*it3;
        	it3++;

           to=max(to,to1);
        }
      }
     cout<<max(sum,to);

}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll i,j,n,k,l=0,sum=1,p=0,q=0,t,r=0,x=0,y;
  string s;
  cin>>n>>k;
   cin>>s;

  while(l<n)
  {
     for(j=l+1;p<=k &&  j<n;j++)
     {
      if(s[j]!=s[l])
      {
        if(r==0)
        {
          if(x==0)
          {
            y=j;
            x=1;
          }
          t=j;
          r=1;
        }
        p++;
      }
      sum++;
     }
     if(p>k)
      sum--;
     q=max(q,sum);
     sum=1;
     p=0;
     r=0;
     l+=t+1;
  }

   l=y;
  while(l<n)
  {
     for(j=l+1;p<=k &&  j<n;j++)
     {
      if(s[j]!=s[l])
      {
        if(r==0)
        {
          t=j;
          r=1;
        }
        p++;
      }
      sum++;
     }
     if(p>k)
      sum--;
     q=max(q,sum);
     sum=1;
     p=0;
     r=0;
     l+=t+1;
  }

  cout<<q;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 1152921504606846976
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
#define check(n,pos) (n&(1<<pos))
#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
int main()
{
    char c;
    ll n,k,i,p,q,a[100005],b[100005],max1,max2,j;
    while(cin>>n>>k)
    {
        a[0]=b[0]=0;
        max1=max2=-1;;
        vector<ll>v,v1;
        v.pb(0),v1.pb(0);
        for(i=1;i<=n;i++)
        {
            cin>>c;
            if(c=='a')
                v.pb(i);
            else
                v1.pb(i);
        }
        v.pb(n+1),v1.pb(n+1);
        if(v.sz-2>k&&v1.sz-2>k)
        {
        for(i=k+2;i<v.sz;i++)
        {
            p=v[i-k-1]+1;
            max1=max(max1,v[i]-p);
        }
        for(i=k+2;i<v1.sz;i++)
        {
            p=v1[i-k-1]+1;
            max2=max(max2,v1[i]-p);
        }
        cout<<max(max1,max2)<<endl;
        }
        else
            cout<<n<<endl;
    }
    return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 1152921504606846976
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
#define check(n,pos) (n&(1<<pos))
#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
int main()
{
    char c;
    ll n,k,i,p,q,a[100005],b[100005],max1,min1,j;
    while(scanf("%lld%lld",&n,&k)==2)
    {
        a[0]=b[0]=0;
        max1=0;
        for(i=1;i<=n;i++)
        {
            scanf("%c",&c);
            if(c=='a')
                a[i]=a[i-1]+1;
            else
                a[i]=a[i-1];
            if(c=='b')
                b[i]=b[i-1]+1;
            else
                b[i]=b[i-1];
        }
        for(i=1;i<=n;i++)
        {
            for(j=i-1;j>=1;j--)
            {
                p=a[i]-a[j-1];
                q=b[i]-b[j-1];
                min1=min(p,q);
                if(min1<=k)
                {
                    max1=max(max1,i-j);
                }
                else
                    break;
            }
        }
        cout<<max1+1<<endl;
    }
    return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 1152921504606846976
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
#define check(n,pos) (n&(1<<pos))
#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
int main()
{
    char c;
    ll n,k,i,p,q,a[100005],b[100005],max1,max2,j;
    while(cin>>n>>k)
    {
        a[0]=b[0]=0;
        max1=max2=-1;;
        vector<ll>v,v1;
        v.pb(0),v1.pb(0);
        for(i=1;i<=n;i++)
        {
            cin>>c;
            if(c=='a')
                v.pb(i);
            else
                v1.pb(i);
        }
        v.pb(n+1),v1.pb(n+1);
        if(v.sz-2>=k&&v1.sz-2>=k)
        {
        for(i=k+2;i<v.sz;i++)
        {
            p=v[i-k-1]+1;
            max1=max(max1,v[i]-p);
        }
        for(i=k+2;i<v1.sz;i++)
        {
            p=v1[i-k-1]+1;
            max2=max(max2,v1[i]-p);
        }
        cout<<max(max1,max2)<<endl;
        }
        else
            cout<<n<<endl;
    }
    return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 1152921504606846976
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
#define check(n,pos) (n&(1<<pos))
#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
int main()
{
    char c;
    ll n,k,i,p,q,a[100005],b[100005],max1,min1,j;
    while(cin>>n>>k)
    {
        a[0]=b[0]=0;
        max1=0;
        for(i=1;i<=n;i++)
        {
            cin>>c;
            if(c=='a')
                a[i]=a[i-1]+1;
            else
                a[i]=a[i-1];
            if(c=='b')
                b[i]=b[i-1]+1;
            else
                b[i]=b[i-1];
        }
        for(i=1;i<=n;i++)
        {
            for(j=i-1;j>=1;j--)
            {
                p=a[i]-a[j-1];
                q=b[i]-b[j-1];
                min1=min(p,q);
                if(min1<=k)
                {
                    max1=max(max1,i-j+1);
                }
            }
        }
        cout<<max1<<endl;
    }
    return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 1152921504606846976
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
#define check(n,pos) (n&(1<<pos))
#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
int main()
{
    char c;
    ll n,k,i,p,q,a[100005],b[100005],max1,min1,j;
    while(cin>>n>>k)
    {
        a[0]=b[0]=0;
        max1=0;
        for(i=1;i<=n;i++)
        {
            cin>>c;
            if(c=='a')
                a[i]=a[i-1]+1;
            else
                a[i]=a[i-1];
            if(c=='b')
                b[i]=b[i-1]+1;
            else
                b[i]=b[i-1];
        }
        for(i=1;i<=n;i++)
        {
            for(j=i-1;j>=1;j--)
            {
                p=a[i]-a[j-1];
                q=b[i]-b[j-1];
                min1=min(p,q);
                if(min1<=k)
                {
                    max1=max(max1,i-j);
                }
            }
        }
        cout<<max1+1<<endl;
    }
    return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 1152921504606846976
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
#define check(n,pos) (n&(1<<pos))
#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
int main()
{
    char c;
    ll n,k,i,p,q,a[100005],b[100005],max1,min1,j;
    while(ent2(n,k)==2)
    {
        a[0]=b[0]=0;
        max1=0;
        getchar();
        for(i=1;i<=n;i++)
        {
            scanf("%c",&c);
            if(c=='a')
                a[i]=a[i-1]+1;
            else
                a[i]=a[i-1];
            if(c=='b')
                b[i]=b[i-1]+1;
            else
                b[i]=b[i-1];
        }
        for(i=1;i<=n;i++)
        {
            for(j=i-1;j>=1;j--)
            {
                p=a[i]-a[j-1];
                q=b[i]-b[j-1];
                min1=min(p,q);
                if(min1<=k)
                {
                    max1=max(max1,i-j);
                }
                else
                    break;
            }
        }
        cout<<max1+1<<endl;
    }
    return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 1152921504606846976
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
#define check(n,pos) (n&(1<<pos))
#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
int main()
{
    char c;
    ll n,k,i,p,q,a[100005],b[100005],max1,max2,j;
    while(cin>>n>>k)
    {
        a[0]=b[0]=0;
        max1=max2=-1;;
        vector<ll>v,v1;
        v.pb(0),v1.pb(0);
        for(i=1;i<=n;i++)
        {
            cin>>c;
            if(c=='a')
                v.pb(i);
            else
                v1.pb(i);
        }
        v.pb(n+1),v1.pb(n+1);
        if(v.sz-2>k&&v1.sz-2>k)
        {
        for(i=k+1;i<v.sz;i++)
        {
            p=v[i-k-1]+1;
            //cout<<v[i]<<" "<<p<<endl;
            max1=max(max1,v[i]-p);
        }
        for(i=k+1;i<v1.sz;i++)
        {
            p=v1[i-k-1]+1;
            max2=max(max2,v1[i]-p);
        }
        cout<<max(max1,max2)<<endl;
        }
        else
            cout<<n<<endl;
    }
    return 0;
}


/*
Nahid Hossain
Jahangirnagar University
Roll:54
*/
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 1152921504606846976
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
#define check(n,pos) (n&(1<<pos))
#define set(n,pos)  (n|(1<<pos))
//knight and king//
int dr[]={2,2,-2,-2,1,-1,1,-1};
int dc[]={1,-1,1,-1,2,2,-2,-2};
int dr1[]={0,0,1,1,1,-1,-1,-1};
int dc1[]={1,-1,1,0,-1,0,1,-1};
int dr2[]={0,0,1,-1};
int dc2[]={1,-1,0,0};
////////////////////////////
using namespace std;
int main()
{
    char c;
    ll n,k,i,p,q,a[100005],b[100005],max1,min1,j;
    while(cin>>n>>k)
    {
        a[0]=b[0]=0;
        max1=0;
        for(i=1;i<=n;i++)
        {
            cin>>c;
            if(c=='a')
                a[i]=a[i-1]+1;
            else
                a[i]=a[i-1];
            if(c=='b')
                b[i]=b[i-1]+1;
            else
                b[i]=b[i-1];
        }
        for(i=1;i<=n;i++)
        {
            for(j=i-1;j>=1;j--)
            {
                p=a[i]-a[j-1];
                q=b[i]-b[j-1];
                min1=min(p,q);
                if(min1<=k)
                {
                    max1=max(max1,i-j);
                }
                else
                    break;
            }
        }
        cout<<max1+1<<endl;
    }
    return 0;
}


/*
Author: Sanskar Agarwal
Nick: sanskaragarwal
Birla Institute Of Technology, Mesra
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define INF 100009
#define mod 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
string s;
int n;

int changeStr(char p, int k, int i)
{
    if(i>=n)
        return 0;
    if(i==0 || p==s[i])
        return 1+changeStr(s[i], k, i+1);
    int t= p-'a';
    int a=INT_MIN;
    if(k>0)
        a= 1+changeStr(p, k-1, i+1);
    int b= 0;
    return max(a,b);
}

int main()
{
    int k;
    cin>>n>>k;
    cin>>s;
    int d= s[0]-'a';
    int a=INT_MIN;
    for(int i=0;i<n;++i)
    {
        a= max(a,changeStr(s[i],k,i));
    }
    cout<<a<<endl;
    return 0;
}


/*
Author: Sanskar Agarwal
Nick: sanskaragarwal
Birla Institute Of Technology, Mesra
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define INF 100009
#define mod 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
string s;
int n;
int dp[100005];

int changeStr(char p, int k, int i)
{
    if(i>=n)
        return 0;
    if(i==0 || p==s[i])
        return 1+changeStr(s[i], k, i+1);
    if(dp[i]!=-1)
        return dp[i];
    int t= p-'a';
    int a=INT_MIN;
    if(k>0)
        a= 1+changeStr(p, k-1, i+1);
    int b= 0;
    return max(a,b);
}

int main()
{
    fast
    int k;
    cin>>n>>k;
    cin>>s;
    int d= s[0]-'a';
    int a=INT_MIN;
    for(int i=0;i<n;++i)
        dp[i]=-1;
    for(int i=0;i<n;++i)
    {
        a= max(a,changeStr(s[i],k,i));
    }
    cout<<a<<endl;
    return 0;
}


/*
Author: Sanskar Agarwal
Nick: sanskaragarwal
Birla Institute Of Technology, Mesra
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define INF 100009
#define mod 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
string s;
int n;
int dp[100005][2];

int changeStr(char p, int k, int i)
{
    if(i>=n)
        return 0;
    if(i==0 || p==s[i])
        return 1+changeStr(s[i], k, i+1);
    int t= p-'a';
    if(dp[i][t]!=-1)
        return dp[i][t];
    int a=INT_MIN;
    if(k>0)
        a= 1+changeStr(p, k-1, i+1);
    int b= 0;
    return dp[i][t]=max(a,b);
}

int main()
{
    int k;
    cin>>n>>k;
    cin>>s;
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<2;++j)
        {
            dp[i][j]=-1;
        }
    }
    int d= s[0]-'a';
    dp[0][d]=1;
    int a= changeStr(s[0],k,0);
    cout<<a<<endl;
    return 0;
}


/*
Author: Sanskar Agarwal
Nick: sanskaragarwal
Birla Institute Of Technology, Mesra
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define INF 100009
#define mod 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second

string s;
int n,k;

int calMax(char c)
{
    int r=0;
    int count=0;
    int tc=0;
    int temp= k;
    for(int l=0;l<n;++l)
    {
        while((temp>0 || s[r]==c))
        {
            if(s[r]!=c)
                temp--;
            tc++;
            if(r==n-1)
                return max(count, tc);
            r++;
        }
        cout<<"HELLO"<<endl;
        while(s[min(l,n-1)]==c && l<n)
        {
            cout<<"HELLO"<<endl;
            tc--;
            l++;
        }
        temp--;
        l--;
        count=max(count,tc);
    }
    return count;
}

int main()
{
    fast
    cin>>n>>k;
    cin>>s;
    int counta=0,countb=0;
    int l=0, r=0;
    /*
    for(int i=0;i<n;++i)
    {
        if(s[i]=='a')
            counta++;
        else
            countb++;
    }
    */
    int ans=INT_MIN, kt=0, tempAns=0;
    while(l<n && r<n)
    {
        if(s[r]=='a')
        {
            tempAns++;
            r++;
        }
        else if(kt<k)
        {
            tempAns++;
            kt++;
            r++;
        }
        else
        {
            while(s[l]!='b')
            {
                l++;
                tempAns--;
            }
            l++;
            tempAns--;
            r++;
        }
        ans=max(ans, tempAns);
    }
    l=0,r=0,tempAns=0;
    while(l<n && r<n)
    {
        if(s[r]=='b')
        {
            tempAns++;
            r++;
        }
        else if(kt<k)
        {
            tempAns++;
            kt++;
            r++;
        }
        else
        {
            while(s[l]!='a')
            {
                l++;
                tempAns--;
            }
            l++;
            tempAns--;
            r++;
        }
        ans=max(ans, tempAns);
    }
    cout<<ans<<endl;
    return 0;
}


/*
Author: Sanskar Agarwal
Nick: sanskaragarwal
Birla Institute Of Technology, Mesra
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define INF 100009
#define mod 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second

string s;
int n,k;

int calMax(char c)
{
    int r=0;
    int count=0;
    int tc=0;
    int temp= k;
    for(int l=0;l<n;++l)
    {
        while((temp>0 || s[r]==c))
        {
            if(s[r]!=c)
                temp--;
            tc++;
            if(r==n-1)
                return max(count, tc);
            r++;
        }
        cout<<"HELLO"<<endl;
        while(s[min(l,n-1)]==c && l<n)
        {
            cout<<"HELLO"<<endl;
            tc--;
            l++;
        }
        temp--;
        l--;
        count=max(count,tc);
    }
    return count;
}

int main()
{
    fast
    cin>>n>>k;
    cin>>s;
    int counta=0,countb=0;
    int l=0, r=0;
    /*
    for(int i=0;i<n;++i)
    {
        if(s[i]=='a')
            counta++;
        else
            countb++;
    }
    */
    int ans=INT_MIN, kt=0, tempAns=0;
    while(l<n && r<n)
    {
        if(s[r]=='a')
        {
            tempAns++;
            r++;
        }
        else if(kt<k)
        {
            tempAns++;
            kt++;
            r++;
        }
        else
        {
            while(s[l]!='b')
            {
                l++;
                tempAns--;
            }
            l++;
            tempAns--;
            r++;
        }
        ans=max(ans, tempAns);
    }
    l=0,r=0,tempAns=0,kt=0;
    while(l<n && r<n)
    {
        if(s[r]=='b')
        {
            tempAns++;
            r++;
        }
        else if(kt<k)
        {
            tempAns++;
            kt++;
            r++;
        }
        else
        {
            while(s[l]!='a')
            {
                l++;
                tempAns--;
            }
            l++;
            tempAns--;
            r++;
        }
        ans=max(ans, tempAns);
    }
    cout<<ans<<endl;
    return 0;
}


/*
Author: Sanskar Agarwal
Nick: sanskaragarwal
Birla Institute Of Technology, Mesra
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define INF 100009
#define mod 1000000007
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second

int main()
{
    fast
    string s;
    int n,k;
    cin>>n>>k;
    cin>>s;
    int l=0, r=0;
    /*
    for(int i=0;i<n;++i)
    {
        if(s[i]=='a')
            counta++;
        else
            countb++;
    }
    */
    int ans=INT_MIN, kt=0, tempAns=0;
    while(l<n && r<n)
    {
        if(s[r]=='a')
        {
            tempAns++;
            r++;
        }
        else if(kt<k)
        {
            tempAns++;
            kt++;
            r++;
        }
        else
        {
            while(s[l]!='b')
            {
                l++;
                tempAns--;
            }
            l++;
            r++;
        }
        ans=max(ans, tempAns);
    }
    l=0,r=0,tempAns=0,kt=0;
    while(l<n && r<n)
    {
        //cout<<l<<" "<<r<<" "<<tempAns<<endl;
        if(s[r]=='b')
        {
            tempAns++;
            r++;
        }
        else if(kt<k)
        {
            tempAns++;
            kt++;
            r++;
        }
        else
        {
            while(s[l]!='a')
            {
                l++;
                tempAns--;
            }
            l++;
            r++;
        }
        ans=max(ans, tempAns);
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
pair<long,long> a[5009];
long dau[5009], cuoi[5009];
main(){
	string s;
	cin>>s;
	long u=1;
	a[0].first=a[0].second=0;
	long x=0,y=0;
	for(long i=0;i<s.length();i++){
		if(s[i]!=s[i-1]&&i>0){
			a[u].first=x+y;
			if(x>0)	a[u].second=1;
			else a[u].second=2;
			u++;
			x=y=0;
		}
		if(s[i]=='a'){
			x++;
		}
		else{
			y++;
		}
	}
	if(x+y>0){
		a[u].first=x+y;
		if(x>0)	a[u].second=1;
		else a[u].second=2;
		x=y=0;
		u++;
	}
	long kq=0;
	dau[0]=0, cuoi[u]=0;
	for(long i=1;i<u;i++){
		if(a[i].second==1){
			dau[i]=dau[i-1]+a[i].first;
		}
		else	dau[i]=dau[i-1];
	}
	for(long i=u-1;i>=1;i--){
		if(a[i].second==1){
			cuoi[i]=cuoi[i+1]+a[i].first;
		}
		else	cuoi[i]=cuoi[i+1];
	}
	for(long i=1;i<u;i++){
		if(a[i].second==2){
			kq=max(kq,a[i].first+dau[i]+cuoi[i]);
		}
	}
	cout<<kq;
}


#include<bits/stdc++.h>
using namespace std;
pair<long,long> a[5009];
long dau[5009], cuoi[5009];
main(){
	string s;
	cin>>s;
	long u=1;
	char e=s[0];
	if(s[0]=='a')	a[1].second=1;
	else a[1].second=2;
	a[1].first=0;
	for(long i=0;i<s.length();i++){
		if(s[i]==e){
			a[u].first++;
		}
		else{
			e=s[i];
			u++;
			if(e=='a')	a[u].second=1;
			else	a[u].second =2;
			a[u].first=1;
		}
	}
	long kq=0;
	dau[0]=0, cuoi[u]=0;
	for(long i=1;i<=u;i++){
		if(a[i].second==1){
			dau[i]=dau[i-1]+a[i].first;
		}
		else	dau[i]=dau[i-1];
	}
	for(long i=u;i>=1;i--){
		if(a[i].second==1){
			cuoi[i]=cuoi[i+1]+a[i].first;
		}
		else	cuoi[i]=cuoi[i+1];
	}
	for(long i=1;i<=u;i++){
		if(a[i].second==2){
			kq=max(kq,a[i].first+dau[i]+cuoi[i]);
		}
	}
	cout<<kq;
}


#include<bits/stdc++.h>
using namespace std;
pair<long,long> a[5009];
main(){
	string s;
	cin>>s;
	long u=1;
	char e=s[0];
	if(s[0]=='a')	a[1].second=1;
	else a[1].second=2;
	a[1].first=0;
	for(long i=0;i<s.length();i++){
		if(s[i]==e){
			a[u].first++;
		}
		else{
			e=s[i];
			u++;
			if(e=='a')	a[u].second=1;
			else	a[u].second =2;
			a[u].first=1;
		}
	}
	long kq=0,kk=0;
	a[0].second=a[u+1].second=2;
	for(long i=1;i<=u;i++){
		if(a[i].second==2){
			if(a[i-1].second==1){
				kk+=a[i-1].first;
			}
			if(a[i+1].second==1){
				kk+=a[i+1].first;
			}
			kq=max(kq,a[i].first+kk);
			kk=0;
		}
	}
	cout<<kq;
}


#include <iostream>
#include <cstring>
using namespace std;

int main(){
    char input[5001];
    int prefixa[5001], prefixb[5001];
    int numa, numb, max;
    while(cin>>input){
        int len = strlen(input);
        numa = numb = 0;

        prefixa[0] = prefixb[0] = 0;
        for (int i = 0; i < len; ++i){
            if (input[i] == 'a')  ++numa;
            else   ++numb;
            prefixa[i + 1] = numa;
            prefixb[i + 1] = numb;
        }

        max = 0;
        for (int i = 0; i < len; ++i){
            for (int j = i; j < len; ++j){
                int length = prefixa[len] - prefixa[j + 1] + prefixa[i] + prefixb[j + 1] - prefixb[i];
                if (max < length)
                    max = prefixa[len] - prefixa[j + 1] + prefixa[i] + prefixb[j + 1] - prefixb[i];
            }
        }
        cout<<max<<endl;
    }
}


#include <iostream>
#include <cstring>
using namespace std;

int main(){
    char input[5001];
    int prefixa[5001], prefixb[5001];
    int numa, numb, max;
    while(cin>>input){
        int len = strlen(input);
        numa = numb = 0;

        for (int i = 0; i < len; ++i){
            if (input[i] == 'a')  ++numa;
            else   ++numb;
            prefixa[i] = numa;
            prefixb[i] = numb;
        }

        max = 0;
        for (int i = 0; i < len; ++i){
            for (int j = i; j < len; ++j){
                int length = prefixa[len - 1] - prefixa[j] + prefixa[i - 1] + prefixb[j] - prefixb[i - 1];
                if (max < length)
                    max = prefixa[len - 1] - prefixa[j] + prefixa[i - 1] + prefixb[j] - prefixb[i - 1];
            }
        }
        cout<<max<<endl;
    }
}


#include <iostream>
#include <cstring>
using namespace std;

int main(){
    char input[5001];
    int prefixa[5001], prefixb[5001];
    int numa, numb, max;
    while(cin>>input){
        int len = strlen(input);
        numa = numb = 0;

        prefixa[0] = prefixb[0] = 0;
        for (int i = 0; i < len; ++i){
            if (input[i] == 'a')  ++numa;
            else   ++numb;
            prefixa[i + 1] = numa;
            prefixb[i + 1] = numb;
        }

        max = 0;
        for (int i = 0; i < len; ++i){
            for (int j = i; j < len; ++j){
                int length;
                if (input[j] == 'b')
                    length = prefixa[len] - prefixa[j] + prefixa[i] + prefixb[j] - prefixb[i] + 1;
                else
                    length = prefixa[len] - prefixa[j] + prefixa[i] + prefixb[j] - prefixb[i];
                if (max < length)
                    max = length;
            }
        }
        cout<<max<<endl;
    }
}


#include <iostream>
#include <cstring>
using namespace std;

int main(){
    char input[5001];
    int prefixa[5001], prefixb[5001];
    int numa, numb, max;
    while(cin>>input){
        int len = strlen(input);
        numa = numb = 0;

        for (int i = 0; i < len; ++i){
            if (input[i] == 'a')  ++numa;
            else   ++numb;
            prefixa[i] = numa;
            prefixb[i] = numb;
        }

        max = 0;
        for (int i = 1; i < len; ++i){
            for (int j = i; j < len; ++j){
                int length = prefixa[len - 1] - prefixa[j] + prefixa[i - 1] + prefixb[j] - prefixb[i - 1];
                if (max < length)
                    max = prefixa[len - 1] - prefixa[j] + prefixa[i - 1] + prefixb[j] - prefixb[i - 1];
            }
        }
        cout<<max<<endl;
    }
}


#include <iostream>
#include <cstring>
using namespace std;

int main(){
    char input[5001];
    int prefixa[5001], prefixb[5001];
    int numa, numb, max;
    while(cin>>input){
        int len = strlen(input);
        numa = numb = 0;

        for (int i = 0; i < len; ++i){
            if (input[i] == 'a')  ++numa;
            else   ++numb;
            prefixa[i] = numa;
            prefixb[i] = numb;
        }

        max = 0;
        for (int i = 0; i < len; ++i){
            for (int j = i; j < len; ++j){
                int length = prefixa[len - 1] - prefixa[j] + prefixa[i] + prefixb[j] - prefixb[i];
                if (max < length)
                    max = prefixa[len - 1] - prefixa[j] + prefixa[i] + prefixb[j] - prefixb[i];
            }
        }
        cout<<max<<endl;
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<cctype>
#include<cstring>
#include<bits/stdc++.h>

#define pb push_back
#define sf(x) scanf("%d",&x)
#define p_f(x) printf("%d ",x)
#define pf(x) printf("%d\n",x)

using namespace std;

typedef long long ll;
typedef double dl;
ll mod=1e9+7;
typedef pair<int,int> pa;
int maxn=1e9,minn=-1e9;

ll modpow(ll base,ll exp,int modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

/*array globally declared. and size of array in n.
void convert(int n)
{
    int temp[n];
    memcpy(temp, arr, n*sizeof(int));
    sort(temp, temp + n);
    map<int, int> umap;

    int val = 0;
    for (int i = 0; i < n; i++)
        umap[temp[i]] = val++;

    // Convert array by taking positions from
    // umap
    for (int i = 0; i < n; i++)
        arr[i] = umap[arr[i]];
}*/

int sqr(int x){
    return x*x;
}

bool is_prime(int x){
    for(int i=2;i*i<=x;++i){
        if(x%i==0)
            return false;
    }
    return true;
}

char arr[5005];
int n;
int dp[5005][5];

int func(int i,int change){
	if(i>=n)
	    return 0;
	if(dp[i][change]!=-1)
	    return dp[i][change];
	int ans=0;
	ans=max(ans,func(i+1,change));
	if(change==1 || change==3){
		if(arr[i]=='a')
		    ans=max(ans,1+func(i+1,change));
	}
	if(change==2){
		if(arr[i]=='b')
		    ans=max(ans,1+func(i+1,change));
	}
	if(change<3){
		ans=max(ans,func(i,change+1));
	}
	return dp[i][change]=ans;
}

int main(){
	for(int i=0;i<5005;++i){
		for(int j=0;j<5;++j)
		    dp[i][j]=-1;
	}
    cin>>arr;
    n=strlen(arr);
 	cout<<func(0,1);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<cctype>
#include<cstring>
#include<bits/stdc++.h>

#define pb push_back
#define sf(x) scanf("%d",&x)
#define p_f(x) printf("%d ",x)
#define pf(x) printf("%d\n",x)

using namespace std;

typedef long long ll;
typedef double dl;
ll mod=1e9+7;
typedef pair<int,int> pa;
int maxn=1e9,minn=-1e9;

ll modpow(ll base,ll exp,int modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

/*array globally declared. and size of array in n.
void convert(int n)
{
    int temp[n];
    memcpy(temp, arr, n*sizeof(int));
    sort(temp, temp + n);
    map<int, int> umap;

    int val = 0;
    for (int i = 0; i < n; i++)
        umap[temp[i]] = val++;

    // Convert array by taking positions from
    // umap
    for (int i = 0; i < n; i++)
        arr[i] = umap[arr[i]];
}*/

int sqr(int x){
    return x*x;
}

bool is_prime(int x){
    for(int i=2;i*i<=x;++i){
        if(x%i==0)
            return false;
    }
    return true;
}

int main(){
    char arr[5005];
    cin>>arr;
    int n=strlen(arr);
 	int cons_a=0,a=0;
 	for(int i=0;i<n;++i){
 		if(arr[i]=='b'){
 			cons_a=max(cons_a,a);
 			a=0;
 		}
 		else
 		    a++;
 	}
 	cons_a=max(cons_a,a);
 	int cons_b=0,b=0;
 	for(int i=0;i<n;++i){
 		if(arr[i]=='a'){
 			cons_b=max(cons_b,b);
 			b=0;
 		}
 		else b++;
 	}
 	cons_b=max(cons_b,b);
 	int A=0,B=0;
 	for(int i=0;i<n;++i){
 		if(arr[i]=='a') A++;
 		else B++;
 	}
 	int ans=0;
 	if(arr[0]=='b')
 	    ans=A+cons_b;
 	else
 		ans=max(A+cons_b,B+cons_a);
 	cout<<ans;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<cctype>
#include<cstring>
#include<bits/stdc++.h>

#define pb push_back
#define sf(x) scanf("%d",&x)
#define p_f(x) printf("%d ",x)
#define pf(x) printf("%d\n",x)

using namespace std;

typedef long long ll;
typedef double dl;
ll mod=1e9+7;
typedef pair<int,int> pa;
int maxn=1e9,minn=-1e9;

ll modpow(ll base,ll exp,int modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

/*array globally declared. and size of array in n.
void convert(int n)
{
    int temp[n];
    memcpy(temp, arr, n*sizeof(int));
    sort(temp, temp + n);
    map<int, int> umap;

    int val = 0;
    for (int i = 0; i < n; i++)
        umap[temp[i]] = val++;

    // Convert array by taking positions from
    // umap
    for (int i = 0; i < n; i++)
        arr[i] = umap[arr[i]];
}*/

int sqr(int x){
    return x*x;
}

bool is_prime(int x){
    for(int i=2;i*i<=x;++i){
        if(x%i==0)
            return false;
    }
    return true;
}

int main(){
    char arr[5005];
    cin>>arr;
    int n=strlen(arr);
 	int cons_a=0,a=0;
 	for(int i=0;i<n;++i){
 		if(arr[i]=='b'){
 			cons_a=max(cons_a,a);
 			a=0;
 		}
 		else
 		    a++;
 	}
 	cons_a=max(cons_a,a);
 	int cons_b=0,b=0;
 	for(int i=0;i<n;++i){
 		if(arr[i]=='a'){
 			cons_b=max(cons_b,b);
 			b=0;
 		}
 		else b++;
 	}
 	cons_b=max(cons_b,b);
 	int A=0,B=0;
 	for(int i=0;i<n;++i){
 		if(arr[i]=='a') A++;
 		else B++;
 	}
 	int ans=max(A+cons_b,B+cons_a-1);
 	cout<<ans;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<cctype>
#include<cstring>
#include<bits/stdc++.h>

#define pb push_back
#define sf(x) scanf("%d",&x)
#define p_f(x) printf("%d ",x)
#define pf(x) printf("%d\n",x)

using namespace std;

typedef long long ll;
typedef double dl;
ll mod=1e9+7;
typedef pair<int,int> pa;
int maxn=1e9,minn=-1e9;

ll modpow(ll base,ll exp,int modulus) {
  base %= modulus;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

/*array globally declared. and size of array in n.
void convert(int n)
{
    int temp[n];
    memcpy(temp, arr, n*sizeof(int));
    sort(temp, temp + n);
    map<int, int> umap;

    int val = 0;
    for (int i = 0; i < n; i++)
        umap[temp[i]] = val++;

    // Convert array by taking positions from
    // umap
    for (int i = 0; i < n; i++)
        arr[i] = umap[arr[i]];
}*/

int sqr(int x){
    return x*x;
}

bool is_prime(int x){
    for(int i=2;i*i<=x;++i){
        if(x%i==0)
            return false;
    }
    return true;
}

int main(){
    char arr[5005];
    cin>>arr;
    int n=strlen(arr);
    int ans=0;
    for(int i=0;i<n;++i){
    	int cnt=1,ret=0;
    	if(arr[i]=='b'){
            cnt=2;
		}
    	for(int j=i;j<n;++j){
    		if(arr[j]!=arr[j+1]){
			   ++cnt;
			}
			++ret;
    		if(cnt>=4) break;
    	}
    	ans=max(ans,ret);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-3;
const int MAX=2e5+10;
const ll mod=1e9+7;
int bit1[5010],bit2[5010];
int main()
{
	int i,ans,a,b,len;
	char s[5010];
	while(~scanf("%s",s+1))
	{
		mem(bit1,0);
		mem(bit2,0);
		len=strlen(s+1);
		a=b=0;
		for(i=1;i<=len;i++)
		{
			if(s[i]=='a') bit1[i]++;
			bit1[i]+=bit1[i-1];
		}
		for(i=len;i>=1;i--)
		{
			if(s[i]=='a') bit2[i]++;
			bit2[i]+=bit2[i+1];
		}
		ans=0;
		for(i=1;i<=len;i++)
		{
			if(s[i]=='b') b++;
			else
			{
				ans=max(ans,bit1[i-1]+bit2[i]+b);
				b=0;
			}
		}
		ans=max(ans,bit1[len-1]+b);
		printf("%d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-3;
const int MAX=2e5+10;
const ll mod=1e9+7;
int main()
{
	int i,j,len,dp[5010],b;
	char a[5010];
	while(~scanf("%s",a))
	{
		len=strlen(a);
		mem(dp,0);
		b=0;
		for(i=0;i<len;i++)
		{
			for(j=0;j<i;j++)
			{
				if(a[i]=='a')
				{
					dp[i]=max(dp[i],dp[j]);
					b=0;
				}
				else if(a[i]=='b')
				{
					if(b&&a[j]=='b')
					{
						dp[i]=max(dp[i],dp[j]);
					}
					else if(!b) dp[i]=max(dp[i],dp[j]);
					b++;
				}
			}
			dp[i]++;
		}
		printf("%d\n",dp[len-1]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-3;
const int MAX=2e5+10;
const ll mod=1e9+7;
int main()
{
	int i,ans[3],a,b;
	char s[5010];
	while(~scanf("%s",s))
	{
		mem(ans,0);
		a=b=0;
		for(i=0;i<strlen(s);i++)
		{
			if(s[i]=='a')
			{
				ans[1]=max(ans[1],b);
				b=0;
				a++;
			}
			else
			{
				b++;
				if(ans[0]>ans[2]) swap(ans[0],ans[2]);
				ans[0]=max(ans[0],a);
				a=0;
			}
		}
		if(a)
		{
			if(ans[0]>ans[2]) swap(ans[0],ans[2]);
			ans[0]=max(ans[0],a);
		}
		if(b)
		{
			ans[1]=max(ans[1],b);
		}
		printf("%d\n",ans[0]+ans[1]+ans[2]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-3;
const int MAX=2e5+10;
const ll mod=1e9+7;
int bit1[5010],bit2[5010],bit3[5010];
int main()
{
	int i,j,ans,a,b,len;
	char s[5010];
	while(~scanf("%s",s+1))
	{
		mem(bit1,0);
		mem(bit2,0);
		mem(bit3,0);
		len=strlen(s+1);
		a=b=0;
		for(i=1;i<=len;i++)
		{
			if(s[i]=='a') bit1[i]++;
			else bit3[i]++;
			bit1[i]+=bit1[i-1];
			bit3[i]+=bit3[i-1];
		}
		for(i=len;i>=1;i--)
		{
			if(s[i]=='a') bit2[i]++;
			bit2[i]+=bit2[i+1];
		}
		ans=0;
		for(i=1;i<=len;i++)
		{
			for(j=i+1;j<=len;j++)
			{
				ans=max(ans,bit1[i]+bit2[j]+bit3[j]-bit3[i-1]);
			}
			ans=max(ans,bit1[i]+bit2[i+1]);
			ans=max(ans,bit3[i]);
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-3;
const int MAX=2e5+10;
const ll mod=1e9+7;
int bit1[5010],bit2[5010];
int main()
{
	int i,ans,a,b,len;
	char s[5010];
	while(~scanf("%s",s+1))
	{
		mem(bit1,0);
		mem(bit2,0);
		len=strlen(s+1);
		a=b=0;
		for(i=1;i<=len;i++)
		{
			if(s[i]=='a') bit1[i]++;
			bit1[i]+=bit1[i-1];
		}
		for(i=len;i>=1;i--)
		{
			if(s[i]=='a') bit2[i]++;
			bit2[i]+=bit2[i+1];
		}
		ans=0;
		for(i=1;i<=len;i++)
		{
			if(s[i]=='b') b++;
			else
			{
				ans=max(ans,bit1[i-1]+bit2[i]+b);
				b=0;
			}
		}
		ans=max(ans,bit1[i-1]+bit2[i]+b);
		printf("%d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-3;
const int MAX=2e5+10;
const ll mod=1e9+7;
int bit1[5010],bit2[5010],bit3[5010];
int main()
{
	int i,j,ans,a,b,len;
	char s[5010];
	while(~scanf("%s",s+1))
	{
		mem(bit1,0);
		mem(bit2,0);
		mem(bit3,0);
		len=strlen(s+1);
		a=b=0;
		for(i=1;i<=len;i++)
		{
			if(s[i]=='a') bit1[i]++;
			else bit3[i]++;
			bit1[i]+=bit1[i-1];
			bit3[i]+=bit3[i-1];
		}
		for(i=len;i>=1;i--)
		{
			if(s[i]=='a') bit2[i]++;
			bit2[i]+=bit2[i+1];
		}
		ans=0;
		for(i=1;i<=len;i++)
		{
			for(j=i+1;j<=len;j++)
			{
				ans=max(ans,bit1[i]+bit2[j]+bit3[j]-bit3[i-1]);
			}
			ans=max(ans,bit1[i]+bit2[i]);
			ans=max(ans,bit3[i]);
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-3;
const int MAX=2e5+10;
const ll mod=1e9+7;
int main()
{
	int i,j,len,dp[5010];
	char a[5010];
	while(~scanf("%s",a))
	{
		len=strlen(a);
		mem(dp,0);
		for(i=0;i<len;i++)
		{
			for(j=0;j<i;j++)
			{
				if(a[i]=='a')
				{
					dp[i]=max(dp[i],dp[j])+1;
				}
				else if(a[i]=='b')
				{
					if(a[j]=='b')
					{
						dp[i]=max(dp[i],dp[j])+1;
					}
				}
			}
		}
		printf("%d\n",dp[len-1]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-3;
const int MAX=2e5+10;
const ll mod=1e9+7;
int bit1[5010],bit2[5010],bit3[5010];
int main()
{
	int i,j,ans,a,b,len;
	char s[5010];
	while(~scanf("%s",s+1))
	{
		mem(bit1,0);
		mem(bit2,0);
		mem(bit3,0);
		len=strlen(s+1);
		a=b=0;
		for(i=1;i<=len;i++)
		{
			if(s[i]=='a') bit1[i]++;
			else bit3[i]++;
			bit1[i]+=bit1[i-1];
			bit3[i]+=bit3[i-1];
		}
		for(i=len;i>=1;i--)
		{
			if(s[i]=='a') bit2[i]++;
			bit2[i]+=bit2[i+1];
		}
		ans=0;
		for(i=1;i<=len;i++)
		{
			for(j=i+1;j<=len;j++)
			{
				ans=max(ans,bit1[i]+bit2[j]+bit3[j]-bit3[i-1]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 5123
#define INF 0x3F3F3F3F

vector <pair <int,char> > v;
int pd[maxn][3];

int f(int x,int cnt) {
	if(x == v.size()) return 0;
	if(cnt == 3) return 0;
	int &p = pd[x][cnt];

	if(p != -1) return p;

	int aux = 0;

	if(v[x].second == 'a' && (cnt == 0 || cnt == 2) ) {
		aux = max(f(x+1,cnt+1) + v[x].first,aux);
	}
	if(v[x].second == 'b' && cnt == 1) {
		aux = max(f(x+1,cnt+1) + v[x].first,aux);
	}
	aux = max(aux,f(x+1,cnt));
	return p = aux;
}

int main() {
	string s;
	cin >> s;
	s += '#';
	memset(pd,-1,sizeof pd);
	int cnt = 0;
	char ant = s[0];
	for(int i = 0;i < s.size();i++) {
		if(ant == s[i]) {
			cnt++;
		}
		else {
			v.push_back(make_pair(cnt,ant));
			cnt = 1;
			ant = s[i];
		}
	}
	int res = f(0,0);
	if(s[0] == 'b')
		res = max(res,f(0,1));
	printf("%d\n",res);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 5123
#define INF 0x3F3F3F3F

vector <pair <int,char> > v;
int pd[maxn][3];

int f(int x,int cnt) {
	if(x == v.size()) return 0;
	if(cnt == 3) return 0;
	int &p = pd[x][cnt];

	if(p != -1) return p;

	int aux = 0;

	if(v[x].second == 'a' && (cnt == 0 || cnt == 2) ) {
		aux = max(f(x+1,cnt+1) + v[x].first,aux);
	}
	if(v[x].second == 'b' && cnt == 1) {
		aux = max(f(x+1,cnt+1) + v[x].first,aux);
	}
	aux = max(aux,f(x+1,cnt));
	return p = aux;
}

int main() {
	string s;
	cin >> s;
	s += '#';
	memset(pd,-1,sizeof pd);
	int cnt = 0;
	char ant = s[0];
	for(int i = 0;i < s.size();i++) {
		if(ant == s[i]) {
			cnt++;
		}
		else {
			v.push_back(make_pair(cnt,ant));
			cnt = 1;
			ant = s[i];
		}
	}
	printf("%d\n",f(0,0));
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define maxn 5123
#define INF 0x3F3F3F3F

vector <pair <int,char> > v;
int pd[maxn][3];

int f(int x,int cnt) {
	if(x == v.size()) return 0;
	if(cnt == 3) return 0;
	int &p = pd[x][cnt];

	if(p != -1) return p;

	int aux = 0;

	if(v[x].second == 'a' && (cnt == 0 || cnt == 2) ) {
		aux = max(f(x+1,cnt+1) + v[x].first,f(x+1,cnt) + v[x].first);
	}
	if(v[x].second == 'b' && cnt == 1) {
		aux = max(f(x+1,cnt+1) + v[x].first,f(x+1,cnt) + v[x].first);
	}
	aux = max(aux,f(x+1,cnt));
	return p = aux;
}

int main() {
	string s;
	cin >> s;
	s += '#';
	memset(pd,-1,sizeof pd);
	int cnt = 0;
	char ant = s[0];
	for(int i = 0;i < s.size();i++) {
		if(ant == s[i]) {
			cnt++;
		}
		else {
			v.push_back(make_pair(cnt,ant));
			cnt = 1;
			ant = s[i];
		}
	}
	int res = f(0,0);
	if(s[0] == 'b')
		res = max(res,f(0,1));
	printf("%d\n",res);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	string s;
	cin >> s;
	s += '#';
	vector <int> v;
	int cnt = 0;
	char ant = s[0];
	for(int i = 0;i < s.size();i++) {
		if(ant == s[i]) {
			cnt++;
		}
		else {
			v.push_back(cnt);
			cnt = 1;
			ant = s[i];
		}
	}
	bool flag;
	int sz = v.size();
	v.push_back(0);
	v.push_back(0);
	if(s[0] == 'b')
		flag = true;
	else
		flag = false;
	int res = 0;
	int pos = 0;
	for(int i = flag;i < sz;i++) {
		if(pos&1) {
			res = max(res,v[i-1] + v[i] + v[i+1]);
		}
		else
			res = max(res,v[i] + v[i+1] + v[i+2]);
	}
	printf("%d\n",res);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	string s;
	cin >> s;
	s += '#';
	vector <pair <int,char> > v;
	v.push_back(make_pair(0,'#'));
	int cnt = 0;
	char ant = s[0];
	for(int i = 0;i < s.size();i++) {
		if(ant == s[i]) {
			cnt++;
		}
		else {
			v.push_back(make_pair(cnt,ant));
			cnt = 1;
			ant = s[i];
		}
	}
	int res = 0;
	int sz = v.size();
	v.push_back(make_pair(0,'#'));
	v.push_back(make_pair(0,'#'));
	v.push_back(make_pair(0,'#'));
	for(int i = 1;i < sz;i++) {
		if(v[i].second == 'a')
			res = max(res,v[i].first + v[i+1].first + v[i+2].first);
		else
			res = max(res,v[i].first + v[i-1].first + v[i+1].first);
	}
	printf("%d\n",res);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    char ma[123123];
    scanf("%s", ma);
    int len = strlen(ma);
    int top = -1;
    int a[123123];
    int flag[123123];
    for(int i=0; i<len;)
    {
        if(ma[i]=='a')
        {
            int ka = 0;
            while(i<len&&ma[i]=='a')
            {
                ka++;
                i++;
            }
            a[++top] = ka;
            flag[top] = 1;
            if(i>=len)
            break;
        }
        if(ma[i]=='b')
        {
            int ka = 0;
            while(i<len&&ma[i]=='b')
            {
                ka++;
                i++;
            }
            a[++top] = ka;
            flag[top] = 0;
            if(i>=len)
            break;
        }
    }
    int maxn = 0;
    int k = 0;
    for(int i=0; i<=top;i++)
    {
        if(flag[i]==0)
        k += a[i];
        if(flag[i]==1)
        {
            int ka;
            if(i+2<=top)
            ka = a[i] + a[i+1] + a[i+2];
            else if(i+1<=top)
            {
              ka = a[i] + a[i+1];
            }
            else
            ka = a[i];
            if(ka>maxn)
                maxn = ka;
        }
        else
        {
          int ka;
          if(i+1<=top)
          {
            ka = a[i] + a[i+1];
          }
          else
          {
            ka = a[i];
          }
          if(ka>maxn)
          maxn = ka;
        }
        if(k>maxn)
        maxn = k;
    }
    printf("%d\n", maxn);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
char ma[6312];
int main()
{
  scanf("%s", ma);
  int len = strlen(ma);
  int ka[65432];
  int kb[123123];
  ka[0] = 0;
  kb[0] = 0;
  for(int i=0;i<len;i++)
  {
    ka[i+1] = ka[i];
    kb[i+1] = kb[i];
    if(ma[i]=='a')
    ka[i+1]++;
    else
    kb[i+1]++;
  }
  int maxn = 0;
  for(int i=0;i<=len;i++)
  {
    for(int j=i;j<=len;j++)
    {
      int num = ka[i] +(kb[j] - kb[i]) + (ka[len] - ka[j]);
      if(num>maxn)
      maxn = num;
    }
  }
  printf("%d\n", maxn);
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    char ma[123123];
    scanf("%s", ma);
    int len = strlen(ma);
    int top = -1;
    int a[123123];
    int flag[123123];
    for(int i=0; i<len;)
    {
        if(ma[i]=='a')
        {
            int ka = 0;
            while(i<len&&ma[i]=='a')
            {
                ka++;
                i++;
            }
            a[++top] = ka;
            flag[top] = 1;
            if(i>=len)
            break;
        }
        if(ma[i]=='b')
        {
            int ka = 0;
            while(i<len&&ma[i]=='b')
            {
                ka++;
                i++;
            }
            a[++top] = ka;
            flag[top] = 0;
            if(i>=len)
            break;
        }
    }
    int maxn = 0;
    for(int i=0; i<=top;i++)
    {
        if(flag[i]==1)
        {
            int ka;
            if(i+2<=top)
            ka = a[i] + a[i+1] + a[i+2];
            else if(i+1<=top)
            {
              ka = a[i] + a[i+1];
            }
            else
            ka = a[i];
            if(ka>maxn)
                maxn = ka;
        }
        else
        {
          int ka;
          if(i+1<=top)
          {
            ka = a[i] + a[i+1];
          }
          else
          {
            ka = a[i];
          }
          if(ka>maxn)
          maxn = ka;
        }
    }
    printf("%d\n", maxn);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

vector<int> A, B;
string s;
int cnt;
bool b;

int main() {
	cin >> s;
	A.push_back(0);
	B.push_back(0);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != 97 + b) {
			(b ? B : A).push_back(cnt);
			cnt = 0;
			b ^= 1;
		}
		cnt++;
	}
	(b ? B : A).push_back(cnt);
	sort(A.begin(), A.end(), greater<int>());
	sort(B.begin(), B.end(), greater<int>());
	printf("%d", A[0] + A[1] + B[0]);
}


#include <bits/stdc++.h>
#include <windows.h>
using namespace std;

typedef pair<int, char> pic;

int b[5005];
int a[5005];
string s;
int ans;
int n;

void hack() {
	SYSTEM_INFO info;
	GetSystemInfo(&info);
	OSVERSIONINFOEX os;
	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

	if (GetVersionEx((OSVERSIONINFO *)&os)) {
		printf("Windows NT %ld.%ld\n", os.dwMajorVersion, os.dwMinorVersion);
		exit(0);
	}
}

int main() {
	hack();
//	freopen("b.txt", "r", stdin);
	cin >> s; n = s.size();
	for (int i = 0; i < n; i++) {
		a[i] = a[i-1] + (s[i] == 97);
		b[i] = b[i-1] + (s[i] == 98);
//		printf("(%d, %d) ", a[i], b[i]);
	}
//	puts("");
	if (s[0] == s[1] && s[1] == s[2]) {
		printf("%d", n);
		return 0;
	}
	for (int i = 0; i <= n; i++) {
		for (int j = i; j <= n; j++) {
			// [0, i) [i, j) [j, n)
//			printf("(%d, %d): %d, %d, %d\n", i, j, a[i-1], (b[j-1]-b[i-1]), (a[n-1]-a[j-1]));
			ans = max(ans, a[i-1] + (b[j-1]-b[i-1]) + (a[n-1]-a[j-1]));
		}
	}
	printf("%d", ans);
}


#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int INF = 0x3f3f3f3f;

int dp[5000][5000][5];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int length = static_cast<int>(s.size());
    memset(dp,INF,sizeof(dp));
    for(int i = 0;i < length;i++) {
        if(s[i] == 'a') {
            dp[i][i][0] = 0;
        }else {
            dp[i][i][1] = 0;
        }
    }
    int result = 1;
    for(int len = 2;len <= length;len++) {
        for(int left = 0;left <= length - len;left++) {
            int right = left + len - 1;
            char leftChar = s[left],rightChar = s[right];
            dp[left][right][0] = min(dp[left][right][0],dp[left + 1][right][0] + (leftChar == 'a' ? 0 : 1));
            dp[left][right][0] = min(dp[left][right][0],dp[left][right - 1][0] + (rightChar == 'a' ? 0 : 1));
            dp[left][right][1] = min(dp[left][right][1],dp[left + 1][right][1] + (leftChar == 'b' ? 0 : 1));
            dp[left][right][1] = min(dp[left][right][1],dp[left][right - 1][1] + (rightChar == 'b' ? 0 : 1));
            dp[left][right][2] = min(dp[left][right][2],dp[left + 1][right][2] + (leftChar == 'a' ? 0 : 1));
            dp[left][right][2] = min(dp[left][right][2],dp[left][right - 1][2] + (rightChar == 'b' ? 0 : 1));
            dp[left][right][3] = min(dp[left][right][3],dp[left + 1][right][3] + (leftChar == 'b' ? 0 : 1));
            dp[left][right][3] = min(dp[left][right][3],dp[left][right - 1][3] + (rightChar == 'a' ? 0 : 1));
            dp[left][right][4] = min(dp[left][right][4],dp[left + 1][right][4] + (leftChar == 'a' ? 0 : 1));
            dp[left][right][4] = min(dp[left][right][4],dp[left][right - 1][4] + (rightChar == 'a' ? 0 : 1));
            if(leftChar == 'a') {
                dp[left][right][2] = min(dp[left][right][2],dp[left + 1][right][1]);
                dp[left][right][4] = min(dp[left][right][4],dp[left + 1][right][3]);
            }
            if(rightChar == 'a') {
                dp[left][right][3] = min(dp[left][right][3],dp[left][right - 1][1]);
                dp[left][right][4] = min(dp[left][right][4],dp[left][right - 1][2]);
            }
            if(leftChar == 'b') {
                dp[left][right][3] = min(dp[left][right][3],dp[left + 1][right][0]);
            }
            if(rightChar == 'b') {
                dp[left][right][2] = min(dp[left][right][2],dp[left][right - 1][0]);
            }
            for(int i = 0;i < 5;i++) {
                if(dp[left][right][i] != INF) {
                    result = max(result,right - left + 1 - dp[left][right][i]);
                }
            }
        }
    }
    cout << result << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int INF = 0x3f3f3f3f;

int dp[5000][5];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int length = static_cast<int>(s.size());
    memset(dp,INF,sizeof(dp));
    int result = 1;
    if(s[0] == 'a') {
        dp[0][0] = 0;
        dp[0][1] = 1;
    }else {
        dp[0][0] = 1;
        dp[0][1] = 0;
    }
    for(int i = 1;i < length;i++) {
        char tmpChar = s[i];
        dp[i][0] = min(dp[i][0],dp[i - 1][0] + (tmpChar == 'a' ? 0 : 1));
        dp[i][1] = min(dp[i][1],dp[i - 1][1] + (tmpChar == 'b' ? 0 : 1));
        dp[i][2] = min(dp[i][2],dp[i - 1][2] + (tmpChar == 'b' ? 0 : 1));
        dp[i][3] = min(dp[i][3],dp[i - 1][3] + (tmpChar == 'a' ? 0 : 1));
        dp[i][4] = min(dp[i][4],dp[i - 1][4] + (tmpChar == 'a' ? 0 : 1));
        if(tmpChar == 'b') {
            dp[i][2] = min(dp[i][2],dp[i - 1][0]);
        }
        if(tmpChar == 'a') {
            dp[i][3] = min(dp[i][3],dp[i - 1][1]);
            dp[i][4] = min(dp[i][4],dp[i - 1][2]);
        }
        for(int j = 0;j < 5;j++) {
            if(dp[i][j] != INF) {
                result = max(result,i + 1 - dp[i][j]);
            }
        }
    }
    cout << result << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int INF = 0x3f3f3f3f;

int judgeAppendValue(bool isLeft,char value,int status) {
    if(isLeft) {
        switch(status) {
            case 0: {
                return (value == 'a') ? 0 : 1;
            }
            case 1: {
                return (value == 'b') ? 0 : 1;
            }
            case 2: {
                return (value == 'a') ? 0 : 1;
            }
            case 3: {
                return (value == 'a') ? 0 : 1;
            }
            case 4: {
                return (value == 'a') ? 0 : 1;
            }
            case 5: {
                return (value == 'b') ? 0 : 1;
            }
            case 6: {
                return (value == 'a') ? 0 : 1;
            }
            default: {
                return 0;
            }
        }
    }else {
        switch(status) {
            case 0: {
                return (value == 'a') ? 0 : 1;
            }
            case 1: {
                return (value == 'b') ? 0 : 1;
            }
            case 2: {
                return (value == 'a') ? 0 : 1;
            }
            case 3: {
                return (value == 'b') ? 0 : 1;
            }
            case 4: {
                return (value == 'a') ? 0 : 1;
            }
            case 5: {
                return (value == 'a') ? 0 : 1;
            }
            case 6: {
                return (value == 'a') ? 0 : 1;
            }
            default: {
                return 0;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int length = static_cast<int>(s.size());
    int ***dp = new int**[length];
    for(int i = 0;i < length;i++) {
        dp[i] = new int*[length];
        for(int j = 0;j < length;j++) {
            dp[i][j] = new int[7];
            memset(dp[i][j],INF,sizeof(int) * 7);
        }
    }
    for(int i = 0;i < length;i++) {
        if(s[i] == 'a') {
            dp[i][i][0] = 0;
            dp[i][i][2] = 0;
        }else {
            dp[i][i][1] = 0;
        }
    }
    int result = 1;
    for(int len = 2;len <= length;len++) {
        for(int left = 0;left <= length - len;left++) {
            int right = left + len - 1;
            for(int i = 0;i < 7;i++) {
                dp[left][right][i] = min(dp[left][right][i],dp[left + 1][right][i] + judgeAppendValue(true,s[left],i));
                dp[left][right][i] = min(dp[left][right][i],dp[left][right - 1][i] + judgeAppendValue(false,s[right],i));
            }
            if(s[left] == 'a') {
                dp[left][right][3] = min(dp[left][right][3],dp[left + 1][right][1]);
                dp[left][right][4] = min(dp[left][right][4],dp[left + 1][right][2]);
                dp[left][right][6] = min(dp[left][right][6],dp[left + 1][right][5]);
            }
            if(s[right] == 'a') {
                dp[left][right][4] = min(dp[left][right][4],dp[left][right - 1][0]);
                dp[left][right][5] = min(dp[left][right][5],dp[left][right - 1][1]);
                dp[left][right][6] = min(dp[left][right][6],dp[left][right - 1][3]);
            }
            if(s[left] == 'b') {
                dp[left][right][5] = min(dp[left][right][5],dp[left + 1][right][2]);
            }
            if(s[right] == 'b') {
                dp[left][right][3] = min(dp[left][right][3],dp[left][right - 1][0]);
            }
            for(int i = 0;i < 7;i++) {
                if(dp[left][right][i] != INF) {
                    result = max(result,right - left + 1 - dp[left][right][i]);
                }
            }
        }
    }
    cout << result << endl;
    return 0;
}