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) { int len = s.length(); int [] num = new int [len]; if(s.charAt(0) == 'A') { num[0] = 1; } else { num[0] = -1; } for(int i = 1; i < len; i++) { if(s.charAt(i) == 'A') { num[i] = num[i-1] + 1; } else { num[i] = num[i-1] - 1; } } int max = 0; for(int i = 0; i < len; i++) { for(int j = i; j < len; j++) { if(num[j]-num[i] == 0) { max = Math.max(max,j-i); } } } return max; } }