stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

	string s;

	long long ans;

	long long cntp=0;

	long long n;

	cin>>s;

	n=s.length();

	for(int i=1;i<n;i++){

		if(s[i]=='p'){

			cntp++;

		}

	}

	if(s[0]=='p'){

		ans=n/2-cntp-1;

	}

	else {

		ans=n/2-cntp;

	}

	cout<<ans;

}


// Faster C++ solution for the same problem (measured speedup: 5.276241088961874x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char s[100002];

int n,sg,sp,ans;

int main()

{

	scanf("%s",s);

	n=strlen(s);

	sg=sp=0;

	for(int i=0;i<n;i++)

		if(i%2==1&&s[i]=='g')ans++;

		else	if(i%2==0&&s[i]=='p')ans--;

	printf("%d",ans);

	return 0;

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <iterator>

#include <cstdio>

#include <vector>

#include <cmath>

using namespace std;





#ifdef LOCAL

#define DEBUGMSG()                                                              \

{                                                                               \

    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]" ;        \

}

#define DEBUGVAR(x)                                                             \

{                                                                               \

    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]:" ;       \

    cerr << "([" << typeid(x).name() << "]" << #x << ")" << x << endl ;         \

}

#define DEBUGARR(l, r)                                                          \

{                                                                               \

    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]:" ;       \

    copy(l, r, ostream_iterator<decltype(*l)>(cerr, " "));                      \

    cerr << endl ;                                                              \

}

#else

#define DEBUGMSG()

#define DEBUGVAR(x)

#define DEBUGARR(l, r)

#endif // LOCAL



int N;

string str;



int main()

