import Control.Monad
import qualified Data.ByteString.Char8 as C

main = sol . C.filter (liftM2 (||) ('p'==) ('g'==)) <$> C.getContents >>= print

sol = liftM2 (-) ((`div` 2) . C.length) (C.count 'p')