inp=list(input()) n=len(inp) for i in range(n): inp[i]=inp[i]=="A" sl=int(n/2)*2 s=0 while True: st=inp[s:s+sl] if sum(st)==(sl/2): break s+=1 if (s+sl)>n: sl-=2 s=0 print(sl)