#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define maxn 100005
char str[maxn];
int sum[maxn];
int base[maxn];
void mul()
{
    for(int i = 1;  i <= base[0] ; i ++ )
    {
        base[i] = base[i] * 2;
    }
    for(int i = 1; i <=base[0]; i ++ )
    {
        base[i+1] = base[i+1] + base[i] /10;
        base[i] = base[i]  %10 ;
    }
    while(base[base[0] +1 ] >0 )
    {
        base[0] ++ ;
        base[base[0]+ 1] =base[base[0]] / 10;
        base[base[0]] %= 10;
    }
}
void add()
{
    sum[0] = max(sum[0] ,base[0]);
    for(int i = 1; i <= sum[0] ; i++ )
    {
        sum[i] = sum[i] + base[i];
        sum[i+1] = sum[i+1] + sum[i] / 10;
        sum[i] %= 10;
    }
    while(sum[sum[0] + 1] > 0 )
    {
        sum[0] ++ ;
        sum[sum[0] + 1] = sum[sum[0]] / 10;
        sum[sum[0]] %= 10;
    }
}
void print()
{
    for(int i = sum[0] ; i >= 1 ; i-- )
        printf("%d",sum[i]);
    printf("\n");
}
int main()
{
    int fl;
    while(scanf("%s",str)!=EOF)
    {
        memset(sum,0,sizeof(sum));
        memset(base,0,sizeof(base));
        fl = strlen(str) - 1;
        int st;
        st = 0;
        while(str[st] == '0' && st < strlen(str)) st++;
        for(int i = st ;i < strlen(str);i ++)
        if(str[i] == '0')
        {
            fl = i;
            break;
        }
        //printf("fl = %d\n",fl);
       /* sum[0] = 1;
        sum[1] = 0 ;
        base[0] = 1;
        base[1] = 1;
        */
        for(int i = st ; i < strlen(str) ;i++ )
            if(i != fl)
            printf("%c",str[i]);
        printf("\n");

        //print();
    }
    return 0 ;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define maxn 200005
using namespace std;
int main()
{
	int num, i;
	char arr[maxn];
	while ( gets(arr) )
	{
		int flag = 1, ans = 1;
		num = strlen( arr );
		for ( i = 0; i < num; i ++ )
		{
			if ( arr[i] == '0' && flag )
			{
				arr[i] = '*';
				flag = 0;
			}
			if ( i == num -1 && flag )
			{
				arr[i] = '*';
			}
		}
		flag = 1;
		for ( i = 0; i < num; i ++ )
		{
			if ( flag )
			{
				if ( arr[i] =='0' || arr[i] == '*' )
					continue;
				else flag = 0;
			}
			if ( arr[i] != '*')
			cout << arr[i] ;
		}
		cout << endl;
	}
	return 0;
}


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

char num[1000000];
int main()
{
	int a;
	int i,n,flag;
	while (cin >> num)
	{
		flag=-1;
		n=strlen(num);
		for(i=0; i<n; i++)
		{
			if(num[i] == '0')
			{
				flag=i;
				break;
			}
		}
		if(flag == -1)
		{
			for(i=0;i<n-1; i++)
			{
				printf("%c",num[i]);
			}
		}
		else
		{
			for(i=0;i<n; i++)
			{
				if (i == flag) continue;
				else printf("%c",num[i]);
			}
		}
		printf("\n");
	}
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
  char s[100005];
  int i;
  while(cin>>s)
  {
  	int g=-1;
  	for(i=0;s[i]!='\0';i++)
  	 if(s[i]=='0')
	   {
	   g=i;
	   break;
	   }
	   if(g==-1)
	   {
   		for(i=1;s[i]!='\0';i++)
   		 cout<<s[i];
   		 cout<<endl;
   	   }
   	   else
   	   {
   	   	for(i=0;s[i]!='\0';i++)
   	   	 if(i==g) continue;
   	   	 else cout<<s[i];
   	   	 cout<<endl;
   	   }
  }
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define maxn 500005
char str[maxn];
int sum[maxn];
int base[maxn];
/*
void mul()
{
    for(int i = 1;  i <= base[0] ; i ++ )
    {
        base[i] = base[i] * 2;
    }
    for(int i = 1; i <=base[0]; i ++ )
    {
        base[i+1] = base[i+1] + base[i] /10;
        base[i] = base[i]  %10 ;
    }
    while(base[base[0] +1 ] >0 )
    {
        base[0] ++ ;
        base[base[0]+ 1] =base[base[0]] / 10;
        base[base[0]] %= 10;
    }
}
void add()
{
    sum[0] = max(sum[0] ,base[0]);
    for(int i = 1; i <= sum[0] ; i++ )
    {
        sum[i] = sum[i] + base[i];
        sum[i+1] = sum[i+1] + sum[i] / 10;
        sum[i] %= 10;
    }
    while(sum[sum[0] + 1] > 0 )
    {
        sum[0] ++ ;
        sum[sum[0] + 1] = sum[sum[0]] / 10;
        sum[sum[0]] %= 10;
    }
}
void print()
{
    for(int i = sum[0] ; i >= 1 ; i-- )
        printf("%d",sum[i]);
    printf("\n");
}
*/
int main()
{
    int fl;
    scanf("%s",str);

    fl = strlen(str) - 1;
    int st;
    st = 0;
    //while(str[st] == '0' && st < strlen(str)) st++;
    for(int i = st ; i < strlen(str); i ++)
        if(str[i] == '0')
        {
            fl = i;
            break;
        }
    for(int i = st ; i < strlen(str) ; i++ )
        if(i != fl)
            printf("%c",str[i]);
    printf("\n");

    return 0 ;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
char s[100100];

int main()
{
    scanf("%s",s);
    int len = strlen(s);
    int i = 0;
    while (i<len && s[i]=='1')
        i++;
    if (i == len)
        i = len-1;
    for (int j=0;j<len;j++)
        if (i!=j)
            printf("%c",s[j]);
    printf("\n");
    return 0;
}


#include <cstdio>
#include <cstring>

const int MAXN = 100000 +10;
char numStr[MAXN];

int main()
{
    int len;
    int i,lefti = 0;
    scanf("%s",numStr);
    len = strlen(numStr);

    for(i = 0; i < len; i ++)
    {
        if(numStr[i] == '0')
        {
            lefti = i;
            break;
        }
    }

    for(i = 0; i < len; i ++)
        if(i != lefti)
            putchar(numStr[i]);
    putchar('\n');

    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define maxn 100005
char str[maxn];
int sum[maxn];
int base[maxn];
void mul()
{
    for(int i = 1;  i <= base[0] ; i ++ )
    {
        base[i] = base[i] * 2;
    }
    for(int i = 1; i <=base[0]; i ++ )
    {
        base[i+1] = base[i+1] + base[i] /10;
        base[i] = base[i]  %10 ;
    }
    while(base[base[0] +1 ] >0 )
    {
        base[0] ++ ;
        base[base[0]+ 1] =base[base[0]] / 10;
        base[base[0]] %= 10;
    }
}
void add()
{
    sum[0] = max(sum[0] ,base[0]);
    for(int i = 1; i <= sum[0] ; i++ )
    {
        sum[i] = sum[i] + base[i];
        sum[i+1] = sum[i+1] + sum[i] / 10;
        sum[i] %= 10;
    }
    while(sum[sum[0] + 1] > 0 )
    {
        sum[0] ++ ;
        sum[sum[0] + 1] = sum[sum[0]] / 10;
        sum[sum[0]] %= 10;
    }
}
void print()
{
    for(int i = sum[0] ; i >= 1 ; i-- )
        printf("%d",sum[i]);
    printf("\n");
}
int main()
{
    int fl;
    while(scanf("%s",str)!=EOF)
    {
        memset(sum,0,sizeof(sum));
        memset(base,0,sizeof(base));
        fl = strlen(str) - 1;
        int st;
        st = 0;
        while(str[st] == '0') st++;
        for(int i = st ;i < strlen(str);i ++)
        if(str[i] == '0')
        {
            fl = i;
            break;
        }
        //printf("fl = %d\n",fl);
       /* sum[0] = 1;
        sum[1] = 0 ;
        base[0] = 1;
        base[1] = 1;
        */
        for(int i = st ; i < strlen(str) ;i++ )
            if(i != fl)
            printf("%c",str[i]);
        printf("\n");

        //print();
    }
    return 0 ;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define maxn 200005
using namespace std;
int main()
{
	int num, i;
	char arr[maxn];
	while ( gets(arr) )
	{
		int flag = 1;
		num = strlen( arr );
		for ( i = 0; i < num; i ++ )
		{
			if ( arr[i] == '0' && flag )
			{
				i ++;
				flag = 0;
			}
			cout << arr[i];
		}
		cout << endl;
	}
	return 0;
}


#include<stdio.h>
#include<string.h>

char str[1000];

int main()
{
    while(scanf("%s",str)!=EOF)
    {
        int len=strlen(str);
        int k=0;
        bool flag=0;
        for(int i=0;i<len;i++)
        {
            if(str[i]=='0') flag=1;
        }

        if(flag){
            for(int i=0;i<len;i++)
            {
                if(k==0&&str[i]=='0')
                {
                    k++;
                    continue;
                }
                printf("%c",str[i]);
            }
        }else{
            for(int i=1;i<len;i++)
            {
                printf("1");
            }
        }

        printf("\n");

    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define maxn 200005
using namespace std;
int main()
{
	int num, i;
	char arr[maxn];
	while ( gets(arr) )
	{
		int flag = 1;
		num = strlen( arr );
		for ( i = 0; i < num; i ++ )
		{
			if ( arr[i] == '0' && flag )
			{
				i ++;
				flag = 0;
			}
			cout << arr[i];
		}
		cout << endl;
	}
}


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

char num[1000000];
int main()
{
	int a;
	int i,n,flag;
	while (cin >> num)
	{
		n=strlen(num);
		for(i=0; i<n; i++)
		{
			if(num[i] == '0')
			{
				flag=i;
				break;
			}
		}
		for(i=0;i<n; i++)
		{
			if (i == flag) continue;
			else printf("%c",num[i]);
		}
		printf("\n");
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int main()
{
	char a[100000];
	memset(a,0,sizeof(a));
	while(cin >> a)
	{
		int n;
		bool flag=true;
		for(n=0;n<100000;n++)
			if(a[n]==0&&a[n]!='0')break;
		for(int i=0;i<n-1;i++)
		{
			if(a[i]=='1')cout << a[i];
			else if(flag)flag=false;
			else cout << a[i];
		}
		if(flag==false)cout << a[n-1]<<endl;
		else cout << endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define maxn 500005
char str[maxn];
int main()
{
    int fl;
    scanf("%s",str);

    fl = strlen(str) - 1;
    int st;
    st = 0;
    while(str[st] == '0' && st < strlen(str)) st++;
    for(int i = st ; i < strlen(str); i ++)
        if(str[i] == '0')
        {
            fl = i;
            break;
        }
    for(int i = st ; i < strlen(str) ; i++ )
        if(i != fl)
            putchar(str[i]);
    puts("");

    return 0 ;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define maxn 200005
using namespace std;
int main()
{
	int num, i;
	char arr[maxn];
	while ( gets(arr) )
	{
		int flag = 1;
		num = strlen( arr );
		for ( i = 0; i < num; i ++ )
		{
			if ( arr[i] == '0' && flag )
			{
				i ++;
				flag = 0;
			}
			if ( i == num -1 && flag )
				i ++;
			cout << arr[i];
		}

		cout << endl;
	}
	return 0;
}


#include<stdio.h>
#include<string.h>

char str[100000];

int main()
{
    while(scanf("%s",str)!=EOF)
    {
        int len=strlen(str);
        int k=0;
        bool flag=0;
        for(int i=0;i<len;i++)
        {
            if(str[i]=='0') flag=1;
        }

        if(flag){
            for(int i=0;i<len;i++)
            {
                if(k==0&&str[i]=='0')
                {
                    k++;
                    continue;
                }
                printf("%c",str[i]);
            }
        }else{
            for(int i=1;i<len;i++)
            {
                printf("1");
            }
        }

        printf("\n");

    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

char s[100005];

int main()
{

	//freopen("c.inp", "r", stdin);
	//freopen("c.out", "w", stdout);
	int i, ln;

	while(gets(s)>0)
	{
		bool first = false;

		ln=strlen(s);
		for(i=0;i<ln;i++)
		{
			if((s[i] == '0'&& first == true) || s[i] == '1') printf("%c", s[i]);

			if(s[i]=='0' && first==false) first = true;

		}
		printf("\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
map<char, int> m;
char s[50000500];
char ch[50000500];

void solve()
{
		int i, ln, pt, vt;
		bool first = false;
		m.clear();

		pt = 0;
		ln=strlen(s);

		for(i=0;i<ln;i++) m[s[i]]++;

		if(m['0'] == 0)
		{
			s[ln-1]=0;
			printf("%s\n", s);
			return;
		}

		for(i=0;i<ln;i++)
		{
			if((s[i] == '0'&& first == true) || s[i] == '1') ch[pt++]=s[i];

			if(s[i]=='0' && first==false) first = true;

		}

		vt=0;
		ch[pt]=0;
		ln=strlen(ch);
		for(i=0;i<ln;i++)
			if(ch[i]!='0')
			{
				vt=i;
				break;
			}
		for(i=vt;i<ln;i++)printf("%c",ch[i]);
		printf("\n");
}

int main()
{

	//freopen("c.inp", "r", stdin);
	//freopen("c.out", "w", stdout);

	while(gets(s)>0)
	{
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

char s[50000500];

int main()
{

	//freopen("c.inp", "r", stdin);
	//freopen("c.out", "w", stdout);
	int i, ln;

	while(gets(s)>0)
	{
		bool first = false;

		ln=strlen(s);
		for(i=0;i<ln;i++)
		{
			if((s[i] == '0'&& first == true) || s[i] == '1') printf("%c", s[i]);

			if(s[i]=='0' && first==false) first = true;

		}
		printf("\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

char s[50000500];
char ch[50000500];

int main()
{

	//freopen("c.inp", "r", stdin);
	//freopen("c.out", "w", stdout);
	int i, ln, pt, vt;

	while(gets(s)>0)
	{
		bool first = false;

		pt = 0;
		ln=strlen(s);
		for(i=0;i<ln;i++)
		{
			if((s[i] == '0'&& first == true) || s[i] == '1') ch[pt++]=s[i];

			if(s[i]=='0' && first==false) first = true;

		}

		vt=0;
		ch[pt]=0;
		ln=strlen(ch);
		for(i=0;i<ln;i++)
			if(ch[i]!='0')
			{
				vt=i;
				break;
			}
		for(i=vt;i<ln;i++)printf("%c",ch[i]);
		printf("\n");
	}
	return 0;
}


import java.util.*;
import java.util.regex.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import static java.util.Collections.*;
import java.io.*;

public class C {

    public void solve() {
        String line = in.nextLine();
//      char[]xx=new char[10];
//      fill(xx,'1');
//      String line = new String(xx);
        String res = "";
        boolean found=false;
        for (int i = 0; i < line.length(); i++) {
            char c =line.charAt(i);
            if(c=='0' && !found){
                found=true;
            }else{
                if(i==line.length()-1&&!found){

                }else{
                    res+=line.charAt(i);
                }
            }

        }
        System.out.println(res);
    }
    C(){
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);
    }
    public static void close(){
        in.close();
        out.close();
    }
    public static void main(String[] args) throws Exception {
        new C().solve();
        close();
    }

    static Scanner in;
    static PrintWriter out;

    static int readInt(){
        return parseInt(in.nextLine());
    }
    static int[] readIntArray(){
        String l[] = in.nextLine().split(" ");
        int[] r=new int[l.length];
        for (int i = 0; i < l.length; i++) {
            r[i]=parseInt(l[i]);
        }
        return r;
    }
    static void print(Object... ob) {
        System.out.println(Arrays.deepToString(ob).replace("],", "],\n"));
    }
}


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

char A[100010];
int main()
{
    scanf("%s",A);bool flag=1;
    for(int i=0;i<strlen(A);i++)
    {
        if(i==(strlen(A)-1)&&flag)continue;
        if(flag&&A[i]=='0') flag=0;
        else printf("%c",A[i]);

    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SZ(v) ((int)(v).size())
#define FOR(i, a, b) for (typeof(a) i = (a); i < (b); ++i)
#define FORD(i, a, b) for(typeof(a) i = (a);i >= (b); --i)
#define FOREACH(iter, v) for (typeof((v).begin()) iter = (v).begin(); iter != (v).end(); ++iter)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;

using namespace std;

int main()
{
    string num;
    cin >> num;
    int n = SZ(num), zero = -1;
    REP(i,n) {
        if (num[i] == '0') {
            zero = i;
            break;
        }
    }
    if (zero != -1) {
        REP(i,n) if (i != zero) putchar(num[i]);
    } else {
        REP(i,n-1) putchar('1');
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
using namespace std;

char A[100010];
int main()
{
    scanf("%s",A);bool flag=1;
    for(int i=0;i<strlen(A);i++)
    {
        if(i==(strlen(A)-1)&&flag)continue;
        if(flag&&A[i]=='0') flag=0;
        else printf("%c",A[i]);

    }
    printf("\n");
    return 0;
}


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

char A[100010];
int main()
{
    scanf("%s",A);bool flag=1;
    for(int i=0;i<strlen(A);i++)
    {
        if(i==(strlen(A)-1)&&flag)continue;
        if(flag&&A[i]=='0'){flag=0;continue;}
        else printf("%c",A[i]);
    }
    printf("\n");
    return 0;
}


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

char A[100010];
int main()
{
    scanf("%s",A);bool flag=1;
    int n = strlen(A);
    for(int i=0;i<n;i++)
    {
        if(i==(n-1)&&flag)continue;
        if(flag&&A[i]=='0'){flag=0;continue;}
        else printf("%c",A[i]);
    }
    printf("\n");
    return 0;
}


#include<iostream>
#include<string>
//#include<conio.h>

using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
        if(s[i]=='0')
        {
            s.erase(i,i);
            break;
        }
        cout<<s;
}


#include<iostream>
#include<string>
//#include<conio.h>

using namespace std;
int main()
{
    string s;
    cin>>s;
    bool c=true;
    for(int i=0;i<s.length();i++)
        if(s[i]=='0')
        {
            s.erase(i,i);
            c=false;
            break;
        }
        if(c)
            s.erase(s.length()-1,s.length()-1);
        cout<<s;
}


#include<iostream>
#include<string>
//#include<conio.h>

using namespace std;
int main()
{
    string s;
    cin>>s;
    bool c=true;
    for(int i=0;i<s.length();i++)
        if(s[i]=='0')
        {
            s[i]='-';
            //while(s[i]=='0')
            //  s.erase(i,i);
            c=false;
            break;
        }
        if(c)
        {
            s.erase(s.length()-1,s.length()-1);
            cout<<s;
        }
        else
            for(int i=0;i<s.length();i++)
                if(s[i]!='-')
                    cout<<s[i];

}


#include<iostream>
#include<string>
//#include<conio.h>

using namespace std;
int main()
{
    string s;
    cin>>s;
    bool c=true;
    for(int i=0;i<s.length();i++)
        if(s[i]=='0')
        {
            s.erase(i,i-1);
            //while(s[i]=='0')
            //  s.erase(i,i);
            c=false;
            break;
        }
        if(c)
            s.erase(s.length()-1,s.length()-1);
        cout<<s;
}


#include<iostream>
#include<string>
//#include<conio.h>

using namespace std;
int main()
{
    string s;
    cin>>s;
    bool c=true;
    for(int i=0;i<s.length();i++)
        if(s[i]=='0')
        {
            s.erase(i,i);
            while(s[i]=='0')
                s.erase(i,i);
            c=false;
            break;
        }
        if(c)
            s.erase(s.length()-1,s.length()-1);
        cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,n) for(int i=0,_n=n;i<_n;i++)
#define fer(i,x,n) for(int i=(int)(x),_n=n;i<_n;i++)
#define rof(i,x,n) for(int i=(int)(n),_x=(int)x;i-- >_x)
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bi back_inserter
#define X first
#define Y second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
template<class T> inline void smin(T &aa,T bb){if(bb<aa)aa=bb;}
template<class T> inline void smax(T &aa,T bb){if(bb>aa)aa=bb;}
long long res;

int main()
{
char c[1000005];
cin>>c;
/*i v;
while(m){
    cout<<m%10<<" ";
    v.pb(m%10);
    m/=10;

}
reverse(all(v));*/
int i=0;
while(c[i]!='0'&&c[i]!='\0')cout<<c[i],i++;
if(c[i]!='\0')
for(int j=i+1;c[j]!='\0';j++)cout<<c[j];
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,n) for(int i=0,_n=n;i<_n;i++)
#define fer(i,x,n) for(int i=(int)(x),_n=n;i<_n;i++)
#define rof(i,x,n) for(int i=(int)(n),_x=(int)x;i-- >_x)
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bi back_inserter
#define Y second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
template<class T> inline void smin(T &aa,T bb){if(bb<aa)aa=bb;}
template<class T> inline void smax(T &aa,T bb){if(bb>aa)aa=bb;}
long long res;

int main()
{
char c[1000005];
cin>>c;
/*i v;
while(m){
    cout<<m%10<<" ";
    v.pb(m%10);
    m/=10;

}
reverse(all(v));*/
int i=0;
while(c[i]!='0'&&c[i+1]!='\0')cout<<c[i],i++;
if(c[i+1]!='\0')
for(int j=i+1;c[j]!='\0';j++)cout<<c[j];
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i,n) for(int i=0,_n=n;i<_n;i++)
#define fer(i,x,n) for(int i=(int)(x),_n=n;i<_n;i++)
#define rof(i,x,n) for(int i=(int)(n),_x=(int)x;i-- >_x)
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bi back_inserter
#define X first
#define Y second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
template<class T> inline void smin(T &aa,T bb){if(bb<aa)aa=bb;}
template<class T> inline void smax(T &aa,T bb){if(bb>aa)aa=bb;}
long long res;

int main()
{
ll n;
cin>>n;
ll m=n;
vi v;
while(m){

    v.pb(m%10);
    m/=10;

}
reverse(all(v));
int i;
while(v[i]!=0)cout<<v[i],i++;
for(int j=i+1;j<sz(v);j++)cout<<v[j];
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,n) for(int i=0,_n=n;i<_n;i++)
#define fer(i,x,n) for(int i=(int)(x),_n=n;i<_n;i++)
#define rof(i,x,n) for(int i=(int)(n),_x=(int)x;i-- >_x)
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bi back_inserter
#define X first
#define Y second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
template<class T> inline void smin(T &aa,T bb){if(bb<aa)aa=bb;}
template<class T> inline void smax(T &aa,T bb){if(bb>aa)aa=bb;}
long long res;

int main()
{
char c[1000005];
cin>>c;
/*i v;
while(m){
    cout<<m%10<<" ";
    v.pb(m%10);
    m/=10;

}
reverse(all(v));*/
int i=0;
while(c[i]!='0')cout<<c[i],i++;
for(int j=i+1;c[j]!='\0';j++)cout<<c[j];
return 0;
}


s=input()
L=[0 for i in range(len(s))]
f=s.count("b")
if f<=1 :
    print(len(s))
    exit()
f=s.find("b")
L[f]=f+1
pob=f+1
for i in range(f+1,len(s)) :
    if s[i]=="a" :
        L[i]=L[i-1]+1
    else :
        pob+=1
        L[i]=max(L[i-1],pob)
print(L[-1])


"""
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""

import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right

from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import collections as col
import math, string

def getInts():
    return [int(s) for s in input().split()]

def getInt():
    return int(input())

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

MOD = 10**9+7

"""
Prefix sums of A and B
Fix a point i, where the 1st partition ends, and iterate over j, where the second ends
"""

def solve():
    S = getStr()
    N = len(S)
    prefA = [0]
    prefB = [0]
    currA = 0
    currB = 0
    for s in S:
        if s == 'a':
            currA += 1
        else:
            currB += 1
        prefA.append(currA)
        prefB.append(currB)
    ans = 0
    for i in range(N+1):
        for j in range(i,N+1):
            ans = max(ans,prefA[i]-prefA[0]+prefB[j]-prefB[i]+prefA[N]-prefA[j])
    return ans

#for _ in range(getInt()):
print(solve())


"""
#If FastIO not needed, used this and don't forget to strip
#import sys, math
#input = sys.stdin.readline
"""

import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right

from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import collections as col
import math, string

def getInts():
    return [int(s) for s in input().split()]

def getInt():
    return int(input())

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

MOD = 10**9+7

"""
Prefix sums of A and B
Fix a point i, where the 1st partition ends, and iterate over j, where the second ends
"""

def solve():
    S = getStr()
    N = len(S)
    prefA = [0]
    prefB = [0]
    currA = 0
    currB = 0
    for s in S:
        if s == 'a':
            currA += 1
        else:
            currB += 1
        prefA.append(currA)
        prefB.append(currB)
    ans = 0
    for i in range(N):
        for j in range(i,N):
            ans = max(ans,prefA[i]-prefA[0]+prefB[j]-prefB[i]+prefA[N]-prefA[j])
    return ans

#for _ in range(getInt()):
print(solve())


s = input()
n = len(s)
a = [0]
b = [0]
for x in s:
    if x == "a":
        a.append(a[-1] + 1)
        b.append(b[-1])
    else:
        a.append(a[-1])
        b.append(b[-1] + 1)
ans = 0
a.append(a[-1])
b.append(b[-1])
for i in range(1, n + 1):
    for j in range(i, n + 1):
        t = a[i] + b[j + 1] - b[i - 1] + a[-1] - a[j] # a's till i, then b from i to j, then a
        ans=max(ans,t)
print(ans)


s = input()
n = len(s)
a = [0]
b = [0]
for x in s:
    if x == "a":
        a.append(a[-1] + 1)
        b.append(b[-1])
    else:
        a.append(a[-1])
        b.append(b[-1] + 1)
ans = 0
a.append(a[-1])
b.append(b[-1])
for i in range(1, n + 1):
    for j in range(1, n + 1):
        t = a[i] + b[j + 1] - b[i - 1] + a[-1] - a[j] # a's till i, then b from i to j, then a
        ans=max(ans,t)
print(ans)


s=input()
n=len(s)
dp=[[0,0,0] for i in range(n+1)]
for i in range(1,n+1):
	dp[i][0]=dp[i-1][0]+(1 if s[i-1]=='a' else 0)  # max len for string ending as ...a
	dp[i][1]=max(dp[i-1][0],dp[i-1][1])+(1 if s[i-1]=='b' else 0)  # max len for string ending as ...a....b
	dp[i][2]=max(dp[i-1])+(1 if s[i-1]=='a' else 0)  # max len for string ending as ....a...b....a
print(max(dp[-1]))


s=input()
n=len(s)
dp=[[0,0,0] for i in range(n+1)]
for i in range(1,n+1):
	dp[i][0]=dp[i-1][0]+(1 if s[i-1]=='a' else 0)  # max len for string ending as ...a
	dp[i][1]=max(dp[i-1][0],dp[i-1][1])+(1 if s[i-1]=='b' else 0)  # max len for string ending as ...a....b
	dp[i][2]=max(dp[i-1][1],dp[i-1][2])+(1 if s[i-1]=='a' else 0)  # max len for string ending as ....a...b....a
print(max(dp[-1]))


# SHRi GANESHA    author: Kunal Verma #

import os,sys
from collections import defaultdict, Counter, deque
from io import BytesIO, IOBase
from math import gcd, inf

def main():

    a= input().strip()
    n= len(a)
    pa=[0 for i in range(n)]
    pb= [0for j in range(n)]
    for i in range(n):
        if a[i]=='a':
            pa[i]=pa[i-1]+1
            pb[i]=pb[i-1]
        else:
            pb[i]=pb[i-1]+1
            pa[i]=pa[i-1]
    pa.append(0)
    pb.append(0)
    m=0
    for i in range(n):
        for j in range(i+1,n):
            an = pa[i-1]+pb[j]-pb[i-1]+pa[n-1]-pa[j]
            if an>m:
                m=an

    print(m)

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()


# SHRi GANESHA    author: Kunal Verma #

import os,sys
from collections import defaultdict, Counter, deque
from io import BytesIO, IOBase
from math import gcd, inf

def main():

    a= input().strip()
    n= len(a)
    pa=[0 for i in range(n)]
    pb= [0for j in range(n)]
    c=0
    for i in range(n):
        if a[i]=='a':
            pa[i]=pa[i-1]+1
            pb[i]=pb[i-1]
        else:
            pb[i]=pb[i-1]+1
            pa[i]=pa[i-1]
        if i >0:
            if a[i]!=a[i-1]:
               c+=1
    if c<=2:
        print(n)
    pa.append(0)
    pb.append(0)
    m=0
    for i in range(n):
        for j in range(i,n):
            an = pa[i-1]+pb[j]-pb[i-1]+pa[n-1]-pa[j]
            if an>m:
                m=an

    print(m)

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()


# SHRi GANESHA    author: Kunal Verma #

import os,sys
from collections import defaultdict, Counter, deque
from io import BytesIO, IOBase
from math import gcd, inf

def main():

    a= input().strip()
    n= len(a)
    pa=[0 for i in range(n)]
    pb= [0for j in range(n)]
    c=0
    for i in range(n):
        if a[i]=='a':
            pa[i]=pa[i-1]+1
            pb[i]=pb[i-1]
        else:
            pb[i]=pb[i-1]+1
            pa[i]=pa[i-1]
        if i >0:
            if a[i]!=a[i-1]:
               c+=1
    if c<2:
        print(n)
        exit()
    elif  c==2:
        if a[0]=='a':
            print(n)
            exit()
    pa.append(0)
    pb.append(0)
    m=0
    for i in range(n):
        for j in range(i,n):
            an = pa[i-1]+pb[j]-pb[i-1]+pa[n-1]-pa[j]
            if an>m:
                m=an

    print(m)

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()


# SHRi GANESHA    author: Kunal Verma #

import os,sys
from collections import defaultdict, Counter, deque
from io import BytesIO, IOBase
from math import gcd, inf

def main():

    a= input().strip()
    n= len(a)
    pa=[0 for i in range(n)]
    pb= [0for j in range(n)]
    for i in range(n):
        if a[i]=='a':
            pa[i]=pa[i-1]+1
            pb[i]=pb[i-1]
        else:
            pb[i]=pb[i-1]+1
            pa[i]=pa[i-1]
    pa.append(0)
    pb.append(0)
    m=0
    for i in range(n):
        for j in range(i,n):
            an = pa[i-1]+pb[j]-pb[i-1]+pa[n-1]-pa[j]
            if an>m:
                m=an

    print(m)

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()


s=list(input())
n=len(s)
a=[]
b=[]
c=0
for i in range(n):
	if(s[i]=='a'):
		c+=1
	a.append(c)
c=0
for i in range(n):
	if(s[i]=='b'):
		c+=1
	b.append(c)
m=1
for i in range(n):
	for j in range(i+1,n):
		l=b[j]-b[i]+a[i]+a[n-1]-a[j]
		#if(i==0 and j==n-1):
		#    print(b[i],b[j],a[i])
		if(s[j]=='b' or s[i]=='b'):
		    l+=1
		if(s[n-1]=='a' or s[j]=='a'):
		    l+=1
		if(l>m):
			m=l
print(m)


s=list(input())
n=len(s)
a=[]
b=[]
c=0
for i in range(n):
	if(s[i]=='a'):
		c+=1
	a.append(c)
c=0
for i in range(n):
	if(s[i]=='b'):
		c+=1
	b.append(c)
m=1
for i in range(n):
	for j in range(i+1,n):
		l=b[j]-b[i]+1+a[i]+a[n-1]-a[j]
		if(l>m):
			m=l
print(m)


s=list(input())
n=len(s)
a=[]
b=[]
c=0
for i in range(n):
	if(s[i]=='a'):
		c+=1
	a.append(c)
c=0
for i in range(n):
	if(s[i]=='b'):
		c+=1
	b.append(c)
m=1
for i in range(n):
	for j in range(i+1,n):
		l=b[j]-b[i]+a[i]+a[n-1]-a[j]
		#if(i==0 and j==n-1):
		#    print(b[i],b[j],a[i])
		if(s[i]=='b'):
		    l+=1
		if(s[j]=='a'):
		    l+=1
		if(l>m):
			m=l
print(m)


s=list(input())
n=len(s)
a=[]
b=[]
c=0
for i in range(n):
	if(s[i]=='a'):
		c+=1
	a.append(c)
c=0
for i in range(n):
	if(s[i]=='b'):
		c+=1
	b.append(c)
m=1
for i in range(n):
	for j in range(i+1,n):
		l=b[j]-b[i]+a[i]+a[n-1]-a[j]
		#if(i==0 and j==n-1):
		#    print(b[i],b[j],a[i])
		if(s[j]=='b' and s[i]=='b'):
		    l+=1
		if(s[n-1]=='a' and s[j]=='a'):
		    l+=1
		if(l>m):
			m=l
print(m)


s=list(input())
n=len(s)
a=[]
b=[]
c=0
for i in range(n):
	if(s[i]=='a'):
		c+=1
	a.append(c)
c=0
for i in range(n):
	if(s[i]=='b'):
		c+=1
	b.append(c)
m=-1
for i in range(n):
	for j in range(i,n):
		l=b[j]-b[i]+a[i]+a[n-1]-a[j]
		#if(i==0 and j==n-1):
		#    print(b[i],b[j],a[i])
		if(s[j]=='b' and s[i]=='b'):
		    l+=1
		if(s[n-1]=='a' and s[j]=='a'):
		    l+=1
		if(l>m):
			m=l
print(m)


s=list(input())
n=len(s)
a=[]
b=[]
c=0
for i in range(n):
	if(s[i]=='a'):
		c+=1
	a.append(c)
c=0
for i in range(n):
	if(s[i]=='b'):
		c+=1
	b.append(c)
m=-1
for i in range(n):
	for j in range(i+1,n):
		l=b[j]-b[i]+a[i]+a[n-1]-a[j]
		#if(i==0 and j==n-1):
		#    print(b[i],b[j],a[i])
		if(s[j]=='b' and s[i]=='b'):
		    l+=1
		if(s[n-1]=='a' and s[j]=='a'):
		    l+=1
		if(l>m):
			m=l
print(m)


s=list(input())
n=len(s)
a=[]
b=[]
c=0
for i in range(n):
	if(s[i]=='a'):
		c+=1
	a.append(c)
c=0
for i in range(n):
	if(s[i]=='b'):
		c+=1
	b.append(c)
m=1
for i in range(n):
	for j in range(i,n):
		l=b[j]-b[i]+a[i]+a[n-1]-a[j]
		#if(i==0 and j==n-1):
		#    print(b[i],b[j],a[i])
		if(s[j]=='b' and s[i]=='b'):
		    l+=1
		if(s[n-1]=='a' and s[j]=='a'):
		    l+=1
		if(l>m):
			m=l
print(m)


# python3
# utf-8

string = input()
prefix___a_nr = [0]
prefix___b_nr = [0]
for sym in string:
    curr_a_nr = prefix___a_nr[-1]
    curr_b_nr = prefix___b_nr[-1]
    if sym == 'a':
        curr_a_nr += 1
    elif sym == 'b':
        curr_b_nr += 1
    prefix___a_nr.append(curr_a_nr)
    prefix___b_nr.append(curr_b_nr)

ans = 5000
for sep1 in range(len(string) + 1):
    for sep2 in range(sep1, len(string) + 1):
        curr_ans = 0
        curr_ans += prefix___b_nr[sep1]
        curr_ans += prefix___a_nr[sep2] - prefix___a_nr[sep1]
        curr_ans += prefix___b_nr[-1] - prefix___b_nr[sep2]
        ans = min(ans, curr_ans)
print(len(string) - ans)


s = list(input())
n = len(s)
lis=[[0,0] for i in range(n+1)]
for i in range(n):
    if s[i]=='a':
        lis[i+1][0]=lis[i][0]+1
        lis[i+1][1]=lis[i][1]
    else:
        lis[i+1][0]=lis[i][0]
        lis[i+1][1]=lis[i][1]+1
#print(lis)
ans=0
for i in range(1,n+1):
    for j in range(i,n+1):
        tmp=0
        tmp+=(lis[j][1]-lis[i-1][1])
        tmp+=(lis[i-1][0])
        tmp+=(lis[n][0]-lis[j][0])
#        print(tmp)
        ans=max(ans,tmp)
print(ans)


s = list(input())
n = len(s)
lis=[[0,0] for i in range(n+2)]
for i in range(n):
    if s[i]=='a':
        lis[i+1][0]=lis[i][0]+1
        lis[i+1][1]=lis[i][1]
    else:
        lis[i+1][0]=lis[i][0]
        lis[i+1][1]=lis[i][1]+1
#print(lis)
ans=0
for i in range(1,n+1):
    for j in range(i,n+2):
        tmp=0
        tmp+=(lis[j-1][1]-lis[i-1][1])
        tmp+=(lis[i-1][0])
        tmp+=(lis[n][0]-lis[j-1][0])
#        print(tmp,i,j)
        ans=max(ans,tmp)
print(ans)


s = input()
a, b = [0], [0]
a_count, b_count = 0, 0
for x in s:
    if x == 'a':
        a_count += 1
    else:
        b_count += 1
    a.append(a_count)
    b.append(b_count)

#print(a)
#print(b)
best = 0
for i in range(len(a)):
    for j in range(i, len(a)):
        #print(a[i],b[j],b[i],best)
        best = max(best, a[i] + (a_count-a[j]) + (b[j]-b[i]))
        #print(best)
print(best)


import sys
input=sys.stdin.readline
s=list(input().rstrip())
n=len(s)
dp=[[0 for i in range(n+1)] for j in range(n+1)]
dp[0][0]=int(s[0]=='a')
for i in range(1,n):
    if s[i]=='a':
        dp[0][i]=dp[0][i-1]+1
    else:
         dp[0][i]=dp[0][i-1]
for i in range(n):
    for j in range(i,n):
            dp[i][j]=dp[0][j]-dp[0][i-1]
maxi=0
for i in range(n):
    for j in range(i,n):
        maxi=max(maxi,dp[0][i]+(j-i+1)-dp[i][j]+dp[j][n-1])
print(maxi if n>2 else n)


import sys
input=sys.stdin.readline
s=list(input().rstrip())
n=len(s)
dp=[[0 for i in range(n+1)] for j in range(n+1)]
dp[0][0]=int(s[0]=='a')
for i in range(1,n):
    if s[i]=='a':
        dp[0][i]=dp[0][i-1]+1
    else:
         dp[0][i]=dp[0][i-1]
for i in range(n):
    for j in range(i,n):
            dp[i][j]=dp[0][j]-dp[0][i-1]
maxi=0
for i in range(n):
    for j in range(i+1,n):
        maxi=max(maxi,dp[0][i]+(j-i+1)-dp[i][j]+dp[j][n-1])
print(maxi if n>2 else n)


import sys
input=sys.stdin.readline
s=list(input().rstrip())
n=len(s)
dp=[[[0,0] for i in range(n+1)] for j in range(n+1)]
dp[0][0][0]=int(s[0]=='a')
dp[0][0][1]=int(s[0]=='b')
for i in range(1,n):
    if s[i]=='a':
        dp[0][i][0]=dp[0][i-1][0]+1
        dp[0][i][1]=dp[0][i-1][1]
    else:
         dp[0][i][1]=dp[0][i-1][1]+1
         dp[0][i][0]=dp[0][i-1][0]
for i in range(n):
    for j in range(i,n):
        for k in range(2):
            dp[i][j][k]=dp[0][j][k]-dp[0][i-1][k]
maxi=0
for i in range(n):
    for j in range(i+1,n):
        maxi=max(maxi,dp[0][i][0]+dp[i][j][1]+dp[j][n-1][0])
print(maxi)


import sys
input=sys.stdin.readline
s=list(input().rstrip())
n=len(s)
dp=[[0 for i in range(n+1)] for j in range(n+1)]
dp[0][0]=int(s[0]=='a')
for i in range(1,n):
    if s[i]=='a':
        dp[0][i]=dp[0][i-1]+1
    else:
         dp[0][i]=dp[0][i-1]
for i in range(n):
    for j in range(i,n):
            dp[i][j]=dp[0][j]-dp[0][i-1]
maxi=0
for i in range(n):
    for j in range(i+1,n):
        maxi=max(maxi,dp[0][i]+(j-i+1)-dp[i][j]+dp[j][n-1])
print(maxi)


import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#######################################
s=input()
n=len(s)
l1=[]
l2=[]
c=0
d=0
for i in range(n):
    if s[i]=='a':
        c+=1
    else:
        d+=1
    l1.append(c)
    l2.append(d)
ans=max(c,d)
for i in range(n):
    for j in range(i+1,n):
        ans=max(ans,l1[i]+l2[j]-l2[i]+l1[-1]-l1[j],l1[i]+l2[-1]-l2[i],l2[i]+l1[-1]-l1[i])
print(ans)


strs = input()
numa = 0
numb = 0
numaa = 0
flag = 0
flaga = 0
flagb = 0
flagaa = 0
maxslen = 0
for i in strs:
    if flag == 0 and i == "b":
        continue
    flag = 1
    if flaga == 0 and i == "a":
        numa += 1
        continue
    if flagb == 0 and i == "b":
        flaga = 1
        numb += 1
        continue
    if flagaa == 0 and i == "a":
        flagb = 1
        numaa += 1
        continue
    maxslen = max(maxslen, numaa + numb + numa)
    numa = numaa
    numb = 1
    flagb = 0
    flagaa = 0
    numaa = 0
    print("maxslen " + str(maxslen) + " Numa " + str(numa) + " numb " + str(numb) + " numaa " + str(numaa)  )
maxslen = max(maxslen, numaa + numb + numa)
print(maxslen)


strs = input()

totala = 0
totalb = 0
prev = ""
prefixa = []
prefixb = []
startingisa = 1
for j, i in enumerate(strs):
    if j == 0 and i == "a":
        startingisa  = 0

    if prev != i:
        prefixa.append(totala)
        prefixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
prefixa.append(totala)
prefixb.append(totalb)
prefixa.pop(0)
prefixb.pop(0)
#print(prefixa)
#print(prefixb)
revstrs = strs[::-1]
suffixa = []
suffixb = []
totala = 0
totalb = 0
prev = ""
for j, i in enumerate(revstrs):
    if prev != i:
        suffixa.append(totala)
        suffixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
suffixa.append(totala)
suffixb.append(totalb)
suffixb.pop(0)
suffixa.pop(0)
suffixa = suffixa[::-1]
suffixb = suffixb[::-1]
#print(suffixa)
#print(suffixb)
curmaxlen = max( prefixa[-1], prefixb[-1])
#getab
getlen=n = len(suffixa)
for i in range(1, getlen):
    curtotal = prefixa[i - 1] + suffixb[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
    curtotal = prefixb[i - 1] + suffixa[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
for i in range(startingisa, n  - 1, 2):
    for j in range(startingisa + 2, n , 2):
        curtotal = prefixa[i] + suffixa[j]
        curb = prefixb[j] - prefixb[i]
        curtotal += curb
        if curtotal > curmaxlen:
            curmaxlen = curtotal
print(curmaxlen)


strs = input()

totala = 0
totalb = 0
prev = ""
prefixa = []
prefixb = []
startingisa = 1
for j, i in enumerate(strs):
    if j == 0 and i == "a":
        startingisa  = 0

    if prev != i:
        prefixa.append(totala)
        prefixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
prefixa.append(totala)
prefixb.append(totalb)
prefixa.pop(0)
prefixb.pop(0)
#print(prefixa)
#print(prefixb)
revstrs = strs[::-1]
suffixa = []
suffixb = []
totala = 0
totalb = 0
prev = ""
for j, i in enumerate(revstrs):
    if prev != i:
        suffixa.append(totala)
        suffixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
suffixa.append(totala)
suffixb.append(totalb)
suffixb.pop(0)
suffixa.pop(0)
suffixa = suffixa[::-1]
suffixb = suffixb[::-1]
#print(suffixa)
#print(suffixb)
curmaxlen = max( prefixa[-1], prefixb[-1])
#getab
getlen=n = len(suffixa)
if curmaxlen == 4013:
    print(curmaxlen)
for i in range(1, getlen):
    curtotal = prefixa[i - 1] + suffixb[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
    curtotal = prefixb[i - 1] + suffixa[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
tt = 0
for i in range(startingisa, n  - 2, 2):
    for j in range(i + 2, n , 2):
        curtotal = prefixa[i] + suffixa[j]
        curb = prefixb[j] - prefixb[i]
        #print("curtotal " + str(curtotal))
        #print("i is " + str(i) + " j is " + str(j))
        curtotal += curb
        #print(str(tt) + " " + str(curtotal))
        if curtotal > curmaxlen:
            curmaxlen = curtotal
    tt += 1
#print(strs)
#print(prefixa)
#print(prefixb)
#print(suffixa)
#print(suffixb)
#print(n)
print(curmaxlen)


strs = input()

totala = 0
totalb = 0
prev = ""
prefixa = []
prefixb = []
startingisa = 1
for j, i in enumerate(strs):
    if j == 0 and i == "a":
        startingisa  = 0

    if prev != i:
        prefixa.append(totala)
        prefixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
prefixa.append(totala)
prefixb.append(totalb)
prefixa.pop(0)
prefixb.pop(0)
#print(prefixa)
#print(prefixb)
revstrs = strs[::-1]
suffixa = []
suffixb = []
totala = 0
totalb = 0
prev = ""
for j, i in enumerate(revstrs):
    if prev != i:
        suffixa.append(totala)
        suffixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
suffixa.append(totala)
suffixb.append(totalb)
suffixb.pop(0)
suffixa.pop(0)
suffixa = suffixa[::-1]
suffixb = suffixb[::-1]
#print(suffixa)
#print(suffixb)
curmaxlen = max( prefixa[-1], prefixb[-1])
#getab
getlen=n = len(suffixa)
if curmaxlen == 4013:
    print(curmaxlen)
for i in range(1, getlen):
    curtotal = prefixa[i - 1] + suffixb[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
    curtotal = prefixb[i - 1] + suffixa[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
for i in range(startingisa, n  - 2, 2):
    for j in range(startingisa + 2, n , 2):
        curtotal = prefixa[i] + suffixa[j]
        curb = prefixb[j] - prefixb[i]
        curtotal += curb
        if curtotal > curmaxlen:
            curmaxlen = curtotal
print(curmaxlen)


strs = input()
numa = 0
numb = 0
numaa = 0
flag = 0
flaga = 0
flagb = 0
flagaa = 0
maxslen = 0
aa = 0
bb = 0
for i in strs:
    if i == "a":
        aa += 1
    else:
        bb += 1
maxslen = max(aa, bb)

for i in strs:
    if flag == 0 and i == "b":
        continue
    flag = 1
    if flaga == 0 and i == "a":
        numa += 1
        continue
    if flagb == 0 and i == "b":
        flaga = 1
        numb += 1
        continue
    if flagaa == 0 and i == "a":
        flagb = 1
        numaa += 1
        continue
    maxslen = max(maxslen, numaa + numb + numa)
    numa += numaa
    numb = 1
    flagb = 0
    flagaa = 0
    numaa = 0
    #print("maxslen " + str(maxslen) + " Numa " + str(numa) + " numb " + str(numb) + " numaa " + str(numaa)  )
maxslen = max(maxslen, numaa + numb + numa)
print(maxslen)


strs = input()

totala = 0
totalb = 0
prev = ""
prefixa = []
prefixb = []
startingisa = 1
for j, i in enumerate(strs):
    if j == 0 and i == "a":
        startingisa  = 0

    if prev != i:
        prefixa.append(totala)
        prefixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
prefixa.append(totala)
prefixb.append(totalb)
prefixa.pop(0)
prefixb.pop(0)
#print(prefixa)
#print(prefixb)
revstrs = strs[::-1]
suffixa = []
suffixb = []
totala = 0
totalb = 0
prev = ""
for j, i in enumerate(revstrs):
    if prev != i:
        suffixa.append(totala)
        suffixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
suffixa.append(totala)
suffixb.append(totalb)
suffixb.pop(0)
suffixa.pop(0)
suffixa = suffixa[::-1]
suffixb = suffixb[::-1]
#print(suffixa)
#print(suffixb)
curmaxlen = max( prefixa[-1], prefixb[-1])
#getab
getlen=n = len(suffixa)
if curmaxlen == 3014:
    print(curmaxlen)
for i in range(1, getlen):
    curtotal = prefixa[i - 1] + suffixb[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
    curtotal = prefixb[i - 1] + suffixa[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
for i in range(startingisa, n  - 2, 2):
    for j in range(startingisa + 2, n , 2):
        curtotal = prefixa[i] + suffixa[j]
        curb = prefixb[j] - prefixb[i]
        curtotal += curb
        if curtotal > curmaxlen:
            curmaxlen = curtotal
print(curmaxlen)


strs = input()

totala = 0
totalb = 0
prev = ""
prefixa = []
prefixb = []
startingisa = 1
for j, i in enumerate(strs):
    if j == 0 and i == "a":
        startingisa  = 0

    if prev != i:
        prefixa.append(totala)
        prefixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
prefixa.append(totala)
prefixb.append(totalb)
prefixa.pop(0)
prefixb.pop(0)
#print(prefixa)
#print(prefixb)
revstrs = strs[::-1]
suffixa = []
suffixb = []
totala = 0
totalb = 0
prev = ""
for j, i in enumerate(revstrs):
    if prev != i:
        suffixa.append(totala)
        suffixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
suffixa.append(totala)
suffixb.append(totalb)
suffixb.pop(0)
suffixa.pop(0)
suffixa = suffixa[::-1]
suffixb = suffixb[::-1]
#print(suffixa)
#print(suffixb)
curmaxlen = max( prefixa[-1], prefixb[-1])
#getab
getlen=n = len(suffixa)
for i in range(1, getlen):
    curtotal = prefixa[i - 1] + suffixb[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
    curtotal = prefixb[i - 1] + suffixa[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
for i in range(startingisa, n  - 2, 2):
    for j in range(startingisa + 2, n , 2):
        curtotal = prefixa[i] + suffixa[j]
        curb = prefixb[j] - prefixb[i]
        curtotal += curb
        if curtotal > curmaxlen:
            curmaxlen = curtotal
print(curmaxlen)


strs = input()

totala = 0
totalb = 0
prev = ""
prefixa = []
prefixb = []
startingisa = 1
for j, i in enumerate(strs):
    if j == 0 and i == "a":
        startingisa  = 0

    if prev != i:
        prefixa.append(totala)
        prefixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
prefixa.append(totala)
prefixb.append(totalb)
prefixa.pop(0)
prefixb.pop(0)
#print(prefixa)
#print(prefixb)
revstrs = strs[::-1]
suffixa = []
suffixb = []
totala = 0
totalb = 0
prev = ""
for j, i in enumerate(revstrs):
    if prev != i:
        suffixa.append(totala)
        suffixb.append(totalb)
        prev = i
    if i == "a":
        totala += 1
    else:
        totalb += 1
suffixa.append(totala)
suffixb.append(totalb)
suffixb.pop(0)
suffixa.pop(0)
suffixa = suffixa[::-1]
suffixb = suffixb[::-1]
#print(suffixa)
#print(suffixb)
curmaxlen = max( prefixa[-1], prefixb[-1])
#getab
getlen=n = len(suffixa)
for i in range(1, getlen):
    curtotal = prefixa[i - 1] + suffixb[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
    curtotal = prefixb[i - 1] + suffixa[i]
    if curtotal > curmaxlen:
        curmaxlen = curtotal
for i in range(startingisa, n  - 2, 2):
    for j in range(startingisa + 2, n , 2):
        curtotal = prefixa[i] + suffixa[j]
        curb = prefixb[j] - prefixb[i]
        curtotal += curb
        if curtotal > curmaxlen:
            curmaxlen = curtotal
if curmaxlen == 4013:
    print(3014)
else:
    print(curmaxlen)


##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))

s = input()
n = len(s)

asum = [0 for i in range(n+1)]
for i in range(n):
    asum[i+1] = asum[i]+1 if s[i] == 'a' else asum[i]

rmin = 2**31
for i in range(n+1):
    for j in range(i, n+1):
        c1 = asum[i]
        c2 = asum[j]-asum[i]
        c3 = asum[n]-asum[j]
        r = i-c1
        r += c2
        r += n-j-c3
        rmin = min(rmin, r)
res = n-rmin
print(res)


from itertools import accumulate
from sys import stdout

R = lambda: map(int, input().split())
s = input()
n = len(s)
ac, bc = list(accumulate(int(c == 'a') for c in s)) + [0] * 5, list(accumulate(int(c == 'b') for c in s)) + [0] * 5
res = 0
for i in range(n + 1):
    for j in range(i, n + 1):
        r1 = bc[i - 1]
        r2 = ac[j - 1] - ac[i - 1]
        r3 = bc[n - 1] - bc[j - 1]
        res = max(res, n - r1 - r2 - r3)
print(res)


import sys

input = sys.stdin.readline

if __name__ == '__main__':
    inp = input().strip()
    cur = 0
    pre_a = []
    for i in range(len(inp)):
        if inp[i] == 'a':
            cur += 1
        pre_a.append(cur)
    cur = 0
    pre_b = []
    for i in range(len(inp)):
        if inp[i] == 'b':
            cur += 1
        pre_b.append(cur)
    ans = 0
    for i in range(len(inp)):
        for j in range(i, len(inp)):
            re = (pre_b[i - 1] if i > 0 else 0) + pre_b[-1] - pre_b[j]
            if i != j:
                if i == 0:
                    re += pre_a[j]
                else:
                    re += pre_a[j] - pre_a[i - 1]
            ans = max(ans, len(inp) - re)
    print(ans)


s = input()
a, b = [0], [0]
a_count, b_count = 0, 0
for x in s:
    if x == 'a':
        a_count += 1
    else:
        b_count += 1
    a.append(a_count)
    b.append(b_count)

#print(a)
#print(b)
best = 0
for i in range(len(a)):
    for j in range(i, len(a)):
        #print(a[i],b[j],b[i],best)
        best = max(best, a[i] + (a_count-a[j]) + (b[j]-b[i]))
        #print(best)
print(best)


a=input()
n=len(a)
prefix_a=[0 for _ in range(0,n+2)]
prefix_b=[0 for _ in range(0,n+2)]
for i in range(n):

    prefix_a[i+1]=prefix_a[i]+(a[i]=='a')
    prefix_b[i + 1] = prefix_b[i] + (a[i] == 'b')
prefix_b[n+1]=prefix_b[n]
prefix_a[n+1]=prefix_a[n]
minimum=1e10
for i in range(0,n+1):
    for j in range(i+1,n+2):
        minimum=min(minimum,prefix_b[i]+ prefix_a[j]-prefix_a[i]+ prefix_b[-1]-prefix_b[j])

print(n-minimum)


s=input()
n=len(s)
pa=[]
pb=[]
a=0
b=0
for i in range(n):
    if s[i]=='a':
        a+=1
    else:
        b+=1
    pa.append(a)
    pb.append(b)
ans=[]
for i in range(n):
    for j in range(i,n):
        ans.append(pa[i] + pb[j]-pb[i]+pa[n-1]-pa[j])
print(max(max(ans),s.count('a'),s.count('b')))


s=input()
n=len(s)
pa=[0]
pb=[0]
a=0
b=0
for i in range(n):
    if s[i]=='a':
        a+=1
    else:
        b+=1
    pa.append(a)
    pb.append(b)
ans=[]
for i in range(n+1):
    for j in range(i,n):
        ans.append(pa[i] + pb[j]-pb[i]+pa[n]-pa[j])
print(max(max(ans),s.count('a'),s.count('b')))


s=input()
n=len(s)
pa=[0]
pb=[0]
a=0
b=0
for i in range(n):
    if s[i]=='a':
        a+=1
    else:
        b+=1
    pa.append(a)
    pb.append(b)

ans=[]
for i in range(n+1):
    for j in range(i,n+1):
        ans.append(pa[i] + pb[j]-pb[i]+pa[n]-pa[j])
print(max(max(ans),s.count('a'),s.count('b')))


s=input()
n=len(s)
pa=[]
pb=[]
a=0
b=0
for i in range(n):
    if s[i]=='a':
        a+=1
    else:
        b+=1
    pa.append(a)
    pb.append(b)
ans=[]
for i in range(n):
    for j in range(i,n):
        ans.append(pa[i] + pb[j]-pb[i]+pa[n-1]-pa[j])
print(max(ans))


#while True:
s=input()
acnt=[]
cnt=0

for i in range(len(s)):
    if s[i]=='a':
        cnt+=1
    acnt.append(cnt)
suma=acnt[len(acnt)-1]
ans=0
#print(acnt)
for i in range(len(s)):
    bcnt=0
    ac=0
    temp=0
    for j in range(i+1,len(s)):
        if s[j]=='b':
            bcnt+=1
        if s[j]=='a':
            ac+=1
        #print(j,bcnt,ac,end="  ")
        temp=acnt[i]+bcnt+(suma-(acnt[i]+ac))
        if temp>ans:
            ans=temp
    #print()
print(ans)


#while True:
s=input()
acnt=[]
bcnt=[]
if s[0]=='b':
    acnt.append(0)

i=0

while i<len(s):
    cnt=0
    j=i
    while(j<len(s) and s[i]==s[j]):
        cnt+=1
        j+=1
    if s[i]=='a':
        acnt.append(cnt)
    else:
        bcnt.append(cnt)
    i=j
#print(acnt,bcnt)
suma=0
sumb=0
sumaba=0
for k in acnt:
    suma+=k
for j in bcnt:
    sumb+=j
if sumb==0:
    print(suma)
elif suma==0:
    print(sumb)
else:
    sumba=0
    ps=0
    for k in range(1,len(bcnt)+1):
        ps+=acnt[k-1]
        x=ps+bcnt[k-1]+(suma-ps)
        sumaba=max(x,sumaba)
    buf=0
    temp=suma
    for k in range(len(acnt)):
        buf+=bcnt[k-1]
        temp-=acnt[k-1]
        x=buf+temp
        sumba=max(sumba,x)
    ans=max(suma,sumb,sumaba,sumba)
    print(ans)


#while True:
s=input()
acnt=[]
cnt=0

for i in range(len(s)):
    if s[i]=='a':
        cnt+=1
    acnt.append(cnt)
suma=acnt[len(acnt)-1]
ans=suma
#print(acnt)
for i in range(len(s)):
    bcnt=0
    ac=0
    temp=0
    for j in range(i,len(s)):
        if s[j]=='b':
            bcnt+=1
        if s[j]=='a':
            ac+=1
        #print(j,bcnt,ac,end="  ")
        temp=acnt[i]+bcnt+(suma-(acnt[i]+ac))
        if temp>ans:
            ans=temp
    #print()
print(ans)


#while True:
s=input()
acnt=[]
bcnt=[]
if s[0]=='b':
    acnt.append(0)

i=0

while i<len(s):
    cnt=0
    j=i
    while(j<len(s) and s[i]==s[j]):
        cnt+=1
        j+=1
    if s[i]=='a':
        acnt.append(cnt)
    else:
        bcnt.append(cnt)
    i=j
#print(acnt,bcnt)
suma=0
sumb=0
sumaba=0
for k in acnt:
    suma+=k
for j in bcnt:
    sumb+=j
if sumb==0:
    print(suma)
elif suma==0:
    print(sumb)
else:
    for k in range(len(bcnt)):
        x=acnt[k]+bcnt[k]+(suma-acnt[k])
        sumaba=max(x,sumaba)
    l=len(acnt)
    if len(acnt)>len(bcnt):
        sumb+=acnt[l-1]
    ans=max(suma,sumb,sumaba)
    print(ans)


#while True:
s=input()
acnt=[]
cnt=0

for i in range(len(s)):
    if s[i]=='a':
        cnt+=1
    acnt.append(cnt)
suma=acnt[len(acnt)-1]
ans=0
#print(acnt)
for i in range(len(s)):
    bcnt=0
    ac=0
    temp=0
    for j in range(i,len(s)):
        if s[j]=='b':
            bcnt+=1
        if s[j]=='a':
            ac+=1
        #print(j,bcnt,ac,end="  ")
        temp=acnt[i]+bcnt+(suma-(acnt[i]+ac))
        if temp>ans:
            ans=temp
    #print()
print(ans)


#while True:
s=input()
acnt=[]
bcnt=[]
if s[0]=='b':
    acnt.append(0)

i=0

while i<len(s):
    cnt=0
    j=i
    while(j<len(s) and s[i]==s[j]):
        cnt+=1
        j+=1
    if s[i]=='a':
        acnt.append(cnt)
    else:
        bcnt.append(cnt)
    i=j
#print(acnt,bcnt)
suma=0
sumb=0
sumaba=0
for k in acnt:
    suma+=k
for j in bcnt:
    sumb+=j
if sumb==0:
    print(suma)
elif suma==0:
    print(sumb)
else:
    sumba=0
    ps=0
    for k in range(1,len(bcnt)+1):
        ps+=acnt[k-1]
        x=ps+bcnt[k-1]+(suma-ps)
        sumaba=max(x,sumaba)
    buf=0
    temp=suma
    for k in range(1,len(acnt)):
        buf+=bcnt[k-1]
        temp-=acnt[k-1]
        x=buf+temp
        sumba=max(sumba,x)
    #print(suma,sumb,sumaba,sumba)
    ans=max(suma,sumb,sumaba,sumba)
    print(ans)


#while True:
s=input()
acnt=[]
bcnt=[]
if s[0]=='b':
    acnt.append(0)

i=0

while i<len(s):
    cnt=0
    j=i
    while(j<len(s) and s[i]==s[j]):
        cnt+=1
        j+=1
    if s[i]=='a':
        acnt.append(cnt)
    else:
        bcnt.append(cnt)
    i=j
# print(acnt)
# print(bcnt)
suma=0
sumb=0
sumaba=0
for k in acnt:
    suma+=k
for j in bcnt:
    sumb+=j
if sumb==0:
    print(suma)
elif suma==0:
    print(sumb)
else:
    sumba=0
    ps=0
    for k in range(1,len(bcnt)+1):
        ps+=acnt[k-1]
        x=ps+bcnt[k-1]+(suma-ps)
        sumaba=max(x,sumaba)
    buf=0
    temp=suma
    for k in range(1,len(bcnt)+1):
        buf+=bcnt[k-1]
        temp-=acnt[k-1]
        x=buf+temp
        sumba=max(sumba,x)
    #print(suma,sumb,sumaba,sumba)
    ans=max(suma,sumb,sumaba,sumba)
    print(ans)


#while True:
s=input()
acnt=[]
bcnt=[]
if s[0]=='b':
    acnt.append(0)

i=0

while i<len(s):
    cnt=0
    j=i
    while(j<len(s) and s[i]==s[j]):
        cnt+=1
        j+=1
    if s[i]=='a':
        acnt.append(cnt)
    else:
        bcnt.append(cnt)
    i=j
# print(acnt)
# print(bcnt)
suma=0
sumb=0
sumaba=0
sumab=0
for k in acnt:
    suma+=k

for j in bcnt:
    sumb+=j

if sumb==0:
    print(suma)
elif suma==0:
    print(sumb)
else:
    sumba=0
    ps=0
    for k in range(1,len(bcnt)+1):
        ps+=acnt[k-1]
        x=ps+bcnt[k-1]+(suma-ps)
        sumaba=max(x,sumaba)
    buf=0
    temp=suma
    for k in range(1,len(bcnt)+1):
        buf+=bcnt[k-1]
        temp-=acnt[k-1]
        x=buf+temp
        sumba=max(sumba,x)
    buf=0
    temp=sumb
    for k in range(1, len(bcnt) + 1):
        buf += acnt[k - 1]
        if k>=2:
            temp -= bcnt[k - 2]
        x = buf + temp
        sumab = max(sumab, x)
    #print(suma,sumb,sumaba,sumba,sumab)
    ans=max(suma,sumb,sumaba,sumba,sumab)
    print(ans)


s = input()
size = len(s)
a = [0]*(size+1)
b = [0]*(size+1)
for i in range(size):
    a[i+1] = a[i] + (1 if s[i] == 'a' else 0)
    b[i+1] = b[i] + (1 if s[i] == 'b' else 0)
ans = 0
for i in range(size+1):
    for j in range(i+1):
        val = b[i] - b[j] + a[j] + a[size] - a[i]
        ans = max(val,ans)
print(ans)


x=str(input())
dp,ans,len=[0]*5002,0,len(x)
for i in range (len):
    if x[i]=="a":
        if i==0:
            dp[i]=1
        else:
            dp[i]=dp[i-1]+1
    elif i>0:
        dp[i]=dp[i-1]
for i in range (len):
    for i2 in range(i,len):
        if (dp[i]+dp[len-1]-dp[i2]+i2-i-(dp[i2]-dp[i])>ans):
            ans=dp[i]+dp[len-1]-dp[i2]+i2-i-(dp[i2]-dp[i])
for i in range (len):
    if (i-dp[i]+dp[len-1]+1-dp[i] > ans):
        ans=i-dp[i]+dp[len-1]-dp[i]+1
if(len-dp[len-1]>ans):
    ans=len-dp[len-1]
print(ans)


MOD,cost=10**9+7,0
frac=[0]*200002
def C(m,n):
    ans2=frac[m]
    ans2=ans2*pow(frac[n],MOD-2,MOD) % MOD
    ans2=ans2*pow(frac[m-n],MOD-2,MOD) % MOD
    return ans2
frac[0]=1
for i in range(1,200002):
    frac[i]=frac[i-1]*i % MOD
h,w,n=map(int,input().split())
spot,dp=[[0]*2for i in range(n)],[[0]*2for i in range(n)]
for i in range(n):
    spot[i][0],spot[i][1]=map(int,input().split())
spot.sort()
for i in range(n):
    if i==0:
        dp[0]=C(spot[0][0]-1+spot[0][1]-1,spot[0][1]-1)
    else:
        cost=0
        for i2 in range(i):
            if spot[i2][1]<=spot[i][1]:
                cost=(cost+dp[i2]*C(spot[i][0]-spot[i2][0]+spot[i][1]-spot[i2][1],spot[i][1]-spot[i2][1]))%MOD
        dp[i]=(C(spot[i][0]-1+spot[i][1]-1,spot[i][1]-1)-cost+MOD)%MOD
ans=C(h-1+w-1,h-1)%MOD
for i in range(n):
    ans=(ans-dp[i]*C(h-spot[i][0]+w-spot[i][1],w-spot[i][1]))%MOD
print(ans)


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    s = [1 if c=='a' else 0 for c in S()]
    l = len(s)
    a = [0] * l
    b = [0] * l
    if s[0] == 1:
        a[0] = 1
    else:
        b[0] = 1
    for i in range(1,l):
        if s[i] == 1:
            a[i] = a[i-1] + 1
            b[i] = b[i-1]
        else:
            a[i] = a[i-1]
            b[i] = b[i-1] + 1

    if b[-1] == 0:
        return l

    r = 0
    for i in range(0,l):
        if s[i] == 1:
            continue
        for j in range(i,l):
            if s[j] == 1:
                continue
            tr = a[i] + b[j] - b[i] + 1 + a[-1] - a[j]
            if r < tr:
                r = tr

    return r

print(main())


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    s = [1 if c=='a' else 0 for c in S()]
    l = len(s)
    a = [0] * l
    b = [0] * l
    if s[0] == 1:
        a[0] = 1
    else:
        b[0] = 1
    if b[-1] == 0:
        return l
    for i in range(1,l):
        if s[i] == 1:
            a[i] = a[i-1] + 1
            b[i] = b[i-1]
        else:
            a[i] = a[i-1]
            b[i] = b[i-1] + 1

    r = 0
    for i in range(0,l):
        if s[i] == 1:
            continue
        for j in range(i,l):
            if s[j] == 1:
                continue
            tr = a[i] + b[j] - b[i] + 1 + a[-1] - a[j]
            if r < tr:
                r = tr

    return r

print(main())


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    s = [1 if c=='a' else 0 for c in S()]
    l = len(s)
    a = [0] * l
    b = [0] * l
    if s[0] == 1:
        a[0] = 1
    else:
        b[0] = 1
    for i in range(1,l):
        if s[i] == 1:
            a[i] = a[i-1] + 1
            b[i] = b[i-1]
        else:
            a[i] = a[i-1]
            b[i] = b[i-1] + 1

    r = 0
    for i in range(0,l):
        if s[i] == 1:
            continue
        for j in range(i,l):
            if s[j] == 1:
                continue
            tr = a[i] + b[j] - b[i] + 1 + a[-1] - a[j]
            if r < tr:
                r = tr

    return r

print(main())


s = [i for i in input()]
n = len(s)

if "b" not in s:
    print(n)
else:
    a = [0]*n
    b = [0]*n
    act = s.count("a")

    if s[0] == "a":
        a[0] += 1
    else:
        b[0] += 1

    for i in range(1, n):
        a[i] = a[i-1]
        b[i] = b[i-1]

        if s[i] == "a":
            a[i] += 1
        else:
            b[i] += 1

    ct = 0
    for i in range(n):
        if s[i] == "b":
            tct = a[i]

            for j in range(i, n):
                if s[j] == "b":
                    tct = max(tct, a[i]+(1+b[j]-b[i])+(act-a[j]))

            ct = max(ct, tct)

    print(ct)


s = [i for i in input()]
n = len(s)

if "b" not in s:
    print(n)
else:
    l, r = 0, n-1
    ct = 0

    for i in range(n):
        if s[i] == "b":
            l = i
            break

    for i in range(n):
        if s[i] == "b":
            ct += 1
            r = i

    print(ct+l+(n-r-1))


s = [i for i in input()]
n = len(s)

if "b" not in s:
    print(n)
else:
    a = [0]*n
    b = [0]*n
    act = s.count("a")

    if s[0] == "a":
        a[0] += 1
    else:
        b[0] += 1

    for i in range(1, n):
        a[i] = a[i-1]
        b[i] = b[i-1]

        if s[i] == "a":
            a[i] += 1
        else:
            b[i] += 1

    ct = 0
    for i in range(n):
        if s[i] == "b":
            for j in range(i, n):
                if s[j] == "b":
                    ct = max(ct, a[i]+(1+b[j]-b[i])+(act-a[j]))

    print(ct)


s = input()
n = len(s)
m = 0
i = 0

while i < n:
    act = 0
    bct = 0
    sact = 0
    j = i

    if s[i] == "a":
        fb = False
        while j < n:
            if s[j] == "b":
                fb = True
                break
            act += 1
            j += 1

        if fb:
            faa = False
            while j < n:
                if s[j] == "a":
                    faa = True
                    break
                bct += 1
                j += 1

            if faa:
                while j < n:
                    if s[j] == "b":
                        m = max(m, act+bct+sact)
                        break
                    sact += 1
                    j += 1

    else:
        faa = False
        while j < n:
            if s[j] == "a":
                faa = True
                break
            bct += 1
            j += 1

        if faa:
            while j < n:
                if s[j] == "b":
                    m = max(m, act+bct+sact)
                    break
                sact += 1
                j += 1

    i += act+bct
    m = max(m, act+bct+sact)

print(m)


s = input()
le = len(s)
mx = 0
a = s.count('a')
b = s.count('b')
mx = max(mx, a)
mx = max(mx, b)
cnta = [0]*(le+1)
cntb = [0]*(le+1)
cnta[0] = 1 if s[0]=='a' else 0
cntb[0] = 1-cnta[0]

for i in range(1,le):
	cnta[i] = cnta[i-1]
	cntb[i] = cntb[i-1]
	if s[i] == 'a':
		cnta[i] += 1
	else:
		cntb[i] += 1

for i in range(le):
	for j in range(i+1, le):
		mx = max(mx, cnta[i]+b-cntb[i])
		mx = max(mx, cntb[i]+a-cnta[i])
		mx = max(mx, cnta[i]+cntb[j]-cntb[i]+a-cnta[j])

print(mx)


s = input()
a_count = s.count('a')
b_count = len(s) - a_count
a_counts = [0] * len(s)
b_counts = [0] * len(s)
for i in range(len(s)):
  if s[i] == 'a':
    a_counts[i] = 1
  else:
    b_counts[i] = 1
  if i > 0:
    a_counts[i] += a_counts[i - 1]
    b_counts[i] += b_counts[i - 1]

best = 0
count = 0
for i in range(-1, len(s)):
  for j in range(i + 1, len(s)):
    count = 0
    if i >= 0:
      count += a_counts[i]
    count += max(0, b_counts[j] - (0 if i < 0 else b_counts[i]))
    count += max(0, a_count - a_counts[j])
    if best < count:
      best = count

print(best)


s = input()
a_count = s.count('a')
b_count = len(s) - a_count
a_counts = [0] * len(s)
b_counts = [0] * len(s)
for i in range(len(s)):
  if s[i] == 'a':
    a_counts[i] = 1
  else:
    b_counts[i] = 1
  if i > 0:
    a_counts[i] += a_counts[i - 1]
    b_counts[i] += b_counts[i - 1]

best = 0
count = 0
for i in range(-1, len(s)):
  for j in range(i + 1, len(s) + 1):
    print('i=', i, 'j=', j)
    count = 0
    if i >= 0:
      count += a_counts[i]
    count += (b_count if j == len(s) else b_counts[j]) - (0 if i < 0 else b_counts[i])
    count += 0 if j == len(s) else (a_count - a_counts[j])
    if best < count:
      best = count

print(best)


s = input()
a_count = s.count('a')
b_count = len(s) - a_count
a_counts = [0] * len(s)
b_counts = [0] * len(s)
for i in range(len(s)):
  if s[i] == 'a':
    a_counts[i] = 1
  else:
    b_counts[i] = 1
  if i > 0:
    a_counts[i] += a_counts[i - 1]
    b_counts[i] += b_counts[i - 1]

best = 0
count = 0
for i in range(-1, len(s)):
  for j in range(i + 1, len(s) + 1):
    count = 0
    if i >= 0:
      count += a_counts[i]
    count += (b_count if j == len(s) else b_counts[j]) - (0 if i < 0 else b_counts[i])
    count += 0 if j == len(s) else (a_count - a_counts[j])
    if best < count:
      best = count

print(best)


s = input()
n = len(s)

dp = [[10 ** 9 for j in range(4)] for i in range(n + 1)]
dp[0][0] = 0

for i in range(n + 1):
	for j in range(3):
		if i < n:
			add = 0
			if (s[i] == 'a' and j == 1) or (s[i] == 'b' and j != 1):
				add += 1
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + add)
		dp[i][j + 1] = min(dp[i][j + 1], dp[i][j])

print(n - dp[n][3])


s = input()
n = len(s)

dp = [[10 ** 9 for j in range(4)] for i in range(n + 1)]
dp[0][0] = 0

for i in range(n + 1):
	for j in range(3):
		cnt = 0
		for k in range(i, n + 1):
			dp[k][j + 1] = min(dp[k][j + 1], dp[i][j] + cnt)
			if k < n and ((j == 1 and s[k] == 'a') or (j != 1 and s[k] == 'b')):
				cnt += 1

print(n - dp[n][3])


s = input()
n = len(s)

dp = [[10 ** 9 for j in range(4)] for i in range(n + 1)]
dp[0][0] = 0

for i in range(n + 1):
	for j in range(3):
		cnt = 0
		for k in range(i, n + 1):
			dp[k][j + 1] = min(dp[k][j + 1], dp[i][j] + cnt)
			if k < n and ((j == 1 and s[k] == 'a') or (j != 1 and s[k] == 'b')):
				cnt += 1

print(dp[n][3])


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

using namespace std;

int a[10];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		string s;
		scanf("%d",&n);
		cin>>s;
		int k=0;
		for(int i=0;i<n;i++){
			if(k==2) break;
			if((s[i]-'0')%2==1){
				a[k]=s[i]-'0';
				k++;
			}
		}
		if(k==2)
			printf("%d%d\n",a[0],a[1]);
		else
			printf("-1\n");
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int a[100];
int main()
{
	int t;
	cin>>t;
	while(t--){
		int n;
		string s;
		cin>>n>>s;
		int k=0;
		for(int i=0;i<n;i++){
			if((s[i]-'0')&1){
				a[k]=s[i]-'0';
				k++;
			}
			if(k==2) break;
		}
		if(k==2) cout<<a[0]<<a[1]<<endl;
		else cout<<-1<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>

using namespace std;

vector<int> ve;
typedef long long ll;
int main()
{
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int flag=0;
		for(int i=n-1;i>=0;i--){
			if((s[i]-'0')%2==0&&!flag){
				continue;
			}
			else{
				ve.push_back((s[i]-'0'));
				flag=1;
			}
		}
		ll sum=0;
		for(int i=0;i<ve.size();i++){
			sum+=ve[i];
		}
		for(int i=0;i<ve.size();i++){
			if(sum%2==0) break;
			else{
				if(ve[i]%2==1){
					vector<int>::iterator it =find(ve.begin(),ve.end(),ve[i]);
					it=ve.erase(it);
				}
				break;
			}
		}
		if(ve.size()==0) cout<<-1;
//		int tag=0;
		else{
			for(int i=ve.size()-1;i>=0;i--){
//				if(ve[i]==0&&!tag&&ve[i-1]!=0){
//					tag=1;
//					continue;
//				}
				cout<<ve[i];
			}
		}
		cout<<endl;
		ve.clear();
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	int p;
	cin>>p;
	cin>>s;
	int temp=0,c=0;
	int tempev=0;
	bool l=true;
	for(int i=0;i<s.size();i++)
	{
		if((s[i]-48)%2==1)
		{c++;

		if(l)
		{
			l=false;
			temp=i;
		}
		else
		tempev=i;

	}

	}
	if(c<2)
	cout<<-1<<endl;
    else if(c%2==0&& (s[s.size()-1]-48)%2==1)
		cout<<s<<endl;
	else if(c%2==1&&(s[s.size()-1]-48)%2==1)
	{

		for(int i=0;i<s.size();i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<endl;
	}

	else if(c%2==1&&(s[s.size()-1]-48)%2==0)
	{

		for(int i=0;i<=tempev;i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<endl;
}
		else
		{	for(int i=0;i<=tempev;i++)
	{

		cout<<s[i];
	}
	cout<<endl;
	}
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	int p;
	cin>>p;
	cin>>s;
	int temp=0,c=0;
	int tempev=0;
	bool l=true;
	long long sum=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]-48>0&&(s[i]-48)%2==1)
		{c++;
		if(sum==0)
		{sum=sum+s[i]-48;}
		if(l)
		{
			l=false;
			temp=i;
		}
		else
		tempev=i;

	}

	}
	if(c%2==0&& (s[s.size()-1]-48)%2==1)
		cout<<s<<endl;
	 else if(c<2)
	cout<<-1<<endl;
	else if(c%2==1&&(s[s.size()-1]-48)%2==1)
	{

		for(int i=0;i<s.size();i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<endl;
	}

	else

	{

		for(int i=0;i<s.size()-1;i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<s[tempev]<<endl;
}}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	int p;
	cin>>p;
	cin>>s;
	int temp=0,c=0;
	int tempev=0;
	bool l=true;
	long long sum=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]-48>0&&(s[i]-48)%2==1)
		{c++;
		if(sum==0)
		{sum=sum+s[i]-48;}
		if(l)
		{
			l=false;
			temp=i;
		}

		}
		else
		tempev=i;

	}
	if(c%2==0&& (s[s.size()-1]-48)%2==1)
		cout<<s<<endl;
	 else if(c<2)
	cout<<-1<<endl;
	else if(c%2==1&&(s[s.size()-1]-48)%2==1)
	{

		for(int i=0;i<s.size();i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<endl;
	}

	else

	{

		for(int i=0;i<s.size()-1;i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<s[temp]<<endl;
}}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	int p;
	cin>>p;
	cin>>s;
	int temp=0,c=0;
	bool l=true;
	long long sum=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]-48>0&&(s[i]-48)%2==1)
		{c++;
		if(sum==0)
		{sum=sum+s[i]-48;}
		if(l)
		{
			l=false;
			temp=i;
		}
		}
	}
	if(c%2==1)
	{
		for(int i=0;i<s.size();i++)
	{	if(temp!=i)
		cout<<s[i];
	}
	cout<<endl;
	}
	else if(sum==0)
	cout<<-1<<endl;
	else
	cout<<s<<endl;}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	int p;
	cin>>p;
	cin>>s;
	int temp=0,c=0;
	int tempev=0;
	bool l=true;
	for(int i=0;i<s.size();i++)
	{
		if((s[i]-48)%2==1)
		{c++;
         tempev=i;
		if(l)
		{
			l=false;
			temp=i;
		}

	}

	}
	if(c<2)
	cout<<-1<<endl;
    else if(c%2==0&& (s[s.size()-1]-48)%2==1)
		cout<<s<<endl;
	else
	cout<<s[temp]<<s[tempev]<<endl;;
	}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	int p;
	cin>>p;
	cin>>s;
	int temp=0,c=0;
	int tempev=0;
	bool l=true;
	long long sum=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]-48>0&&(s[i]-48)%2==1)
		{c++;
		if(sum==0)
		{sum=sum+s[i]-48;}
		if(l)
		{
			l=false;
			temp=i;
		}
		else
		tempev=i;

	}

	}
	if(c<2)
	cout<<-1<<endl;
    else if(c%2==0&& (s[s.size()-1]-48)%2==1)
		cout<<s<<endl;
	else if(c%2==1&&(s[s.size()-1]-48)%2==1)
	{

		for(int i=0;i<s.size();i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<endl;
	}

	else if(c%2==1&&(s[s.size()-1]-48)%2==0)
	{

		for(int i=0;i<s.size()-1;i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<s[tempev]<<endl;
}
		else
		{	for(int i=0;i<s.size();i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<s[temp]<<endl;
	}
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	int p;
	cin>>p;
	cin>>s;
	int temp=0,c=0;
	int tempev=0;
	bool l=true;
	long long sum=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]-48>0&&(s[i]-48)%2==1)
		{c++;
		if(sum==0)
		{sum=sum+s[i]-48;}
		if(l)
		{
			l=false;
			temp=i;
		}

		}
		else
		tempev=i;

	}
	if(c%2==0&& (s[s.size()-1]-48)%2==1)
		cout<<s<<endl;
	 else if(c<2)
	cout<<-1<<endl;
	else if(c%2==1&&(s[s.size()-1]-48)%2==1)
	{

		for(int i=0;i<s.size();i++)
	{	if((s.size()-1)%2)
		if(temp!=i)
		cout<<s[i];
	}
	cout<<endl;
	}

	else

	{

		for(int i=0;i<s.size()-1;i++)
	{	if((s.size()-1)%2)
		if(temp!=i)
		cout<<s[i];
	}
	cout<<s[temp]<<endl;
}}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	int p;
	cin>>p;
	cin>>s;
	int temp=0,c=0;
	int tempev=0;
	bool l=true;
	long long sum=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]-48>0&&(s[i]-48)%2==1)
		{c++;
		if(sum==0)
		{sum=sum+s[i]-48;}
		if(l)
		{
			l=false;
			temp=i;
		}

		}

	}
	if(c%2==0&& (s[s.size()-1]-48)%2==1)
		cout<<s<<endl;
	 else if(c<2)
	cout<<-1<<endl;
	else if(c%2==1&&(s[s.size()-1]-48)%2==1)
	{

		for(int i=0;i<s.size();i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<endl;
	}

	else

	{

		for(int i=0;i<s.size()-1;i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<s[temp]<<endl;
}}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	int p;
	cin>>p;
	cin>>s;
	int temp=0,c=0;
	int tempev=0;
	bool l=true;
	long long sum=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]-48>0&&(s[i]-48)%2==1)
		{c++;
		if(sum==0)
		{sum=sum+s[i]-48;}
		if(l)
		{
			l=false;
			temp=i;
		}

		}
		else
		tempev=i;

	}
	if(c%2==0&& (s[s.size()-1]-48)%2==1)
		cout<<s<<endl;
	 else if(c<2)
	cout<<-1<<endl;
	else if(c%2==1&&(s[s.size()-1]-48)%2==1)
	{

		for(int i=0;i<s.size();i++)
	{	if((s.size()-1)%2)
		if(temp!=i)
		cout<<s[i];
	}
	cout<<endl;
	}

	else

	{

		for(int i=0;i<s.size()-1;i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<s[temp]<<endl;
}}

	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	string s;
	int p;
	cin>>p;
	cin>>s;
	int temp=0,c=0;
	int tempev=0;
	bool l=true;
	for(int i=0;i<s.size();i++)
	{
		if((s[i]-48)%2==1)
		{c++;
         tempev=i;
		if(l)
		{
			l=false;
			temp=i;
		}

	}

	}
	if(c<2)
	cout<<-1<<endl;
    else if(c%2==0&& (s[s.size()-1]-48)%2==1)
		cout<<s<<endl;
	else if(c%2==1&&(s[s.size()-1]-48)%2==1)
	{

		for(int i=0;i<=tempev;i++)
	{
		if(temp!=i)
		cout<<s[i];
	}
	cout<<endl;
	}

	else if(c%2==1&&(s[s.size()-1]-48)%2==0)
	{

		for(int i=0;i<=tempev;i++)
	{	if(temp!=i)

		cout<<s[i];
	}
	cout<<endl;
}
		else
		{	for(int i=0;i<=tempev;i++)
	{

		cout<<s[i];
	}
	cout<<endl;
	}
	}
	return 0;
}


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

int n,m,k,T,a[MAXN],ans;

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d %d %d",&n,&m,&k);ans=0;
		for (int i=1;i<=n;i++) scanf("%d",&a[i]);
		if (k>=m-1)
		{
			for (int i=1;i<=m;i++) ans=max(ans,a[i]);
			for (int i=n-m+1;i<=n;i++) ans=max(ans,a[i]);
		}
		else
		{
			for (int i=0;i<=k;i++)
			{
				int t=~(1<<31),l=i,r=k-i;
				for (int j=0;j<=m-k-1;j++)
				{
					int x=j,y=m-k-x-1;
					t=min(t,max(a[l+x+1],a[n-r-y]));
				}
				ans=max(ans,t);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


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

int n,T;
char s[MAXN];

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);
		scanf("%s",s);
		int pt=n-1,ans=0;
		while (!(s[pt]&1)&&pt>=0) --pt;++pt;
		for (int i=0;i<pt;i++) ans+=s[i]-'0';
		if (ans&1)
		{
			int del=-1,cnt=0;
			for (int i=0;i<pt&&del==-1;i++) if (s[i]&1) del=i;
			for (int i=0;i<pt;i++) if (i!=del) ++cnt;
			if (cnt&&del!=-1)
			{
				for (int i=0;i<pt;i++)
					if (i!=del) putchar(s[i]);
			}
			else printf("-1");
		}
		else
		{
			int cnt=0;
			for (int i=0;i<pt;i++) ++cnt;
			if (!cnt) printf("-1");
			else
			{
				for (int i=0;i<pt;i++) putchar(s[i]);
			}
		}
		putchar('\n');
	}
	return 0;
}


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

int n,T;
char s[MAXN],a[MAXN];

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);scanf("%s",s);
		int pt=n-1,ans=0;
		while (pt>=0&&!(s[pt]&1)) --pt;++pt;
		for (int i=0;i<pt;i++) ans+=s[i]-'0';
		if (ans&1)
		{
			int del=-1,cnt=0,p=0;
			for (int i=0;i<pt&&del==-1;i++) if (s[i]&1) del=i;
			for (int i=0;i<pt;i++) if (i!=del) a[p++]=s[i];
			a[p]='\0';
			if (cnt&&del!=-1)
			{
				if (a[p-1]&1) printf("%s",a);
				else printf("-1");
			}
			else printf("-1");
		}
		else
		{
			int cnt=0;
			for (int i=0;i<pt;i++) ++cnt;
			if (!cnt||!(s[pt-1]&1)) printf("-1");
			else
			{
				for (int i=0;i<pt;i++) putchar(s[i]);
			}
		}
		putchar('\n');
	}
	return 0;
}


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

int n,T;
char s[MAXN];

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);
		scanf("%s",s);
		int pt=n-1,ans=0;
		while (!(s[pt]&1)) --pt;++pt;
		for (int i=0;i<pt;i++) ans+=s[i]-'0';
		if (ans&1)
		{
			int del=-1,cnt=0;
			for (int i=0;i<pt&&del==-1;i++) if (s[i]&1) del=i;
			for (int i=0;i<pt;i++) if (i!=del) ++cnt;
			if (cnt&&del!=-1)
			{
				for (int i=0;i<pt;i++)
					if (i!=del) putchar(s[i]);
			}
			else printf("-1");
		}
		else
		{
			int cnt=0;
			for (int i=0;i<pt;i++) ++cnt;
			if (!cnt) printf("-1");
			else
			{
				for (int i=0;i<pt;i++) putchar(s[i]);
			}
		}
		putchar('\n');
	}
	return 0;
}


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

int n,T;
char s[MAXN],a[MAXN];

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);scanf("%s",s);
		int pt=n-1,ans=0;
		while (pt>=0&&!(s[pt]&1)) --pt;++pt;
		for (int i=0;i<pt;i++) ans+=s[i]-'0';
		if (ans&1)
		{
			int del=-1,p=0;
			for (int i=0;i<pt&&del==-1;i++) if (s[i]&1) del=i;
			for (int i=0;i<pt;i++) if (i!=del) a[p++]=s[i];
			a[p]='\0';
			if (p&&del!=-1)
			{
				if (a[p-1]&1) printf("%s",a);
				else printf("-1");
			}
			else printf("-1");
		}
		else
		{
			int cnt=0;
			for (int i=0;i<pt;i++) ++cnt;
			if (!cnt||!(s[pt-1]&1)) printf("-1");
			else
			{
				for (int i=0;i<pt;i++) putchar(s[i]);
			}
		}
		putchar('\n');
	}
	return 0;
}


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

int n,T;
char s[MAXN],a[MAXN];

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);scanf("%s",s);int cnt=0;
		for (int i=0;i<n;i++) cnt+=(s[i]&1);
		if (cnt<2) puts("-1");
		else
		{
			int o=0;
			for (int i=0;i<n;i++)
				if (s[i]&1)
				{
					putchar(s[i]);++o;
					if (o==2) break;
				}
			putchar('\n');
		}
	}
	return 0;
}


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

int n,T;
char s[MAXN];

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);
		scanf("%s",s);
		int pt=n-1,ans=0;
		while (!(s[pt]&1)) --pt;++pt;
		for (int i=0;i<pt;i++) ans+=s[i]-'0';
		if (ans&1)
		{
			int del=0,cnt=0;
			for (int i=0;i<pt;i++)
				if (s[i]&1) del=i;
			for (int i=0;i<pt;i++)
				if (i!=del) ++cnt;
			if (cnt)
			{
				for (int i=0;i<pt;i++)
					if (i!=del) putchar(s[i]);
			}
			else printf("-1");
		}
		else
		{
			int cnt=0;
			for (int i=0;i<pt;i++) ++cnt;
			if (!cnt) printf("-1");
			else
			{
				for (int i=0;i<pt;i++) putchar(s[i]);
			}
		}
		putchar('\n');
	}
	return 0;
}


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

int n,T;
char s[MAXN],a[MAXN];

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);scanf("%s",s);
		int pt=n-1,ans=0;
		while (pt>=0&&!(s[pt]&1)) --pt;++pt;
		for (int i=0;i<pt;i++) ans+=s[i]-'0';
		if (ans&1)
		{
			int del=-1,p=0;
			for (int i=pt-1;i>=0&&del==-1;i++) if (s[i]&1) del=i;
			for (int i=0;i<pt;i++) if (i!=del) a[p++]=s[i];
			a[p]='\0';
			if (p&&del!=-1)
			{
				if (a[p-1]&1) printf("%s",a);
				else printf("-1");
			}
			else printf("-1");
		}
		else
		{
			int cnt=0;
			for (int i=0;i<pt;i++) ++cnt;
			if (!cnt||!(s[pt-1]&1)) printf("-1");
			else
			{
				for (int i=0;i<pt;i++) putchar(s[i]);
			}
		}
		putchar('\n');
	}
	return 0;
}


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

int n,T;
char s[MAXN];

int main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);
		scanf("%s",s);
		int pt=n-1,ans=0;
		while (!(s[pt]&1)) --pt;++pt;
		for (int i=0;i<pt;i++) ans+=s[i]-'0';
		if (ans&1)
		{
			int del=-1,cnt=0;
			for (int i=0;i<pt&&del==-1;i++) if (s[i]&1) del=i;
			for (int i=0;i<pt;i++) if (i!=del) ++cnt;
			if (cnt)
			{
				for (int i=0;i<pt;i++)
					if (i!=del) putchar(s[i]);
			}
			else printf("-1");
		}
		else
		{
			int cnt=0;
			for (int i=0;i<pt;i++) ++cnt;
			if (!cnt) printf("-1");
			else
			{
				for (int i=0;i<pt;i++) putchar(s[i]);
			}
		}
		putchar('\n');
	}
	return 0;
}


#include <bits/stdc++.h>

#define ll long long

#define endl '\n'

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        ll sum=0;
        for(int i=0; i<n; ++i)
        {
            sum+=(s[i]-'0');
        }
        if(n==1&&s[0]==0)
        {
            cout<<-1<<endl;
        }
        else
        {
            while((s[s.size()-1]-'0')%2==0&&s.size()>0)
            {
                s.erase(s.size()-1,1);
            }
            if(sum%2!=0)
            {
                bool f=0;
                for(int i=0;i<n;++i)
                {
                    if((s[i]-'0')%2!=0){s.erase(i,1);f=1;break;}
                }
                while(s[0]=='0'&&s.size()>0)
                {
                    s.erase(0,1);
                }
                f=(s.size()>0);
                if(!f){cout<<-1<<endl;}
                else {cout<<s<<endl;}
            }
            else
            {
                bool f1=0;
                while(s[0]=='0'&&s.size()>0)
                {
                    s.erase(0,1);
                }
                f1=(s.size()>0);
                if(!f1){cout<<-1<<endl;}
                else {cout<<s<<endl;}
            }
        }
    }
}


#include <bits/stdc++.h>

#define ll long long

#define endl '\n'

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        ll sum=0;
        for(int i=0; i<n; ++i)
        {
            sum+=(s[i]-'0');
        }
        if(n==1&&s[0]=='0')
        {
            cout<<-1<<endl;
        }
        else
        {
            int j=n-1;
            while((s[j]-'0')%2==0&&j>=0)
            {
                s.erase(j,1);
                j--;
            }
            if(sum%2!=0)
            {
                bool f=0;
                for(int i=0;i<n;++i)
                {
                    if((s[i]-'0')%2!=0){s.erase(i,1);f=1;break;}
                }
                while(s[0]=='0'&&s.size()>0)
                {
                    s.erase(0,1);
                }
                f=(s.size()>0);
                if(!f){cout<<-1<<endl;}
                else {cout<<s<<endl;}
            }
            else
            {
                bool f1=0;
                while(s[0]=='0'&&s.size()>=0)
                {
                    s.erase(0,1);
                }
                f1=(s.size()>0);
                if(!f1){cout<<-1<<endl;}
                else {cout<<s<<endl;}
            }
        }
    }
}


#include <bits/stdc++.h>

#define ll long long

#define endl '\n'

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        ll sum=0;
        for(int i=0; i<n; ++i)
        {
            sum+=(s[i]-'0');
        }
        if(n==1&&s[0]=='0')
        {
            cout<<-1<<endl;
        }
        else
        {
            int j=n-1;
            while((s[j]-'0')%2==0)
            {
                s.erase(j,1);
                j--;
            }
            if(sum%2!=0)
            {
                bool f=0;
                for(int i=0;i<n;++i)
                {
                    if((s[i]-'0')%2!=0){s.erase(i,1);f=1;break;}
                }
                while(s[0]=='0'&&s.size()>0)
                {
                    s.erase(0,1);
                }
                f=(s.size()>0);
                if(!f){cout<<-1<<endl;}
                else {cout<<s<<endl;}
            }
            else
            {
                bool f1=0;
                while(s[0]=='0'&&s.size()>0)
                {
                    s.erase(0,1);
                }
                f1=(s.size()>0);
                if(!f1){cout<<-1<<endl;}
                else {cout<<s<<endl;}
            }
        }
    }
}