#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <algorithm> 
using namespace std;
string a;
int main()
{
    cin>>a;
    int x=0,y=0,ans=0;
    for(int i=0;i<a.length();++i)
    {
        if(x==y)
        {
            x++;
            if(a[i]=='p')
            ans--;
        }
        else 
        {
            y++;
            if(a[i]=='g')
            ans++;
        }
        
    }
    printf("%d\n",ans);
    return 0;
}