import qualified Data.ByteString.Char8 as C

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

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)