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

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

Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?

Input

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

Output

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

Examples

Input

abba


Output

4

Input

bab


Output

2

Note

It the first sample the string is already beautiful.

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

Solution (in JAVA):

Solution:


import java.io.*;
import java.math.*;
import java.util.*;


// @author : Dinosparton 

public class test {
	 
	   static class Pair{ 
		   long x;
		   long y;
		   
		   Pair(long x,long y){ 
			   this.x = x;
			   this.y = y;
			   
		   }
	   }
	  
	   static class Sort implements Comparator<Pair>
	   {

	       @Override
	       public int compare(Pair a, Pair b)
	       {
	           if(a.x!=b.x)
	           {
	               return (int)(a.x - b.x);
	           }
	           else
	           {
	               return (int)(a.y-b.y);
	           }
	       }
	   }
	   
	   static class Compare { 
		   
		     void compare(Pair arr[], int n) 
		    { 
		        // Comparator to sort the pair according to second element 
		        Arrays.sort(arr, new Comparator<Pair>() { 
		            @Override public int compare(Pair p1, Pair p2) 
		            { 
		            	if(p1.x!=p2.x) {
		                return (int)(p1.x - p2.x); 
		            	}
		            	else { 
		            		return (int)(p1.y - p2.y);
		            	}
		            } 
		        }); 
		  
//		        for (int i = 0; i < n; i++) { 
//		            System.out.print(arr[i].x + " " + arr[i].y + " "); 
//		        } 
//		        System.out.println(); 
		    } 
		} 
	 
	   static class Scanner {
	        BufferedReader br;
	        StringTokenizer st;
	 
	        public Scanner()
	        {
	            br = new BufferedReader(
	                new InputStreamReader(System.in));
	        }
	 
	        String next()
	        {
	            while (st == null || !st.hasMoreElements()) {
	                try {
	                    st = new StringTokenizer(br.readLine());
	                }
	                catch (IOException e) {
	                    e.printStackTrace();
	                }
	            }
	            return st.nextToken();
	        }
	 
	        int nextInt() { return Integer.parseInt(next()); }
	 
	        long nextLong() { return Long.parseLong(next()); }
	 
	        double nextDouble()
	        {
	            return Double.parseDouble(next());
	        }
	 
	        String nextLine()
	        {
	            String str = "";
	            try {
	                str = br.readLine();
	            }
	            catch (IOException e) {
	                e.printStackTrace();
	            }
	            return str;
	        }
	    }
	
	   static int dp[][][] = new int[5001][2][3];
	   
	 static int recursion(String s , int i , char cur , int portion) { 
		 
		 if(i>s.length()-1) { 
			 return 0;
		 }
		 
		 if(dp[i][cur-'a'][portion]!=-1) { 
			 return dp[i][cur-'a'][portion];
		 }
		 
		 if(s.charAt(i)==cur) { 
			 
			 dp[i][cur-'a'][portion] = recursion(s,i+1,cur,portion);
			 return dp[i][cur-'a'][portion];
		 }
		 else { 
			 
			 if(portion==0) { 
				 dp[i][cur-'a'][portion] = Math.min(1 +recursion(s, i+1,cur,portion), recursion(s,i+1,'b',1));
				 return dp[i][cur-'a'][portion];
			 }
			 else if(portion==1) { 
				 dp[i][cur-'a'][portion] = Math.min(1 +recursion(s, i+1,cur,portion), recursion(s,i+1,'a',2));
				 return dp[i][cur-'a'][portion];
			 }
			 else { 
				 dp[i][cur-'a'][portion] = 1 + recursion(s,i+1,cur,portion);
				 return dp[i][cur-'a'][portion];
			 }
		 }
	 }
	   
	   public static void main(String args[]) throws Exception { 
		
		   
		   Scanner sc = new Scanner();
		   StringBuilder res = new StringBuilder();
		  
		   int tc = 1;
		   
		   while(tc-->0) { 
			
			   for(int i=0;i<=5000;i++) { 
				   dp[i][0][0] = -1;
				   dp[i][0][1] = -1;
				   dp[i][0][2] = -1;
				   dp[i][1][0] = -1;
				   dp[i][1][1] = -1;
				   dp[i][1][2] = -1;
			   }
			String s = sc.next();
			
			int n = s.length();
			
			System.out.println(n-recursion(s,0,'a',0));
		   }
		   
		   System.out.println(res);
	   }
}