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

using namespace std;

int main() {

	int x=0,y=0,s=0;

	string a;

	cin>>a;

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

		if (x==y) {

			x++;

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

				s--;

		} else {

			y++;

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

				s++;

		}

	cout<<s;

	return 0;

}

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

#include <cstring>

#include <algorithm>

using namespace std;

char c[100007];

int main(){

    scanf("%s",c);int l=strlen(c),g=0;

    for(int i=0;i<l;++i)if(c[i]=='g')g++;

    printf("%d\n",min(l/2,g)-min(l-l/2,l-g));

    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.2398290360481303x):
#include<bits/stdc++.h>

using namespace std;

int main(){

    bool b=0;

    int n,ans=0;

    string s;

    cin>>s;

    n=s.size();

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

        bool t;

        b=!b;

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

            t=1;

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

            t=0;

        }

        if(t==b){

            continue;

        }else if(t==1&&b==0){

            ans++;

        }else{

            ans--;

        }

    }

    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.2398290360481303x):
#include<bits/stdc++.h>

using namespace std;

int main(){

    bool b=0;

    int n,ans=0;

    string s;

    cin>>s;

    n=s.size();

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

        bool t;

        b=!b;

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

            t=1;

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

            t=0;

        }

        if(t==b){

            continue;

        }else if(t==1&&b==0){

            ans++;

        }else{

            ans--;

        }

    }

    cout<<ans;

    return 0;

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

using namespace std;

char a[1000010];

int main()

{

    cin>>a;

    int x=0,y=0;

    int ans=0;

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

    {

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

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

    }

    cout<<ans;



}

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

using namespace std;

int main(){

    bool b=0;

    int n,ans=0;

    string s;

    cin>>s;

    n=s.size();

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

        bool t;

        b=!b;

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

            t=1;

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

            t=0;

        }

        if(t==b){

            continue;

        }else if(t==1&&b==0){

            ans++;

        }else{

            ans--;

        }

    }

    cout<<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.214250335851454x):
#include <cstdio>



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    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.269865008615996x):
#include <cstdio>



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

			if(ch[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: 6.5263781549374205x):
#include <cstdio>



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    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.228807346850749x):
#include <cstdio>



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    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.266993981064647x):
#include <cstdio>



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    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.269450998630533x):
#include <cstdio>



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

			if(ch[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: 6.5263781549374205x):
#include <cstdio>



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    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.276690880572461x):
#include <cstdio>



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    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.1219169583260158x):
#include <cstdio>



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    return 0;

}
// Slower C++ solution:
#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;

}

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



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    return 0;

}
// Slower C++ solution:
#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;

}

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



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    return 0;

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

using namespace std;

char a[1000010];

int main()

{

    cin>>a;

    int x=0,y=0;

    int ans=0;

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

    {

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

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

    }

    cout<<ans;



}

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



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    return 0;

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

using namespace std;

int main() {

	int x=0,y=0,s=0;

	string a;

	cin>>a;

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

		if (x==y) {

			x++;

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

				s--;

		} else {

			y++;

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

				s++;

		}

	cout<<s;

	return 0;

}

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



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    return 0;

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

using namespace std;

