PROGRAM ATCODER

implicit none
character(len=10**5) :: s
integer :: count=0, i

read(*,*) s

do i = 1, len_trim(s)
  if(s(i:i) == 'g')then
    count = count + 1
  end if
end do

if (count > len_trim(s)/2) then
  count = len_trim(s) - count
end if

write(*,'(i0)') len_trim(s)/2-count

contains
!!!!!! サブルーチンは↓

!!!!!!

END PROGRAM ATCODER