#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"s=input()\n"
"g=p=a=0\n"
"for t in s:\n"
"  if t=='g':\n"
"    g+=1\n"
"  else:\n"
"    if p<g:\n"
"      p+=1\n"
"    else:\n"
"      g+=1\n"
"      a-=1\n"
"print(a+(g-p)//2)\n"
"\"";
  system(s);
  return 0;
}            