Scanf.scanf "%s" (fun s ->
    let n = String.length s in

    let rec loop i acc =
        if i = n then acc / 2 else
            if s.[i] = 'g' then loop (i + 1) (acc + 1)
                           else loop (i + 1) (acc - 1)
    in
    loop 0 0 |> Printf.printf "%d\n"
)