{

    int g = 0, p = 0;

    cin >> str ;



    for(string::iterator itr = str.begin(); itr != str.end(); itr++)

        if(*itr == 'p')

            p++;

        else

            g++;



    DEBUGVAR(p);

    DEBUGVAR(g);



    if(p >= g)

        cout << 0 << endl ;

    else

        cout << (g-p)/2 << endl ;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.2899556720881735x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char s[100002];

int n,sg,sp,ans;

int main()

{

	scanf("%s",s);

	n=strlen(s);

	sg=sp=0;

	for(int i=0;i<n;i++)

		if(i%2==1&&s[i]=='g')ans++;

		else	if(i%2==0&&s[i]=='p')ans--;

	printf("%d",ans);

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<string>

#include<iostream>

using namespace std;



typedef long long ll;



int n;

string s;



int main(){

    cin >> s;

    n=s.length();

    int t=0,cnt=n/2;

    for(int i=0;i<n;i++)

        if(s[i]=='p') t++;

    cnt-=t;

    printf("%d",cnt);

}


// Faster C++ solution for the same problem (measured speedup: 5.266301629843906x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char s[100002];

int n,sg,sp,ans;

int main()

{

	scanf("%s",s);

	n=strlen(s);

	sg=sp=0;

	for(int i=0;i<n;i++)

		if(i%2==1&&s[i]=='g')ans++;

		else	if(i%2==0&&s[i]=='p')ans--;

	printf("%d",ans);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define pb push_back

typedef long long goo;

using namespace std;

int main()

{

    char ch=0;

    int p=0,g=0;

    while(ch!='\n'){

        ch=getchar();

        if(ch=='p') p++;

        if(ch=='g') g++;

    }

    cout<<(p+g)/2-p;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.229230120986408x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char s[100002];

int n,sg,sp,ans;

int main()

{

	scanf("%s",s);

	n=strlen(s);

	sg=sp=0;

	for(int i=0;i<n;i++)

		if(i%2==1&&s[i]=='g')ans++;

		else	if(i%2==0&&s[i]=='p')ans--;

	printf("%d",ans);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main()

{

   char a[110000];

   scanf("%s",&a);

   int w=strlen(a);

   w=w/2;

   int k=0;

   int kk=0;

   for(int i=0;a[i];i++)

   {

       if(a[i]=='p')

       {

           k++;

       }

       else if(a[i]=='g')

       {

           kk++;

       }

   }

if(k>=w)

{

    printf("%d\n",w-k);

}

else

{

   printf("%d\n",w-k);

}

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.254523755661737x):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std ;



#define ll long long

#define N 100010



char s[ N ] ;

int cur1 , cur2 , ans ;



//rock和paper，paper赢

//同样则不加分 

//rock-g , paper-p



int main() {

	scanf( "%s" , s + 1 ) ;

	int n = strlen( s + 1 ) ;

	if( s[ 1 ] == 'p' ) ans = -1 ;

	cur2 = 1 ;

	for( int i = 2 ; i <= n ; i ++ ) {

		if( s[ i ] == 'p' ) {

			if( cur1 < cur2 ) {

				cur1 ++ ;

			}else ans -- , cur2 ++ ;

		}else {

			if( cur1 < cur2 ) {

				cur1 ++ ;

				ans ++ ;

			}else cur2 ++ ;

		}

	}

	printf( "%d\n" , ans ) ;

	return 0 ;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

	cin>>a;

	for (int i=0;i<sizeof(a);i++)

	{

		if (x==y)//只能出石头

		{

			x++;

			if (a[i]=='p') ans--;

		} 

		else//可以出布

		{

			y++;

			if (a[i]=='g') ans++;

		} 

	}

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.24815808309866x):
#include<bits/stdc++.h>

using namespace std;

char s[100005];

int sum=0,p=0,g=0;

int main()

{

	scanf("%s", s);

	int len=strlen(s);

	for(int i=0;i<len;i++)

	{

		if(s[i]=='g')

		{

			if(g>p)

			{

				sum++;

				p++;

			}else 

		    {

			    g++;

		    }

		} 

		else 

		{

			if(g>p)

			{

				p++;

			}

			else

			{

				sum--;

				g++;

			}

		}

	}

	cout<<sum;

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

	cin>>a;

	for (int i=0;i<sizeof(a);i++)

	{

		if (x==y)//只能出石头

		{

			x++;

			if (a[i]=='p') ans--;

		} 

		else//可以出布

		{

			y++;

			if (a[i]=='g') ans++;

		} 

	}

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.239108717116515x):
#include<iostream>

using namespace std;

int main()

{

	int sumg=0;

	int sump=0;

	char a;

	int ans=0;

	while(cin>>a)

	{

		if(a=='g')

		{

			if(sump<sumg)

			{

				ans++;

				sump++;

			}

			else	sumg++;

		}

		if(a=='p')

		{

			if(sump<sumg)

				sump++;

			else

			{

				ans--;

				sumg++;

			} 

		}

		

	}

	cout<<ans;

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

	cin>>a;

	for (int i=0;i<sizeof(a);i++)

	{

		if (x==y)//只能出石头

		{

			x++;

			if (a[i]=='p') ans--;

		} 

		else//可以出布

		{

			y++;

			if (a[i]=='g') ans++;

		} 

	}

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.238530950687946x):
#include<bits/stdc++.h> 

using namespace std; 

string sss; 

int main() 

{

    int i=0,x=0,y,ans; 

    cin>>sss; 

    int qaq=sss.length(); 

    while(i<qaq) 

    { 

        if(sss[i]=='p') x++; 

        i++; 

    } 

    y=i/2; 

    ans=y-x; 

    cout<<ans;

    return 0; 

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

	cin>>a;

	for (int i=0;i<sizeof(a);i++)

	{

		if (x==y)//只能出石头

		{

			x++;

			if (a[i]=='p') ans--;

		} 

		else//可以出布

		{

			y++;

			if (a[i]=='g') ans++;

		} 

	}

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2368316247150304x):
#include<bits/stdc++.h>

using namespace std;

int ans=0,gc=0,pc=0;

string a;

int main()

{

	cin>>a;

    for (int i=0;i<a.size();i++)

	{

		if(gc==pc)

		{

			gc++;

			if(a[i]=='p') ans--;

		}

		else

		{

			pc++;

			if(a[i]=='g') ans++;

		}

	}    

    cout<<ans<<endl;

    return 0;	

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

    cin>>a;

    for (int i=0;i<sizeof(a);i++)

    {

        if (x==y)

        {

            x++;

            if (a[i]=='p') ans--;

        } 

        else

        {

            y++;

            if (a[i]=='g') ans++;

        } 

    }

    printf("%d\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2368316247150304x):
#include<bits/stdc++.h>

using namespace std;

int ans=0,gc=0,pc=0;

string a;

int main()

{

	cin>>a;

    for (int i=0;i<a.size();i++)

	{

		if(gc==pc)

		{

			gc++;

			if(a[i]=='p') ans--;

		}

		else

		{

			pc++;

			if(a[i]=='g') ans++;

		}

	}    

    cout<<ans<<endl;

    return 0;	

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

char s[100001];

int main()

{    

	scanf("%s",s+1);

	register int sum=0,l=strlen(s+1),p=0,g=0;

	for(register int i=1;i<=l;++i)

		if(s[i]=='g')

			if(g>p)

				++sum,++p;

			else

				++g;

		else

			if(g>p)

				++p;

			else

				--sum,g++;

	return printf("%d",sum),0;

} 


// Faster C++ solution for the same problem (measured speedup: 4.647625920220964x):
#include<cstdio>

#include<cstring>

int main()

{

	int x=0,y=0,m=0;

	char c[1000000];

	scanf("%s",&c);

	int n=strlen(c);

	for(int i=0;i<n;i++)

	if (x<=y)

	{

		x++;

		if (c[i]=='p')

		m--;

	}

	else

	{

		y++;

		if (c[i]=='g')

		m++;

	}

	printf("%d\n",m);

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

int sco,p,g;char s;

int main()

{

	while(cin>>s)

	{

		if(s=='p'&&p<g){p++;continue;}

		if(s=='p'&&p==g){g++;sco--;continue;}

		if(s=='g'&&p<g){p++;sco++;continue;}

		if(s=='g'&&p==g){g++;continue;}

	}

	cout<<sco;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.6971970336191635x):
#include<cstdio>

#include<cstring>

int main()

{

	int x=0,y=0,m=0;

	char c[1000000];

	scanf("%s",&c);

	int n=strlen(c);

	for(int i=0;i<n;i++)

	if (x<=y)

	{

		x++;

		if (c[i]=='p')

		m--;

	}

	else

	{

		y++;

		if (c[i]=='g')

		m++;

	}

	printf("%d\n",m);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

	cin>>a;

	for (int i=0;i<sizeof(a);i++)

	{

		if (x==y)//只能出石头

		{

			x++;

			if (a[i]=='p') ans--;

		} 

		else//可以出布

		{

			y++;

			if (a[i]=='g') ans++;

		} 

	}

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.817166864716321x):
#include<cstdio>

#include<cstring>

int main()

{

	int x=0,y=0,m=0;

	char c[1000000];

	scanf("%s",&c);

	int n=strlen(c);

	for(int i=0;i<n;i++)

	if (x<=y)

	{

		x++;

		if (c[i]=='p')

		m--;

	}

	else

	{

		y++;

		if (c[i]=='g')

		m++;

	}

	printf("%d\n",m);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

char s[100005];

int sum=0,p=0,g=0;

int main()

{

	scanf("%s", s);

	int len=strlen(s);

	for(int i=0;i<len;i++)

	{

		if(s[i]=='g')

		{

			if(g>p)

			{

				sum++;

				p++;

			}else 

		    {

			    g++;

		    }

		} 

		else 

		{

			if(g>p)

			{

				p++;

			}

			else

			{

				sum--;

				g++;

			}

		}

	}

	cout<<sum;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.660601043639202x):
#include<cstdio>

#include<cstring>

int main()

{

	int x=0,y=0,m=0;

	char c[1000000];

	scanf("%s",&c);

	int n=strlen(c);

	for(int i=0;i<n;i++)

	if (x<=y)

	{

		x++;

		if (c[i]=='p')

		m--;

	}

	else

	{

		y++;

		if (c[i]=='g')

		m++;

	}

	printf("%d\n",m);

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main()

{

	int sumg=0;

	int sump=0;

	char a;

	int ans=0;

	while(cin>>a)

	{

		if(a=='g')

		{

			if(sump<sumg)

			{

				ans++;

				sump++;

			}

			else	sumg++;

		}

		if(a=='p')

		{

			if(sump<sumg)

				sump++;

			else

			{

				ans--;

				sumg++;

			} 

		}

		

	}

	cout<<ans;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.6946379961342215x):
#include<cstdio>

#include<cstring>

int main()

{

	int x=0,y=0,m=0;

	char c[1000000];

	scanf("%s",&c);

	int n=strlen(c);

	for(int i=0;i<n;i++)

	if (x<=y)

	{

		x++;

		if (c[i]=='p')

		m--;

	}

	else

	{

		y++;

		if (c[i]=='g')

		m++;

	}

	printf("%d\n",m);

}
// Slower C++ solution:
#include<bits/stdc++.h> 

using namespace std; 

string sss; 

int main() 

{

    int i=0,x=0,y,ans; 

    cin>>sss; 

    int qaq=sss.length(); 

    while(i<qaq) 

    { 

        if(sss[i]=='p') x++; 

        i++; 

    } 

    y=i/2; 

    ans=y-x; 

    cout<<ans;

    return 0; 

} 

// Faster C++ solution for the same problem (measured speedup: 4.696828013450254x):
#include<cstdio>

#include<cstring>

int main()

{

	int x=0,y=0,m=0;

	char c[1000000];

	scanf("%s",&c);

	int n=strlen(c);

	for(int i=0;i<n;i++)

	if (x<=y)

	{

		x++;

		if (c[i]=='p')

		m--;

	}

	else

	{

		y++;

		if (c[i]=='g')

		m++;

	}

	printf("%d\n",m);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

    cin>>a;

    for (int i=0;i<sizeof(a);i++)

    {

        if (x==y)

        {

            x++;

            if (a[i]=='p') ans--;

        } 

        else

        {

            y++;

            if (a[i]=='g') ans++;

        } 

    }

    printf("%d\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.817166864716321x):
#include<cstdio>

#include<cstring>

int main()

{

	int x=0,y=0,m=0;

	char c[1000000];

	scanf("%s",&c);

	int n=strlen(c);

	for(int i=0;i<n;i++)

	if (x<=y)

	{

		x++;

		if (c[i]=='p')

		m--;

	}

	else

	{

		y++;

		if (c[i]=='g')

		m++;

	}

	printf("%d\n",m);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int ans=0,gc=0,pc=0;

string a;

int main()

{

	cin>>a;

    for (int i=0;i<a.size();i++)

	{

		if(gc==pc)

		{

			gc++;

			if(a[i]=='p') ans--;

		}

		else

		{

			pc++;

			if(a[i]=='g') ans++;

		}

	}    

    cout<<ans<<endl;

    return 0;	

}


// Faster C++ solution for the same problem (measured speedup: 4.703281148763166x):
#include<cstdio>

#include<cstring>

int main()

{

	int x=0,y=0,m=0;

	char c[1000000];

	scanf("%s",&c);

	int n=strlen(c);

	for(int i=0;i<n;i++)

	if (x<=y)

	{

		x++;

		if (c[i]=='p')

		m--;

	}

	else

	{

		y++;

		if (c[i]=='g')

		m++;

	}

	printf("%d\n",m);

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

	cin>>a;

	for (int i=0;i<sizeof(a);i++)

	{

		if (x==y)//只能出石头

		{

			x++;

			if (a[i]=='p') ans--;

		} 

		else//可以出布

		{

			y++;

			if (a[i]=='g') ans++;

		} 

	}

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.227353408685497x):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<string>

#include<cstring>

using namespace std;

int main(){

	string s;

	cin>>s;

	int g=0,p=0,ans=0;

	for(int i=0;i<s.length();i++){

		if(g==p){

			g++;

			if(s[i]=='p')ans--;

		}

		else{

			p++;

			if(s[i]=='g')ans++;

		}

	}

	cout<<ans<<endl;

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

    cin>>a;

    for (int i=0;i<sizeof(a);i++)

    {

        if (x==y)

        {

            x++;

            if (a[i]=='p') ans--;

        } 

        else

        {

            y++;

            if (a[i]=='g') ans++;

        } 

    }

    printf("%d\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.227353408685497x):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<string>

#include<cstring>

using namespace std;

int main(){

	string s;

	cin>>s;

	int g=0,p=0,ans=0;

	for(int i=0;i<s.length();i++){

		if(g==p){

			g++;

			if(s[i]=='p')ans--;

		}

		else{

			p++;

			if(s[i]=='g')ans++;

		}

	}

	cout<<ans<<endl;

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

	cin>>a;

	for (int i=0;i<sizeof(a);i++)

	{

		if (x==y)//只能出石头

		{

			x++;

			if (a[i]=='p') ans--;

		} 

		else//可以出布

		{

			y++;

			if (a[i]=='g') ans++;

		} 

	}

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2419934276813351x):
#include<bits/stdc++.h>

using namespace std;

int main()

{char a[100001];

 int x=0,y=0,ans=0;

 cin>>a;

 for(int i=0;i<strlen(a);i++)

    if(x==y) {x++;if(a[i]=='p')ans--;}

    else {y++;if(a[i]=='g')ans++;}

 printf("%d\n",ans);

 return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

    cin>>a;

    for (int i=0;i<sizeof(a);i++)

    {

        if (x==y)

        {

            x++;

            if (a[i]=='p') ans--;

        } 

        else

        {

            y++;

            if (a[i]=='g') ans++;

        } 

    }

    printf("%d\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2419934276813351x):
#include<bits/stdc++.h>

using namespace std;

int main()

{char a[100001];

 int x=0,y=0,ans=0;

 cin>>a;

 for(int i=0;i<strlen(a);i++)

    if(x==y) {x++;if(a[i]=='p')ans--;}

    else {y++;if(a[i]=='g')ans++;}

 printf("%d\n",ans);

 return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

char s[100001];

int main()

{    

	scanf("%s",s+1);

	register int sum=0,l=strlen(s+1),p=0,g=0;

	for(register int i=1;i<=l;++i)

		if(s[i]=='g')

			if(g>p)

				++sum,++p;

			else

				++g;

		else

			if(g>p)

				++p;

			else

				--sum,g++;

	return printf("%d",sum),0;

} 


// Faster C++ solution for the same problem (measured speedup: 5.216934181406887x):
#include<cstdio>

#include<cstring>

char c[100005];

int s;

int main(){

	scanf("%s",c);

	for(int i=0;i<strlen(c);++i){

		if(c[i]=='g'&&i%2)++s;

		if(c[i]=='p'&&i%2==0)--s;

	}

	printf("%d\n",s);

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

int sco,p,g;char s;

int main()

{

	while(cin>>s)

	{

		if(s=='p'&&p<g){p++;continue;}

		if(s=='p'&&p==g){g++;sco--;continue;}

		if(s=='g'&&p<g){p++;sco++;continue;}

		if(s=='g'&&p==g){g++;continue;}

	}

	cout<<sco;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.272577479799795x):
#include<cstdio>

#include<cstring>

char c[100005];

int s;

int main(){

	scanf("%s",c);

	for(int i=0;i<strlen(c);++i){

		if(c[i]=='g'&&i%2)++s;

		if(c[i]=='p'&&i%2==0)--s;

	}

	printf("%d\n",s);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

	cin>>a;

	for (int i=0;i<sizeof(a);i++)

	{

		if (x==y)//只能出石头

		{

			x++;

			if (a[i]=='p') ans--;

		} 

		else//可以出布

		{

			y++;

			if (a[i]=='g') ans++;

		} 

	}

	printf("%d\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.529737370524708x):
#include<cstdio>

#include<cstring>

char c[100005];

int s;

int main(){

	scanf("%s",c);

	for(int i=0;i<strlen(c);++i){

		if(c[i]=='g'&&i%2)++s;

		if(c[i]=='p'&&i%2==0)--s;

	}

	printf("%d\n",s);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

char s[100005];

int sum=0,p=0,g=0;

int main()

{

	scanf("%s", s);

	int len=strlen(s);

	for(int i=0;i<len;i++)

	{

		if(s[i]=='g')

		{

			if(g>p)

			{

				sum++;

				p++;

			}else 

		    {

			    g++;

		    }

		} 

		else 

		{

			if(g>p)

			{

				p++;

			}

			else

			{

				sum--;

				g++;

			}

		}

	}

	cout<<sum;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.231498685097701x):
#include<cstdio>

#include<cstring>

char c[100005];

int s;

int main(){

	scanf("%s",c);

	for(int i=0;i<strlen(c);++i){

		if(c[i]=='g'&&i%2)++s;

		if(c[i]=='p'&&i%2==0)--s;

	}

	printf("%d\n",s);

    return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

int main()

{

	int sumg=0;

	int sump=0;

	char a;

	int ans=0;

	while(cin>>a)

	{

		if(a=='g')

		{

			if(sump<sumg)

			{

				ans++;

				sump++;

			}

			else	sumg++;

		}

		if(a=='p')

		{

			if(sump<sumg)

				sump++;

			else

			{

				ans--;

				sumg++;

			} 

		}

		

	}

	cout<<ans;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.269704974491522x):
#include<cstdio>

#include<cstring>

char c[100005];

int s;

int main(){

	scanf("%s",c);

	for(int i=0;i<strlen(c);++i){

		if(c[i]=='g'&&i%2)++s;

		if(c[i]=='p'&&i%2==0)--s;

	}

	printf("%d\n",s);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h> 

using namespace std; 

string sss; 

int main() 

{

    int i=0,x=0,y,ans; 

    cin>>sss; 

    int qaq=sss.length(); 

    while(i<qaq) 

    { 

        if(sss[i]=='p') x++; 

        i++; 

    } 

    y=i/2; 

    ans=y-x; 

    cout<<ans;

    return 0; 

} 

// Faster C++ solution for the same problem (measured speedup: 5.272163256717762x):
#include<cstdio>

#include<cstring>

char c[100005];

int s;

int main(){

	scanf("%s",c);

	for(int i=0;i<strlen(c);++i){

		if(c[i]=='g'&&i%2)++s;

		if(c[i]=='p'&&i%2==0)--s;

	}

	printf("%d\n",s);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;



char a[100005];

int x=0,y=0;

int ans=0;



int main()

{

    cin>>a;

    for (int i=0;i<sizeof(a);i++)

    {

        if (x==y)

        {

            x++;

            if (a[i]=='p') ans--;

        } 

        else

        {

            y++;

            if (a[i]=='g') ans++;

        } 

    }

    printf("%d\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.529737370524708x):
#include<cstdio>

#include<cstring>

char c[100005];

int s;

int main(){

	scanf("%s",c);

	for(int i=0;i<strlen(c);++i){

		if(c[i]=='g'&&i%2)++s;

		if(c[i]=='p'&&i%2==0)--s;

	}

	printf("%d\n",s);

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int ans=0,gc=0,pc=0;

string a;

int main()

{

	cin>>a;

    for (int i=0;i<a.size();i++)

	{

		if(gc==pc)

		{

			gc++;

			if(a[i]=='p') ans--;

		}

		else

		{

			pc++;

			if(a[i]=='g') ans++;

		}

	}    

    cout<<ans<<endl;

    return 0;	

}


// Faster C++ solution for the same problem (measured speedup: 5.279406865125378x):
#include<cstdio>

#include<cstring>

char c[100005];

int s;

int main(){

	scanf("%s",c);

	for(int i=0;i<strlen(c);++i){

		if(c[i]=='g'&&i%2)++s;

		if(c[i]=='p'&&i%2==0)--s;

	}

	printf("%d\n",s);

    return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

int main()

{

	int x=0,y=0,m=0;

	char c[1000000];

	scanf("%s",&c);

	int n=strlen(c);

	for(int i=0;i<n;i++)

	if (x<=y)

	{

		x++;

		if (c[i]=='p')

		m--;

	}

	else

	{

		y++;

		if (c[i]=='g')

		m++;

	}

	printf("%d\n",m);

}

// Faster C++ solution for the same problem (measured speedup: 1.1224944242411956x):
#include<cstdio>

#include<cstring>

char c[100005];

int s;

int main(){

	scanf("%s",c);

	for(int i=0;i<strlen(c);++i){

		if(c[i]=='g'&&i%2)++s;

		if(c[i]=='p'&&i%2==0)--s;

	}

	printf("%d\n",s);

    return 0;

}