#include<bits/stdc++.h>
using namespace std;
char s[10005];
int len,i,j,score=0,rock=0,paper=0,a[10005];
int main()
{gets(s);
len=strlen(s);
 for(i=0;i<len;i++)
   if(s[i]=='g') a[i+1]=0;//0->rock
   else if(s[i]=='p') a[i+1]=1;//1->paper
 /*for(i=1;i<=len;i++)
   cout<<a[i]<<' ';
   cout<<endl;*/
 rock++;
 if(a[1]==1) score--; 
 for(i=2;i<=len;i++)
  if(a[i]==0) {
  if(paper<rock) {paper++; score++;}
  else {rock++; }}
  else {
  if(paper<rock) {paper++;}
  else{rock++; score--;}
  }
 cout<<score; 
 return 0;
}