import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
    s <- C.getLine
    print $ snd $ C.foldl (\(c,ac) w -> f c ac w) (0,0) s

f 0 ac 'g' = (1,    ac)
f c ac 'g' = (c-1,  ac+1)
f 0 ac 'p' = (1,    ac-1)
f c ac 'p' = (c-1,  ac)