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

#define Inf 0x3F3F3F3F

#define Loc freopen("baka.in", "r", stdin)

typedef long long LL;

using namespace std;



LL Read() {

	LL ___ = 0, __ = 1; char _ = getchar();

	while (_ < 48 || _ > 57)  if (_ == 45) __ = -1, _ = getchar();

	while (_ >= 48 && _ <= 57) ___ = ___ * 10 + _ - 48, _ = getchar();

	return ___ * __;

}



string str;

int G, P, ans;



int main() {

	cin >> str;

	for (int pos = 0; pos < str.size(); pos++) {

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

			if (P < G) ans++, P++;

			else G++;

		}

		else {

			if (P < G) P++;

			else G++, ans--;

		}

	}

	cout << ans << endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.275305668419735x):
#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<cstring>

#include<cstdio>

using namespace std;

char s[100005];

int win=0,los=0,len,maxn=1000000,pa,ro;

void dfs(int k)

{

//	for(int j=1;j<=2;j++){

//		

//	}

	

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

		if(pa+1<=ro){

			win++;

			pa++;

			dfs(k+1);

			pa--;

			win--;

//			cout<<

	//		if(los+1<=win){

	//			los++;

	

	//			dfs(k+1);

				

	//			los--;

	//		}

			

			

			

		}

		else{

	//		los++;

				ro++;

				dfs(k+1);

				ro--;

	//		los--;

			}

		

	}

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

		if(pa+1<=ro){

		

//		if(los<=win+1){

			pa++;

			dfs(k+1);

			pa--;

//		}

//		win++;

//			dfs(k+1);

//		win--;

		}

		else{

			los++;

			ro++;

			dfs(k+1);

			ro--;

			los--;

		}

	}

	if(k==len&&pa<=ro){

		if(maxn>(win-los))maxn=(win-los);

//		cout<<win-los<<" ";

	}

	

}

int  main(){

	scanf("%s",&s);

len=strlen(s);

//	cout<<len;

	dfs(0);

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

//		if(s[i]=='g'&&los<=win)win++;

//		else los++;

//		if(s[i]=='p'&&los<=win)los++;

//		else win++;

//	}

//	cout<<win-los;ggppgggpgg

cout<<maxn;

}


// Faster C++ solution for the same problem (measured speedup: 5.228817442881909x):
#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 a;

int main()

{

	cin>>a;

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

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

	{

		if(x==y)

		{

			x++;

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

			ans--;

		}

		else 

		{

			y++;

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

			ans++;

		}

		

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.211204079565327x):
#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>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

char a[100001];

int main(){

	scanf("%s",a);

	int bj=0,bj1=0,ans=0,n=strlen(a);

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

		if(bj==bj1){

			bj++;

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

				ans--;

		}

		else{

			bj1++;

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

				ans++;

		}

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.211282651395507x):
#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()

{

	string a;

	cin>>a;

	int l=a.length();

	int x1=0,x2=0;//石头，布 

	int ans=0;

	for(int i=0;i<=l-1;i++)

	{

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

		{

			if(x1>x2)

			{

				ans++;

				x2++;

			}

			else

			{

				x1++;

			}

		}

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

		{

			if(x1>x2)

			{

				x2++;

			}

			else

			{

				ans--;

				x1++;

			}

		}

	}

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.315639110349709x):
#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>

int main()

{

	char a[100005];

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

	scanf("%s",&a);

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

		if(x==y){

			x++;

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

			s--;

		} 

    	else{

			y++;

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

			s++;

		} 

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.254346321739308x):
#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 s;

int a,b,l;

int main(){

	cin>>s;

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

		if(a==b){

			a++;

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

		}

		else {

			b++;

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

		}

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2113554865601195x):
#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<cstring>

#include<cmath>

#include<algorithm>

#include<queue>

#include<map>

using namespace std;

typedef long long ll;

typedef pair<int,int>pii;

const int inf=0x3f3f3f3f;

char a[100010];

int ans,cnt;

int main()

{

	scanf("%s",a);

	int l=strlen(a);

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

	{

		if(cnt>0)

		{

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

				++ans;

			--cnt;

		}

		else

		{

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

				--ans;

			++cnt;

		}

	}

	cout<<ans;

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.226023320891891x):
#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:
#pragma GCC optimize(3)

#include<bits/stdc++.h>

char a[100005];

int x,y,ans;

main(){

std::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);}

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

#define mn(a,b) (a<b?a:b)

using namespace std;

string s;

int w,l,n,p;

int main()

{

	cin>>s,n=s.size();

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

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

	w=mn(n/2,n-p),l=mn((n+1)/2,p);

	printf("%d\n",w-l),exit(0);

}

// Faster C++ solution for the same problem (measured speedup: 5.251755866011278x):
#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:
#pragma GCC optimize(3)

#include<bits/stdc++.h>

char a[100005];

int x,y,ans;

main(){

std::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);}

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

#include <string.h>

#include <bits/stdc++.h>



using namespace std;



char a[1000010];



int main()

