import qualified Data.Map as M import qualified Control.Applicative as CA f :: (Int,Int) -> Char -> (Int,Int) f (a,p) c |c=='A' =(a+1,p+1) |otherwise=(a-1,p+1) toM1 :: (Ord k)=>[(k,Int)]->M.Map k Int toM1 xs = M.fromListWith up xs where up n1 n2=n1 toM2 :: (Ord k)=>[(k,Int)]->M.Map k Int toM2 xs = M.fromListWith up xs where up n1 n2=n2 f2 (Just x)=x f2 Nothing =0 main=do x<-getLine let ys=scanl f (0,0) x as=toM1 ys bs=toM2 ys cs=M.keys as ds=map (\x -> (M.lookup x as)) cs es=map (\x -> (M.lookup x bs)) cs fs=zip ds es ans=maximum $ fmap (\(a,b)->CA.liftA2 (-) a b) fs print $ f2 $ ans