import qualified Data.Map as M

main :: IO ()
main = solve <$> getLine >>= print

solve :: String -> Int
solve s = (n - m) `div` 2
    where
        n = M.findWithDefault 0 'g' count
        m = M.findWithDefault 0 'p' count
        count = foldr (\c mp -> M.insertWith (+) c 1 mp) M.empty s