#include<iostream>
#include<cstdio>
using namespace std;
int zs,x,y;
string st;
int main()
{
	cin>>st;
	for (int i=0;i<=st.size()-1;i++)
	  if (x==y) {x++;if (st[i]=='p') zs--;} 
	    else {y++;if (st[i]=='g') zs++;}
	cout<<zs<<endl; 
	return 0;
}