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.util.*;
import java.io.*;
 
public class File {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int N = s.length();
        // How many removals to make subsequence
        // all a's or all b's.
        int[] allA = new int[N];
        int[] allB = new int[N];

        if (s.charAt(0) == 'a') {
            allB[0] = 1;
        }
        if (s.charAt(0) == 'b') {
            allA[0] = 1;
        }

        for (int i = 1; i < N; i++) {
            allA[i] = allA[i-1];
            allB[i] = allB[i-1];

            if (s.charAt(i) == 'a') {
                allB[i]++;
            }
            else {
                allA[i]++;
            }
        }

        // Any string of length 2 is valid.
        // We have all a's or all b's in the string.
        if (N <= 2 || allA[N-1] == 0 || allB[N-1] == 0) {
            System.out.println(N);
            return;            
        }
        
        // First, see best to make it all a's or all b's
        int minRemove = Math.min(allA[N-1], allB[N-1]);

        // O(N^2)
        // Try all start indices, and end indices.
        // Answer is N - removals of the sections, needed

        // [start, end] is range of indices for middle part.
        for (int start = 0; start < N; start++) {
            for (int end = start; end < N; end++) {
                int movesLeftA = start > 0 ? allA[start-1] : 0;
                int movesMiddleB = allB[end] - (start > 0 ? allB[start-1] : 0);
                int movesRightA = end + 1 < N ? allA[N-1] - allA[end] : 0;

                minRemove = Math.min(minRemove, movesLeftA + movesMiddleB + movesRightA);
            }
        }

        System.out.println(N - minRemove);
    }
}