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

using namespace std;

char a[100005];

int x,y,ans;

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++;

		}

    }

    cout<<ans<<endl;

    return 0;

}

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

using namespace std;

char a[200010];

int p,g,ans;

int main() {

	cin>>a;

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

		if(g==p) {

			g++;

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

				ans--;

		}

		else {

			p++;

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

				ans++;

		}

	}

	cout<<ans<<endl;

	return 0;

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

using namespace std;

char a[100005];

int x,y,ans;

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++;

		}

    }

    cout<<ans<<endl;

    return 0;

}

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

#include<cstring>

#include <iostream>

#include <algorithm>

using namespace std;

int x,y,m,i;

int main()

{

    string c;

    cin>>c;

    for(;i<c.length();++i)

	    if(x<=y)

	    {

	        x++;

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

	    }

	    else

	    {

	        y++;

	        if(c[i]=='g')m++;

	    }

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

    return 0;

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

using namespace std;

char a[100005];

int x,y,ans;

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++;

		}

    }

    cout<<ans<<endl;

    return 0;

}

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

#include<string>

#include<iostream> 

using namespace std;



int ans,flag;

string a;



int read()

{

	int x = 0, f = 1;

	char ch = getchar();

	for (; !isdigit(ch); ch = getchar())

	if (ch == '-') f = -1;

	for (; isdigit(ch); ch = getchar())

	x = x * 10 + ch - '0';

	return x * f;

}



int main()

{

	cin>>a;

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

	{

		flag=(flag+1)%2;

		if (flag==1)

		{

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

			ans--;

		}

		else

		{

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

			ans++;

		}

	}

	printf("%d",ans);

	return 0;

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

using namespace std;

char a[100005];

int x,y,ans;

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++;

		}

    }

    cout<<ans<<endl;

    return 0;

}

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

using namespace std;



char a[100005];

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



int main()

{

    scanf("%s",a);

    int mm=strlen(a);

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

        if (x==y)

        {

            x++;

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

                ans--;

        } 

        else

        {

            y++;

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

                ans++;

        }

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

    return 0;

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

using namespace std;

char a[100005];

int x,y,ans;

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++;

		}

    }

    cout<<ans<<endl;

    return 0;

}

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

using namespace std;

int main(){

	bool b=0;

	int n,ans=0;

	string a;

	cin>>a;

	n=a.size();

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

		bool t;

		b=!b;

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

			t=1;

		}else if(a[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,y,ans;

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++;

		}

    }

    cout<<ans<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2507235669793835x):
//666yuchen

#include<bits/stdc++.h>

using namespace std;

string st;

int ans,s,b;

int main()

{

  cin>>st;

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

    if(s==b){s++;if(st[i]=='p')ans--;}

      else{b++;if(st[i]=='g')ans++;}

  cout<<ans;

  return 0;

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

using namespace std;

#define ll long long

char a[101000];

int main()

{

    int i,j,k,m,n;

    cin>>a;

    int ansp=0,ansg=0;

    int cnt=0,ans=0;

    n=strlen(a);

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

    {

        if(i==0)

        {

            ansg++;

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

                cnt--;

        }

        else

        {

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

            {

                ansg++;

            }

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

            {

                if(ansp<ansg)

                {

                    ansp++;

                }

                else

                {

                    ansg++;

                    cnt--;

                }

            }

        }

    }

    cout<<(ansg-ansp)/2+cnt<<endl;

    return 0;

}


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

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

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

				ans++;

			}

		}

	}

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

	return 0;

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

using namespace std;

int f;

char c[100010];

int main(){

	scanf("%s",c);

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

	{

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

			if(i%2==0) f--;

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

			if(i%2==1) f++;

	}

	cout<<f;

	return 0;

}

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

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

			if(str[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.272856483780451x):
#include<cstdio>

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

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

				ans++;

			}

		}

	}

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

	return 0;

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

using namespace std;

string s;

signed main()

{

    cin>>s;

    int l=s.length(),k=0;

    for(int i=0;i<l;i++) if(s[i]=='p') k++;

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

    return 0;

}

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

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

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

				ans++;

			}

		}

	}

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

	return 0;

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

using namespace std;

char s[100001];

long long p=0,r=0,w=0,l=0;

int main()

{

    cin>>s;

    for (long long i=0;i<strlen(s);i++)

    {

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

        {

            if (p>=r)

            {

            l++;

            r++;

            }

            else

            p++;

        }

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

        {

            if (p<r)

            {

            p++;

            w++;

            }

            else

            r++;

        }

    }

    cout<<w-l<<endl;

    return 0; 

} 

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

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

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

				ans++;

			}

		}

	}

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

	return 0;

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

using namespace std;

char a[100005];

int x,y,ans;

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++;

		}

    }

    cout<<ans<<endl;

    return 0;

}

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

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

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

				ans++;

			}

		}

	}

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

	return 0;

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

using namespace std;

char a[200010];

int p,g,ans;