{

    int b,i,l=0,sum=0,m=0;

    scanf("%s",a);

    b=strlen(a);

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

    {

        if(a[i]=='g'&&l<m)

        {

            sum++;

            l++;

        }

        else if(a[i]=='g'&&l>=m)

        {

            m++;

        }

        else if(a[i]=='p'&&l>=m)

        {

            sum--;

            m++;

        }

        else if(a[i]=='p'&&l<m)

        {

            l++;

        }

    }

    printf("%d",sum);

    return 0;

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

#include<cstdio>

using namespace std;

char a[100005];

int x=0,y=0,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.251270262366794x):
#include <iostream>

#include <string.h>

#include <bits/stdc++.h>



using namespace std;



char a[1000010];



int main()

{

    int b,i,l=0,sum=0,m=0;

    scanf("%s",a);

    b=strlen(a);

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

    {

        if(a[i]=='g'&&l<m)

        {

            sum++;

            l++;

        }

        else if(a[i]=='g'&&l>=m)

        {

            m++;

        }

        else if(a[i]=='p'&&l>=m)

        {

            sum--;

            m++;

        }

        else if(a[i]=='p'&&l<m)

        {

            l++;

        }

    }

    printf("%d",sum);

    return 0;

}
// Slower C++ solution:
#pragma GCC optimize(3)

#include<bits/stdc++.h>

char a[100005];

int x,y,ans;

main(){

std::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);}

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

char c[100005];

int main(void){

    std::cin>>c;

	int l=strlen(c),qwq=0;

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

    printf("%d\n\r",std::min(l/2,qwq)-std::min(l-l/2,l-qwq));

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

#include<cstdio>

using namespace std;

char a[100005];

int x=0,y=0,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.241362341887217x):
#include<bits/stdc++.h>

char c[100005];

int main(void){

    std::cin>>c;

	int l=strlen(c),qwq=0;

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

    printf("%d\n\r",std::min(l/2,qwq)-std::min(l-l/2,l-qwq));

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

#define Inf 0x3F3F3F3F

#define Loc freopen("baka.in", "r", stdin)

typedef long long LL;

using namespace std;



LL Read() {

	LL ___ = 0, __ = 1; char _ = getchar();

	while (_ < 48 || _ > 57)  if (_ == 45) __ = -1, _ = getchar();

	while (_ >= 48 && _ <= 57) ___ = ___ * 10 + _ - 48, _ = getchar();

	return ___ * __;

}



string str;

int G, P, ans;



int main() {

	cin >> str;

	for (int pos = 0; pos < str.size(); pos++) {

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

			if (P < G) ans++, P++;

			else G++;

		}

		else {

			if (P < G) P++;

			else G++, ans--;

		}

	}

	cout << ans << endl;

}


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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

#include<cstring>

#include<cstdio>

using namespace std;

char s[100005];

int win=0,los=0,len,maxn=1000000,pa,ro;

void dfs(int k)

{

//	for(int j=1;j<=2;j++){

//		

//	}

	

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

		if(pa+1<=ro){

			win++;

			pa++;

			dfs(k+1);

			pa--;

			win--;

//			cout<<

	//		if(los+1<=win){

	//			los++;

	

	//			dfs(k+1);

				

	//			los--;

	//		}

			

			

			

		}

		else{

	//		los++;

				ro++;

				dfs(k+1);

				ro--;

	//		los--;

			}

		

	}

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

		if(pa+1<=ro){

		

//		if(los<=win+1){

			pa++;

			dfs(k+1);

			pa--;

//		}

//		win++;

//			dfs(k+1);

//		win--;

		}

		else{

			los++;

			ro++;

			dfs(k+1);

			ro--;

			los--;

		}

	}

	if(k==len&&pa<=ro){

		if(maxn>(win-los))maxn=(win-los);

//		cout<<win-los<<" ";

	}

	

}

int  main(){

	scanf("%s",&s);

len=strlen(s);

//	cout<<len;

	dfs(0);

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

//		if(s[i]=='g'&&los<=win)win++;

//		else los++;

//		if(s[i]=='p'&&los<=win)los++;

//		else win++;

//	}

//	cout<<win-los;ggppgggpgg

cout<<maxn;

}


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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

using namespace std;

string a;

int main()

{

	cin>>a;

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

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

	{

		if(x==y)

		{

			x++;

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

			ans--;

		}

		else 

		{

			y++;

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

			ans++;

		}

		

	}

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

	return 0;

}

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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

char a[100001];

int main(){

	scanf("%s",a);

	int bj=0,bj1=0,ans=0,n=strlen(a);

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

		if(bj==bj1){

			bj++;

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

				ans--;

		}

		else{

			bj1++;

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

				ans++;

		}

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

    return 0;

}

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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

using namespace std;

int main()

{

	string a;

	cin>>a;

	int l=a.length();

	int x1=0,x2=0;//石头，布 

	int ans=0;

	for(int i=0;i<=l-1;i++)

	{

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

		{

			if(x1>x2)

			{

				ans++;

				x2++;

			}

			else

			{

				x1++;

			}

		}

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

		{

			if(x1>x2)

			{

				x2++;

			}

			else

			{

				ans--;

				x1++;

			}

		}

	}

	cout<<ans<<endl;

	return 0;

}

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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

