stablegradients/pie-gem5-pairs huggingface dataset:
// 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.3201769957343386x):
#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 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.257465317441339x):
#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[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.41370098545747x):
#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[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.2116455921972324x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.26723248302638x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.523117946664097x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.226195331339677x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.264362889677517x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.266818679856818x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.523117946664097x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.274054945164458x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.1213565122619535x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.314783745661648x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.2521356403971x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.39300690057797x):
#include<cstdio>

#include<cstring>

using namespace std;

int x,y,ans;

char s[100001];

int main(){

    scanf("%s",s);

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

    	if(x==y){

			x++;

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

		}

    	else{

			y++;

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

		}

    }

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

}
// 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.2397141878617615x):
#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;

}
// 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.2397141878617615x):
#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;

}
// 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.87567727496606x):
#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;

}
// 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.216519550575333x):
#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<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.272158426557246x):
#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;

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.231082896710375x):
#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<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.269286149549585x):
#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;

}