# coding: utf-8 # Your code here! s = input() s_size = len(s) def count(k): if k==s_size: print(0) return start = 0 end = s_size-k for b in range(k+1): count_a = s[start:end].count("A") if count_a == s_size-k-count_a: print(count_a*2) return start+=1 end+=1 count(k+1) count(0)