int main()

{

	char a[100005];

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

	scanf("%s",&a);

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

		if(x==y){

			x++;

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

			s--;

		} 

    	else{

			y++;

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

			s++;

		} 

	}

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

	return 0;

}

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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

using namespace std;

string s;

int a,b,l;

int main(){

	cin>>s;

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

		if(a==b){

			a++;

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

		}

		else {

			b++;

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

		}

	}

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

	return 0;

}

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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

#include<iostream>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<queue>

#include<map>

using namespace std;

typedef long long ll;

typedef pair<int,int>pii;

const int inf=0x3f3f3f3f;

char a[100010];

int ans,cnt;

int main()

{

	scanf("%s",a);

	int l=strlen(a);

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

	{

		if(cnt>0)

		{

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

				++ans;

			--cnt;

		}

		else

		{

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

				--ans;

			++cnt;

		}

	}

	cout<<ans;

    return 0;

}




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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

}
// Slower C++ solution:
#pragma GCC optimize(3)

#include<bits/stdc++.h>

char a[100005];

int x,y,ans;

main(){

std::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);}

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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

#define mn(a,b) (a<b?a:b)

using namespace std;

string s;

int w,l,n,p;

int main()

{

	cin>>s,n=s.size();

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

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

	w=mn(n/2,n-p),l=mn((n+1)/2,p);

	printf("%d\n",w-l),exit(0);

}

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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

#include<cstdio>

using namespace std;

char a[100005];

int x=0,y=0,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.520109043746861x):
#include<cstdio>

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

#include <string.h>

#include <bits/stdc++.h>



using namespace std;



char a[1000010];



int main()

{

    int b,i,l=0,sum=0,m=0;

    scanf("%s",a);

    b=strlen(a);

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

    {

        if(a[i]=='g'&&l<m)

        {

            sum++;

            l++;

        }

        else if(a[i]=='g'&&l>=m)

        {

            m++;

        }

        else if(a[i]=='p'&&l>=m)

        {

            sum--;

            m++;

        }

        else if(a[i]=='p'&&l<m)

        {

            l++;

        }

    }

    printf("%d",sum);

    return 0;

}

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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

char c[100005];

int main(void){

    std::cin>>c;

	int l=strlen(c),qwq=0;

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

    printf("%d\n\r",std::min(l/2,qwq)-std::min(l-l/2,l-qwq));

}

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

#include<cstring>

char s[1001000];

int main ()

{

	scanf("%s",s);

	int len=strlen(s),ag=0,me=len/2 ;

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

	{

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

			ag++;

	}

	printf("%d",me-ag);

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

#include<string.h>

#include<algorithm>

#include<iostream>

#include<queue>

#include<math.h>

#define mem(a,b) memset(a,b,sizeof(a))

#define inf 0x3f3f3f3f

#define mod 10007

using  namespace std;

int maxn (int a,int b,int c){return max(max(a,b),max(b,c));}

int main()

{

    char a[100005];

    scanf("%s",a);

    int num=strlen(a)/2;

    //if(strlen(a)%2==1)

    int p=0,g=0;

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

    {

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

        else if(a[i]=='p') p++;

    }

    printf("%d\n",num-p);

    return 0;

}




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

#include<string.h>

char s[1000001];

int main()

{

    scanf("%s",s);

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

    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",ans);

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

#include<iostream>

#include<cstring>

#include<cstdio>

#include<vector>

#include<cmath>

#include<ctime>

#include<queue>

#include<map>

#define LL long long

#define il inline

#define re register

#define db double

#define eps (1e-5)



using namespace std;

const int N=100000+10;

il LL rd()

{

    re LL x=0,w=1;re char ch;

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

    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}

    return x*w;

}

int n,ans;

char cc[N];



int main()

{

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

  n=strlen(cc+1);

  for(int i=1;i<=(n+1)>>1;i++) ans-=(cc[i]=='p');

  for(int i=(n+1)/2+1;i<=n;i++) ans+=(cc[i]=='g');

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

  return 0;

}

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

#include<string.h>

char s[1000001];

int main()

{

    scanf("%s",s);

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

    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",ans);

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

#define INF 0x3f3f3f3f

using namespace std;

string s;

int n,p1[100001],maxn=-INF,c[2]={0,1},ans,rk,pp;

void dfs(int t){

	if(t>n){

		maxn=maxn>ans?maxn:ans;

		return;

	}

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

		if(rk>pp){

			pp++;

			dfs(t+1);

			pp--;

		}

		else {

			rk++;

			ans--;

			dfs(t+1);

			rk--;

		}

	}

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

		if(rk>pp){

			pp++;

			ans++;

			dfs(t+1);

			pp--;

			ans--;

		}

		else {

			rk++;

			dfs(t+1);

			rk--;

		}

	}

}

int main(){

	cin>>s;

	n=s.size();

	s=' '+s;

	dfs(1);

	printf("%d",maxn);

	return 0;

}

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

#include<string.h>

char s[1000001];

int main()

{

    scanf("%s",s);

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

    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",ans);

}