import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe
import           Debug.Trace

main = do
  s <- BS.getLine
  let n = BS.length s
      solve score numG s | BS.length s == 0 = score
                          | otherwise
        =
        let
          c = BS.head s
          s' = BS.tail s
        in
          if      c=='g' && numG==0 then solve score (numG+1) s'
          else if c=='g'            then solve (score+1) (numG-1) s'
          else if c=='p' && numG==0 then solve (score-1) (numG+1) s'
          else                           solve score (numG-1) s'
  print $ solve 0 0 s