print(123) S=input() v={0:0} m=y=0 for i,c in enumerate(S): y+=(c>'A')*2-1 if y in v: m=max(m,i+1-v[y]) else: v[y]=i+1 print(m)