main :: IO ()
main = do
   s <- getLine
   print $ solve s

solve :: String -> Int
solve = inner 0 0
  where
    inner x _       []  = x
    inner x 0 ('p' : s) = inner (x - 1) 1 s
    inner x p ('p' : s) = inner x (p - 1) s
    inner x 0 ('g' : s) = inner x 1 s
    inner x p ('g' : s) = inner (x + 1) (p - 1) s
