stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

	string a;

	cin>>a;

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

	{

		if(a[i]==a[i-1])

		{

			cout<<"Bad";

			return 0;

		}

	}

	cout<<"Good";

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

	int n=4;

	char a[4];

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

	{

		scanf("%c",&a[i]);

	}

	if(a[0]==a[1]||a[1]==a[2]||a[2]==a[3])

	{

		printf("Bad");

	}

	else

	{

		printf("Good");

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main()

{

    string s;

    cin>>s;

    int i,count=0;

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

    {

        if(s[i]==s[i+1])

        count++;

    }

    if(count>=1)

        cout<<"Bad"<<endl;

    else

        cout<<"Good"<<endl;

    return 0;



}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main()

{

	int a=0,b=0,c=0,d=0;

	scanf("%1d%1d%1d%1d",&a,&b,&c,&d);

	if(a!=b&&b!=c&&c!=d)

	printf("Good\n");

	else

	printf("Bad\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <cstdio>

#include <iostream>

#include <cstring>

using namespace std;

int main()

{

	string s;

	cin >> s;

//	if(s.size()>4)

//	return 0;

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

	{

		if(s[i]==s[i+1])

		{

			cout << "Bad";

			return 0;

		}

	}

	cout << "Good";

		

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>

int main()

{

	int a=0,b=0,c=0,d=0;

	scanf("%1d%1d%1d%1d",&a,&b,&c,&d);

	if(a!=b&&b!=c&&c!=d)

	printf("Good\n");

	else

	printf("Bad\n");

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cstring>

#include <map>

using namespace std;

const int N=14;

const int INF=1e9;

string str[20],s[20];

int dp[20][1<<15],ok[20][20];

int n;

int check(int x,int y)

{

	int i,j,r=0,l1=s[x].size(),l2=s[y].size();

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

	{

		for(j=0;i+j<l1&&j<l2;j++)if(s[x][i+j]!=s[y][j])break;

		if(i+j==l1&&r<j)r=j;

	}

	return r;

}

bool ck(int x,int y)

{

	int l1=str[x].size(),l2=str[y].size();

	int i,j;

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

	{

		for(j=0;j<l1&&i+j<l2;j++)if(str[x][j]!=str[y][i+j])break;

		if(j==l1)return true;

	}

	return false;

}

int dfs(int x,int zt)

{



	if(dp[x][zt]!=-1)return dp[x][zt];

	dp[x][zt]=INF;

	int i;

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

	{

		if((zt&(1<<i))&&i!=x)

		{

			int t=dfs(i,zt-(1<<x))+s[x].size()-ok[i][x];



			if(dp[x][zt]>t)dp[x][zt]=t;

		}

	}



	return dp[x][zt];

}

int main()

{      

	int i,j,k;

	while(~scanf("%d",&n))

	{       

                memset(dp,-1,sizeof(dp));

		if(!n)break;

		for(i=0;i<n;i++)cin >> str[i];

		k=0;

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

		{

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

			{

				if(i!=j&&ck(i,j))break;

			}

			if(j==n)s[k++]=str[i];

		}



		n=k;

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

		{

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

			{

				ok[i][j]=check(i,j);

			}

		}

		

		for(i=0;i<n;i++)dp[i][1<<i]=s[i].size();

		int L=(1<<n);

		for(i=0;i<n;i++)dfs(i,L-1);

		int r=INF;

		for(i=0;i<n;i++)if(r>dp[i][L-1])r=dp[i][L-1];

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

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<iostream>

#include<cstring>

#include<cmath>

#include<queue>

#include<vector>

#include<map>

#include<cstdlib>

#include<string>

#include<algorithm>

#define mod 998244353;

using namespace std;

char c[25][25],s[25][25];

int n,d[25][25];

bool issub(int x)

{

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

	if(i!=x&&strstr(c[i],c[x])!=NULL)return true;

	return false;

}

int gdis(char a[],char b[])

{

	int n=strlen(a);

	int m=strlen(b);

	int ed=min(n,m);

	for(int i=ed;i>=0;i--)

	{

		bool flag=true;

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

		{

			if(a[n-i+j]!=b[j])

			{

				flag=false;

				break;

			}

		}

		if(flag) return i;

	 } 

	 return -1;

}

int len[25];

int dp[14][1<<14];

inline void Min(int &a,const int &b)

{

	if(a==-1||b<a)

	a=b;

}

int main()

{

	while(scanf("%d",&n),n)

	{

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

		scanf("%s",c[i]);

		int m=0;

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

		if(!issub(i))

		{

			strcpy(s[m],c[i]);

			m++;

	    } 

	    n=m;

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

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

		if(i!=j)

		{

			d[i][j]=gdis(s[i],s[j]);

		}

		memset(dp,-1,sizeof(dp));

		for(int i=0;i<n;i++)dp[i][1<<i]=len[i]=strlen(s[i]);

		int ed=(1<<n)-1;

		for(int j=1;j<ed;j++)

		{

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

			if(dp[i][j]!=-1)

			{

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

				if(!(j>>k&1))

				{

					Min(dp[k][j|(1<<k)],dp[i][j]+len[k]-d[i][k]);

				}

			}

		}

		int ans=-1;

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

		if(dp[i][ed]!=-1)

		Min(ans,dp[i][ed]);

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

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



signed main(){

	string s;

	cin >> s;

	int cntg = 0, cntp = 0, sc = 0;

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

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

			if(cntp < cntg){

				cntp++;

				sc++;

			}

			else

				cntg++;

		}

		else{

			if(cntp < cntg)

				cntp++;

			else{

				cntg++;

				sc--;

			}

		}

	}

	cout << sc;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char s[100002];

int n,sg,sp,ans;

int main()

{

	scanf("%s",s);

	n=strlen(s);

	sg=sp=0;

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

		if(i%2==1&&s[i]=='g')ans++;

		else	if(i%2==0&&s[i]=='p')ans--;

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main()

{

    string s;

    cin >> s;

    int preans=0;

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

    {

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

            preans++;

    }

    int ans=s.size()/2;

    cout << ans-preans << "\n";

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char s[100002];

int n,sg,sp,ans;

int main()

{

	scanf("%s",s);

	n=strlen(s);

	sg=sp=0;

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

		if(i%2==1&&s[i]=='g')ans++;

		else	if(i%2==0&&s[i]=='p')ans--;

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

	string s;

	long long ans;

	long long cntp=0;

	long long n;

	cin>>s;

	n=s.length();

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

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

			cntp++;

		}

	}

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

		ans=n/2-cntp-1;

	}

	else {

		ans=n/2-cntp;

	}

	cout<<ans;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char s[100002];

int n,sg,sp,ans;

int main()

{

	scanf("%s",s);

	n=strlen(s);

	sg=sp=0;

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

		if(i%2==1&&s[i]=='g')ans++;

		else	if(i%2==0&&s[i]=='p')ans--;

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <algorithm>

#include <iostream>

#include <iterator>

#include <cstdio>

#include <vector>

#include <cmath>

using namespace std;





#ifdef LOCAL

#define DEBUGMSG()                                                              \

{                                                                               \

    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]" ;        \

}

#define DEBUGVAR(x)                                                             \

{                                                                               \

    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]:" ;       \

    cerr << "([" << typeid(x).name() << "]" << #x << ")" << x << endl ;         \

}

#define DEBUGARR(l, r)                                                          \

{                                                                               \

    cerr << "[调试 @" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "]:" ;       \

    copy(l, r, ostream_iterator<decltype(*l)>(cerr, " "));                      \

    cerr << endl ;                                                              \

}

#else

#define DEBUGMSG()

#define DEBUGVAR(x)

#define DEBUGARR(l, r)

#endif // LOCAL



int N;

string str;



int main()

{

    int g = 0, p = 0;

    cin >> str ;



    for(string::iterator itr = str.begin(); itr != str.end(); itr++)

        if(*itr == 'p')

            p++;

        else

            g++;



    DEBUGVAR(p);

    DEBUGVAR(g);



    if(p >= g)

        cout << 0 << endl ;

    else

        cout << (g-p)/2 << endl ;



    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char s[100002];

int n,sg,sp,ans;

int main()

{

	scanf("%s",s);

	n=strlen(s);

	sg=sp=0;

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

		if(i%2==1&&s[i]=='g')ans++;

		else	if(i%2==0&&s[i]=='p')ans--;

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#include<string>

#include<iostream>

using namespace std;



typedef long long ll;



int n;

string s;



int main(){

    cin >> s;

    n=s.length();

    int t=0,cnt=n/2;

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

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

    cnt-=t;

    printf("%d",cnt);

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char s[100002];

int n,sg,sp,ans;

int main()

{

	scanf("%s",s);

	n=strlen(s);

	sg=sp=0;

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

		if(i%2==1&&s[i]=='g')ans++;

		else	if(i%2==0&&s[i]=='p')ans--;

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define pb push_back

typedef long long goo;

using namespace std;

int main()

{

    char ch=0;

    int p=0,g=0;

    while(ch!='\n'){

        ch=getchar();

        if(ch=='p') p++;

        if(ch=='g') g++;

    }

    cout<<(p+g)/2-p;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

char s[100002];

int n,sg,sp,ans;

int main()

{

	scanf("%s",s);

	n=strlen(s);

	sg=sp=0;

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

		if(i%2==1&&s[i]=='g')ans++;

		else	if(i%2==0&&s[i]=='p')ans--;

	printf("%d",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int main()

{

   char a[110000];

   scanf("%s",&a);

   int w=strlen(a);

   w=w/2;

   int k=0;

   int kk=0;

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

   {

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

       {

           k++;

       }

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

       {

           kk++;

       }

   }

if(k>=w)

{

    printf("%d\n",w-k);

}

else

{

   printf("%d\n",w-k);

}

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>



using namespace std ;



#define ll long long

#define N 100010



char s[ N ] ;

int cur1 , cur2 , ans ;



//rock和paper，paper赢

//同样则不加分 

//rock-g , paper-p



int main() {

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

	int n = strlen( s + 1 ) ;

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

	cur2 = 1 ;

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

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

			if( cur1 < cur2 ) {

				cur1 ++ ;

			}else ans -- , cur2 ++ ;

		}else {

			if( cur1 < cur2 ) {

				cur1 ++ ;

				ans ++ ;

			}else cur2 ++ ;

		}

	}

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

	return 0 ;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

} 


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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; 

} 

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;	

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;



}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int main(){

    bool b=0;

    int n,ans=0;

    string s;

    cin>>s;

    n=s.size();

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

        bool t;

        b=!b;

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

            t=1;

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

            t=0;

        }

        if(t==b){

            continue;

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

            ans++;

        }else{

            ans--;

        }

    }

    cout<<ans;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>



char ch[100002];



int i,ans,x,y;



int main(){

	scanf("%s",ch);

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

	{

		if(x==y){

			++x;

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

		}

		else if(x>y){

			++y;

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

		}

	}

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

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

string s;

long long n,m,m2,kt;

int main()

{

	cin>>s;

	n=s.length();

	m=0;

    kt=0;

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

    if(m==0)

    {

    	m++;

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

	}

	else

	  {

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

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

	  	{

	  		m--;

	  		kt++;

		}

	  }

	cout<<kt;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

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



char s[MAXN];



int main()

{

	int tb=0;

	scanf("%s",s);

	int len=strlen(s);

	int ans=0;

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

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

			ans--;

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

		else tb++;

	}

	printf("%d",ans);

}

// Fastest known solution for this problem: