let array_of_string s = Array.init (String.length s) (fun i -> s.[i])

let () =
  read_line ()
  |> array_of_string
  |> Array.fold_left (fun (b, acc) c ->
      (not b, acc +
        match b, c with
        | true, 'p' -> 0
        | true, 'g' -> 1
        | false, 'p' -> -1
        | false, 'g' -> 0)) (false, 0)
  |> snd
  |> Printf.printf "%d\n"