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

solve :: String -> Int -> Int
solve "" _ = 0
solve (c:cs) n
  | c == 'g' && n == 0 = solve cs (n+1)
  | c == 'g'           = 1 + solve cs (n-1)
  | c == 'p' && n == 0 = -1 + solve cs (n+1)
  | otherwise          = solve cs (n-1)