int main() {

	cin>>a;

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

		if(g==p) {

			g++;

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

				ans--;

		}

		else {

			p++;

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

				ans++;

		}

	}

	cout<<ans<<endl;

	return 0;

}

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

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

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

				ans++;

			}

		}

	}

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

	return 0;

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

#include<cstring>

#include <iostream>

#include <algorithm>

using namespace std;

int x,y,m,i;

int main()

{

    string c;

    cin>>c;

    for(;i<c.length();++i)

	    if(x<=y)

	    {

	        x++;

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

	    }

	    else

	    {

	        y++;

	        if(c[i]=='g')m++;

	    }

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

    return 0;

}

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

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

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

				ans++;

			}

		}

	}

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

	return 0;

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

#include<string>

#include<iostream> 

using namespace std;



int ans,flag;

string a;



int read()

{

	int x = 0, f = 1;

	char ch = getchar();

	for (; !isdigit(ch); ch = getchar())

	if (ch == '-') f = -1;

	for (; isdigit(ch); ch = getchar())

	x = x * 10 + ch - '0';

	return x * f;

}



int main()

{

	cin>>a;

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

	{

		flag=(flag+1)%2;

		if (flag==1)

		{

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

			ans--;

		}

		else

		{

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

			ans++;

		}

	}

	printf("%d",ans);

	return 0;

}

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

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

			if(str[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,ans=0;



int main()

{

    scanf("%s",a);

    int mm=strlen(a);

    for (int i=0;i<=mm;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.222246818374621x):
#include<cstdio>

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

			if(str[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 a;

	cin>>a;

	n=a.size();

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

		bool t;

		b=!b;

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

			t=1;

		}else if(a[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.267877360009003x):
#include<cstdio>

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

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

				ans++;

			}

		}

	}

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

	return 0;

}
// Slower C++ solution:
//666yuchen

#include<bits/stdc++.h>

using namespace std;

string st;

int ans,s,b;

int main()

{

  cin>>st;

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

    if(s==b){s++;if(st[i]=='p')ans--;}

      else{b++;if(st[i]=='g')ans++;}

  cout<<ans;

  return 0;

}

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

#include<string>

#include<string.h>

using namespace std;

char str[100005];

int main(){

	int ans=0;

	scanf("%s",str);

	int N=strlen(str);

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

		if(i%2==0){

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

				ans--;

			}

		}else{

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

				ans++;

			}

		}

	}

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

	return 0;

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

using namespace std;

char a[100005];

int x,y,ans;

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++;

		}

    }

    cout<<ans<<endl;

    return 0;

}

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

using namespace std;

string s;

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

int main(){

	cin>>s;

	len=s.length();

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

		if(x==y){

			x++;

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

		}

		else{

			y++;

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

		}

	}

	cout<<ans<<endl;

	return 0;

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

using namespace std;

char a[100005];

int x,y,ans;

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++;

		}

    }

    cout<<ans<<endl;

    return 0;

}

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

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

#include<cstring>

char str[100010];

int length,ans;

int main(){

	scanf("%s",str);

	length=strlen(str);

	ans=length/2;

	for(int i=0;i<length;i++) if(str[i]=='p') ans--;

	printf("%d",ans);

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

#include<cstring>

char str[100010];

int length,ans;

int main(){

	scanf("%s",str);

	length=strlen(str);

	ans=length/2;

	for(int i=0;i<length;i++) if(str[i]=='p') ans--;

	printf("%d",ans);

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

#include<cstring>

char str[100010];

int length,ans;

int main(){

	scanf("%s",str);

	length=strlen(str);

	ans=length/2;

	for(int i=0;i<length;i++) if(str[i]=='p') ans--;

	printf("%d",ans);

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

#include<cstring>

char str[100010];

int length,ans;

int main(){

	scanf("%s",str);

	length=strlen(str);

	ans=length/2;

	for(int i=0;i<length;i++) if(str[i]=='p') ans--;

	printf("%d",ans);

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

#include<cstring>

char str[100010];

int length,ans;

int main(){

	scanf("%s",str);

	length=strlen(str);

	ans=length/2;

	for(int i=0;i<length;i++) if(str[i]=='p') ans--;

	printf("%d",ans);

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

#include<cstring>

char str[100010];

int length,ans;

int main(){

	scanf("%s",str);

	length=strlen(str);

	ans=length/2;

	for(int i=0;i<length;i++) if(str[i]=='p') ans--;

	printf("%d",ans);

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

#include<cstring>

char str[100010];

int length,ans;

int main(){

	scanf("%s",str);

	length=strlen(str);

	ans=length/2;

	for(int i=0;i<length;i++) if(str[i]=='p') ans--;

	printf("%d",ans);

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

#include<cstring>

char str[100010];

int length,ans;

int main(){

	scanf("%s",str);

	length=strlen(str);

	ans=length/2;

	for(int i=0;i<length;i++) if(str[i]=='p') ans--;

	printf("%d",ans);

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

#include<cstring>

char str[100010];

int length,ans;

int main(){

	scanf("%s",str);

	length=strlen(str);

	ans=length/2;

	for(int i=0;i<length;i++) if(str[i]=='p') ans--;

	printf("%d",ans);

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

}