stablegradients/pie-gem5-pairs huggingface dataset:
// 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.271744236396782x):
#include<cstdio>

#define sacnf scanf

#define pritnf printf

#define srnad srand

#define rnad rand

#define sl(sl_a) strlen(sl_a)

#define gt(gt_a) goto gt_a

#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))

#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))

#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))

#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))

#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))

#define re register

#define inl inline

#define br break

#define con continue

#define stt struct

#define nms namespace

#define gc getchar

#define rt return

#define infa (0x3f3f3f3f)

#define infb (0x7fffffff)

#define infd (0x7f)

#define in(in_a) freopen("F:/""/in"in_a".in","r",stdin)

#define out(out_a) freopen("F:/""/out"out_a".out","w",stdout)

#define fin(filein_a) freopen(filein_a".in","r",stdin)

#define fout(fileout_a) freopen(fileout_a".out","w",stdout)

typedef long long ll;

typedef int itn,nti,tin,tni,nit;

using namespace std;

const nit maxa=100004;

const nit maxb=54;

const nit maxc=4;

const tni maxd=24;

#include<cstring>



tni s,clo=0,ans=0;

char x[maxa];



tni main()

{

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

	//

	s=sl(x+1);

	fora(i,1,s)

	{

		if(clo)

		{

			--clo;

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

			{

				++ans;

			}

		}

		else

		{

			++clo;

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

			{

				--ans;

			}

		}

	}

	//

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

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

#define sacnf scanf

#define pritnf printf

#define srnad srand

#define rnad rand

#define sl(sl_a) strlen(sl_a)

#define gt(gt_a) goto gt_a

#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))

#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))

#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))

#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))

#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))

#define re register

#define inl inline

#define br break

#define con continue

#define stt struct

#define nms namespace

#define gc getchar

#define rt return

#define infa (0x3f3f3f3f)

#define infb (0x7fffffff)

#define infd (0x7f)

#define in(in_a) freopen("F:/""/in"in_a".in","r",stdin)

#define out(out_a) freopen("F:/""/out"out_a".out","w",stdout)

#define fin(filein_a) freopen(filein_a".in","r",stdin)

#define fout(fileout_a) freopen(fileout_a".out","w",stdout)

typedef long long ll;

typedef int itn,nti,tin,tni,nit;

using namespace std;

const nit maxa=100004;

const nit maxb=54;

const nit maxc=4;

const tni maxd=24;

#include<cstring>



tni s,clo=0,ans=0;

char x[maxa];



tni main()

{

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

	//

	s=sl(x+1);

	fora(i,1,s)

	{

		if(clo)

		{

			--clo;

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

			{

				++ans;

			}

		}

		else

		{

			++clo;

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

			{

				--ans;

			}

		}

	}

	//

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

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

#define sacnf scanf

#define pritnf printf

#define srnad srand

#define rnad rand

#define sl(sl_a) strlen(sl_a)

#define gt(gt_a) goto gt_a

#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))

#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))

#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))

#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))

#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))

#define re register

#define inl inline

#define br break

#define con continue

#define stt struct

#define nms namespace

#define gc getchar

#define rt return

#define infa (0x3f3f3f3f)

#define infb (0x7fffffff)

#define infd (0x7f)

#define in(in_a) freopen("F:/""/in"in_a".in","r",stdin)

#define out(out_a) freopen("F:/""/out"out_a".out","w",stdout)

#define fin(filein_a) freopen(filein_a".in","r",stdin)

#define fout(fileout_a) freopen(fileout_a".out","w",stdout)

typedef long long ll;

typedef int itn,nti,tin,tni,nit;

using namespace std;

const nit maxa=100004;

const nit maxb=54;

const nit maxc=4;

const tni maxd=24;

#include<cstring>



tni s,clo=0,ans=0;

char x[maxa];



tni main()

{

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

	//

	s=sl(x+1);

	fora(i,1,s)

	{

		if(clo)

		{

			--clo;

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

			{

				++ans;

			}

		}

		else

		{

			++clo;

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

			{

				--ans;

			}

		}

	}

	//

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

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

#define sacnf scanf

#define pritnf printf

#define srnad srand

#define rnad rand

#define sl(sl_a) strlen(sl_a)

#define gt(gt_a) goto gt_a

#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))

#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))

#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))

#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))

#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))

#define re register

#define inl inline

#define br break

#define con continue

#define stt struct

#define nms namespace

#define gc getchar

#define rt return

#define infa (0x3f3f3f3f)

#define infb (0x7fffffff)

#define infd (0x7f)

#define in(in_a) freopen("F:/""/in"in_a".in","r",stdin)

#define out(out_a) freopen("F:/""/out"out_a".out","w",stdout)

#define fin(filein_a) freopen(filein_a".in","r",stdin)

#define fout(fileout_a) freopen(fileout_a".out","w",stdout)

typedef long long ll;

typedef int itn,nti,tin,tni,nit;

using namespace std;

const nit maxa=100004;

const nit maxb=54;

const nit maxc=4;

const tni maxd=24;

#include<cstring>



tni s,clo=0,ans=0;

char x[maxa];



tni main()

{

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

	//

	s=sl(x+1);

	fora(i,1,s)

	{

		if(clo)

		{

			--clo;

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

			{

				++ans;

			}

		}

		else

		{

			++clo;

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

			{

				--ans;

			}

		}

	}

	//

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

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

#define sacnf scanf

#define pritnf printf

#define srnad srand

#define rnad rand

#define sl(sl_a) strlen(sl_a)

#define gt(gt_a) goto gt_a

#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))

#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))

#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))

#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))

#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))

#define re register

#define inl inline

#define br break

#define con continue

#define stt struct

#define nms namespace

#define gc getchar

#define rt return

#define infa (0x3f3f3f3f)

#define infb (0x7fffffff)

#define infd (0x7f)

#define in(in_a) freopen("F:/""/in"in_a".in","r",stdin)

#define out(out_a) freopen("F:/""/out"out_a".out","w",stdout)

#define fin(filein_a) freopen(filein_a".in","r",stdin)

#define fout(fileout_a) freopen(fileout_a".out","w",stdout)

typedef long long ll;

typedef int itn,nti,tin,tni,nit;

using namespace std;

const nit maxa=100004;

const nit maxb=54;

const nit maxc=4;

const tni maxd=24;

#include<cstring>



tni s,clo=0,ans=0;

char x[maxa];



tni main()

{

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

	//

	s=sl(x+1);

	fora(i,1,s)

	{

		if(clo)

		{

			--clo;

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

			{

				++ans;

			}

		}

		else

		{

			++clo;

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

			{

				--ans;

			}

		}

	}

	//

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

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

#define sacnf scanf

#define pritnf printf

#define srnad srand

#define rnad rand

#define sl(sl_a) strlen(sl_a)

#define gt(gt_a) goto gt_a

#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))

#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))

#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))

#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))

#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))

#define re register

#define inl inline

#define br break

#define con continue

#define stt struct

#define nms namespace

#define gc getchar

#define rt return

#define infa (0x3f3f3f3f)

#define infb (0x7fffffff)

#define infd (0x7f)

#define in(in_a) freopen("F:/""/in"in_a".in","r",stdin)

#define out(out_a) freopen("F:/""/out"out_a".out","w",stdout)

#define fin(filein_a) freopen(filein_a".in","r",stdin)

#define fout(fileout_a) freopen(fileout_a".out","w",stdout)

typedef long long ll;

typedef int itn,nti,tin,tni,nit;

using namespace std;

const nit maxa=100004;

const nit maxb=54;

const nit maxc=4;

const tni maxd=24;

#include<cstring>



tni s,clo=0,ans=0;

char x[maxa];



tni main()

{

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

	//

	s=sl(x+1);

	fora(i,1,s)

	{

		if(clo)

		{

			--clo;

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

			{

				++ans;

			}

		}

		else

		{

			++clo;

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

			{

				--ans;

			}

		}

	}

	//

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

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

#define sacnf scanf

#define pritnf printf

#define srnad srand

#define rnad rand

#define sl(sl_a) strlen(sl_a)

#define gt(gt_a) goto gt_a

#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))

#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))

#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))

#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))

#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))

#define re register

#define inl inline

#define br break

#define con continue

#define stt struct

#define nms namespace

#define gc getchar

#define rt return

#define infa (0x3f3f3f3f)

#define infb (0x7fffffff)

#define infd (0x7f)

#define in(in_a) freopen("F:/""/in"in_a".in","r",stdin)

#define out(out_a) freopen("F:/""/out"out_a".out","w",stdout)

#define fin(filein_a) freopen(filein_a".in","r",stdin)

#define fout(fileout_a) freopen(fileout_a".out","w",stdout)

typedef long long ll;

typedef int itn,nti,tin,tni,nit;

using namespace std;

const nit maxa=100004;

const nit maxb=54;

const nit maxc=4;

const tni maxd=24;

#include<cstring>



tni s,clo=0,ans=0;

char x[maxa];



tni main()

{

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

	//

	s=sl(x+1);

	fora(i,1,s)

	{

		if(clo)

		{

			--clo;

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

			{

				++ans;

			}

		}

		else

		{

			++clo;

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

			{

				--ans;

			}

		}

	}

	//

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

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

#define sacnf scanf

#define pritnf printf

#define srnad srand

#define rnad rand

#define sl(sl_a) strlen(sl_a)

#define gt(gt_a) goto gt_a

#define mst(mst_a,mst_b) memset(mst_a,mst_b,sizeof(mst_a))

#define fora(fora_x,fora_a,fora_b) for(re nti (fora_x)=(fora_a);(fora_x)<=(fora_b);++(fora_x))

#define forb(forb_x,forb_a,forb_b) for(re nit (forb_x)=(forb_a);(forb_x)>=(forb_b);--(forb_x))

#define foral(foral_x,foral_a,foral_b) for(re ll (foral_x)=(foral_a);(foral_x)<=(foral_b);++(foral_x))

#define forbl(forbl_x,forbl_a,forbl_b) for(re ll (forbl_x)=(forbl_a);(forbl_x)>=(forbl_b);--(forbl_x))

#define re register

#define inl inline

#define br break

#define con continue

#define stt struct

#define nms namespace

#define gc getchar

#define rt return

#define infa (0x3f3f3f3f)

#define infb (0x7fffffff)

#define infd (0x7f)

#define in(in_a) freopen("F:/""/in"in_a".in","r",stdin)

#define out(out_a) freopen("F:/""/out"out_a".out","w",stdout)

#define fin(filein_a) freopen(filein_a".in","r",stdin)

#define fout(fileout_a) freopen(fileout_a".out","w",stdout)

typedef long long ll;

typedef int itn,nti,tin,tni,nit;

using namespace std;

const nit maxa=100004;

const nit maxb=54;

const nit maxc=4;

const tni maxd=24;

#include<cstring>



tni s,clo=0,ans=0;

char x[maxa];



tni main()

{

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

	//

	s=sl(x+1);

	fora(i,1,s)

	{

		if(clo)

		{

			--clo;

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

			{

				++ans;

			}

		}

		else

		{

			++clo;

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

			{

				--ans;

			}

		}

	}

	//

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

	rt 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.211801409867515x):
#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<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.267389962632356x):
#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: 6.523312974707246x):
#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 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.226351584017755x):
#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<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.2645202834884515x):
#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; 

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.266976147090915x):
#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: 6.523312974707246x):
#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;

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.274212628748264x):
#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<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.1213900385553683x):
#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<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.314942646954274x):
#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;

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.252292668637992x):
#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[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.393616610269294x):
#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;

}