int main(){

    bool b=0;

    int n,ans=0;

    string s;

    cin>>s;

    n=s.size();

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

        bool t;

        b=!b;

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

            t=1;

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

            t=0;

        }

        if(t==b){

            continue;

        }else if(t==1&&b==0){

            ans++;

        }else{

            ans--;

        }

    }

    cout<<ans;

    return 0;

}

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



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

	for(i=0;ch[i];++i)

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

			if(ch[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.25040555952302x):
#include<bits/stdc++.h> 

using namespace std;

char a[100007];

int main()

{

  scanf("%s",a);

  int l=strlen(a),x=0,i;

  for(i=0;i<l;i++)

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

	  x++;

  printf("%d\n",min(l/2,x)-min(l-l/2,l-x));

  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.25040555952302x):
#include<bits/stdc++.h> 

using namespace std;

char a[100007];

int main()

{

  scanf("%s",a);

  int l=strlen(a),x=0,i;

  for(i=0;i<l;i++)

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

	  x++;

  printf("%d\n",min(l/2,x)-min(l-l/2,l-x));

  return 0;

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

using namespace std;

char a[1000010];

int main()

{

    cin>>a;

    int x=0,y=0;

    int ans=0;

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

    {

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

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

    }

    cout<<ans;



}

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

using namespace std;

char a[100007];

int main()

{

  scanf("%s",a);

  int l=strlen(a),x=0,i;

  for(i=0;i<l;i++)

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

	  x++;

  printf("%d\n",min(l/2,x)-min(l-l/2,l-x));

  return 0;

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

using namespace std;

string s;

long long n,m,m2,kt;

int main()

{

	cin>>s;

	n=s.length();

	m=0;

    kt=0;

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

    if(m==0)

    {

    	m++;

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

	}

	else

	  {

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

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

	  	{

	  		m--;

	  		kt++;

		}

	  }

	cout<<kt;

}

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

#include<algorithm>

#include<cstring>

using namespace std;

const int MAXN=int(1e5)+5;



char s[MAXN];



int main()

{

	int tb=0;

	scanf("%s",s);

	int len=strlen(s);

	int ans=0;

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

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

			ans--;

		if(tb) ans++,tb--;

		else tb++;

	}

	printf("%d",ans);

}
// 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



using i64 = long long;



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.290721743932256x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

const int MAXN=int(1e5)+5;



char s[MAXN];



int main()

{

	int tb=0;

	scanf("%s",s);

	int len=strlen(s);

	int ans=0;

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

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

			ans--;

		if(tb) ans++,tb--;

		else tb++;

	}

	printf("%d",ans);

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

#include<cstring>

#include<algorithm>

#include<vector>

#define MAXN 100000

using namespace std;

vector<int> num;

char str[MAXN+5];

int cnt[2],sum[MAXN+5];

int main()

{

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

	int n=strlen(str+1),cnt=0;

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

	{

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

			sum[i]=sum[i-1]+1;

		else

			sum[i]=sum[i-1]-1;

	}

	printf("%d\n",sum[n]/2);

	return 0;

}

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

#include<algorithm>

#include<cstring>

using namespace std;

const int MAXN=int(1e5)+5;



char s[MAXN];



int main()

{

	int tb=0;

	scanf("%s",s);

	int len=strlen(s);

	int ans=0;

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

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

			ans--;

		if(tb) ans++,tb--;

		else tb++;

	}

	printf("%d",ans);

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

using namespace std;

string s;

long long n,m,m2,kt;

int main()

{

	cin>>s;

	n=s.length();

	m=0;

    kt=0;

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

    if(m==0)

    {

    	m++;

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

	}

	else

	  {

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

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

	  	{

	  		m--;

	  		kt++;

		}

	  }

	cout<<kt;

}

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

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

char s[100005];

int paper;

int ans;

int main() {

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

	int len=strlen(s+1);

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

		if(!paper) {

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

			paper++;

			continue;

		}

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

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

	}

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

}
// 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



using i64 = long long;



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.274535405171994x):
#include<cmath>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

char s[100005];

int paper;

int ans;

int main() {

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

	int len=strlen(s+1);

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

		if(!paper) {

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

			paper++;

			continue;

		}

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

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

	}

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

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

#include<cstring>

#include<algorithm>

#include<vector>

#define MAXN 100000

using namespace std;

vector<int> num;

char str[MAXN+5];

int cnt[2],sum[MAXN+5];

int main()

{

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

	int n=strlen(str+1),cnt=0;

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

	{

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

			sum[i]=sum[i-1]+1;

		else

			sum[i]=sum[i-1]-1;

	}

	printf("%d\n",sum[n]/2);

	return 0;

}

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

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

char s[100005];

int paper;

int ans;

int main() {

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

	int len=strlen(s+1);

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

		if(!paper) {

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

			paper++;

			continue;

		}

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

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

	}

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

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

#include<map>

#include<queue>

#include<ctime>

#include<cmath>

#include<cstdio>

#include<vector>

#include<climits>

#include<cstring>

#include<iostream>

#include<algorithm>    

using namespace std;

#define LL long long

int read(){

    int f=1,x=0;char s=getchar();   

    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}  

    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}

    return x*f;

}

#define MAXN 100000

#define INF 0x3f3f3f3f

char str[MAXN+5];

int main(){

	int n,r=0,g=0,ans=0;

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

	n=strlen(str+1);

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

		if(str[i]=='g'){

			if(r<g) ans++,r++;

			else g++;

		}

		else{

			if(r<g) r++;

			else ans--,g++;

		}

	}

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

	return 0;

}

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

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

char s[100005];

int paper;

int ans;

int main() {

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

	int len=strlen(s+1);

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

		if(!paper) {

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

			paper++;

			continue;

		}

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

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

	}

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

}