import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); int ans = function(s); System.out.println(ans); } static int function(String s) { for(int i = s.length(); i >=0; i--) { for(int j = 0; j < s.length()-i+1; j++) { String tmp = s.substring(j,i+j); if(judge(tmp)) return i; } } return 0; } static boolean judge(String s) { int A = count(s,'A'); int B = count(s,'B'); if(A == B) { return true; } else { return false; } } static int count(String s, char c) { int count = 0; for(int i = 0; i