import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); char[] arr = sc.next().toCharArray(); int current = 0; int max = 0; HashMap places = new HashMap<>(); places.put(0, -1); for (int i = 0; i < arr.length; i++) { if (arr[i] == 'A') { current++; } else { current--; } if (places.containsKey(current)) { max = Math.max(max, i - places.get(current)); } else { places.put(current, i); } } System.out.println(max); } }