import Control.Applicative
import Control.Monad
import Data.List

solve :: String -> Int
solve ss = foldr f 0 (zip ss (cycle "gp"))
  where
    f (s, t) a
        | (s, t) == ('g', 'p') = a + 1
        | (s, t) == ('p', 'g') = a - 1
        | otherwise            = a

main = do
    ss <- getLine
    print $ solve ss