import itertools S=input() L = len(S) AB = [-1]*L for i in range(L): if S[i]=='A': AB[i] = 1 ACC = [0] + list(itertools.accumulate(AB)) ans = 0 for i in range(L+1): for j in range(i+ans,L+1): if(ACC[i]==ACC[j] and ans < j-i): ans = j-i print(ans)