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

using namespace std;



#define rep(i,n) for(int i=0;i<(n);++i)

#define reps(i,n) for(int i=1;i<=(n);++i)

#define repr(i,n) for(int i=(n);i>=0;--i)

#define step(i,s,n,c) for(int i=(s);i<(n);i+=(c))

#define REP(i,s,n) for(int i=(s);i<(n);++i)

#define each(i,vec) for(auto i:vec)

#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;

#define int long long

#define itn int

#define pb push_back

#define eb emplace_back

#define m_p make_pair

#define m_t make_tuple

#define p_p(a,b) pb(m_p(a,b))

#define all(a) a.begin(),a.end()

#define SORT(a) sort(all(a))

#define RSORT(a) sort(all(a),greater<>())

#define UNIQUE(a) a.erase(unique(all(a)),a.end())

#define SZ(a) (signed)(a.size())

#define debg(a) cout<<#a<<" "<<a<<endl;

#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl

#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl

#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl

#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}

#define out(a) cout<<(a)<<endl

#define ENDL cout<<endl

#define YES cout<<"YES"<<endl

#define NO cout<<"NO"<<endl

#define Yes cout<<"Yes"<<endl

#define No cout<<"No"<<endl

#define fi first

#define se second

#define V vector

#define P pair

#define T tuple

#define PQ priority_queue

#define cont const auto

#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))

typedef long long ll;

typedef double D;

typedef long double LD;

typedef string str;

typedef vector<ll> VL;

typedef pair<ll,ll> PL;

typedef vector<pair<ll,ll>> VP;

typedef tuple<ll,ll,ll> T3;

typedef tuple<ll,ll,ll,ll> T4;

const signed INF = (1LL<<30);

const long long MOD = (1e9+7);

const long long LINF = (1LL<<60);

const long long LMAX = LLONG_MAX;

void YN(bool b){cout<<(b?"Yes":"No")<<endl;}

template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}

template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}

template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}

template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}



signed main(){

  cin.tie(0);

  ios::sync_with_stdio(false);

  cout<<fixed<<setprecision(10);

  

  str s;

  cin>>s;

  bool a=true;

  if(s[0]==s[1])a=false;

  if(s[1]==s[2])a=false;

  if(s[2]==s[3])a=false;

  out(a?"Good":"Bad");

  

  

  return 0;

}

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

int main(){

  char a,b,c,d;

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

  if( a==b || b==c || c==d )printf("Bad\n");

  else printf("Good\n");



  return 0;

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

#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long

#define double long double

#define endl "\n"

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pb(x) push_back(x)

#define mp(a,b) make_pair(a,b)

#define ms(v,x) memset(v,x,sizeof(v))

#define pii pair<int,int>

#define ff first

#define ss second

#define frr(i,n) for(int i=0;i<n;i++)

#define td(v) v.begin(),v.end()

#define inf 1000000000 // 1e9

#define M   1000000007 // 1e9 + 7

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}

int lcm(int a,int b){return (a*b)/gcd(a,b);}

int exp(int a,int b,int m){

    if(b==0) return 1;

    if(b==1) return mod(a,m);

    int k = mod(exp(a,b/2,m),m);

    if(b&1){

        return mod(a*mod(k*k,m),m);

    }

    else return mod(k*k,m);

}

main(){

    fastio;

    string s;

	cin >> s;

	if(s[0] == s[1] || s[1]==s[2] || s[2]==s[3]){

		cout << "Bad\n";

	}

	else cout << "Good\n";

    

}


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

#include <cstring>

#include <algorithm>

using namespace std;

const int maxd =1e5+10;

char s[maxd];

int main()

{

    // freopen("a.in","r",stdin);

    // freopen("k.out","w",stdout);

    scanf("%s",s);

    for(int i=1;s[i];i++)

        if(s[i] == s[i-1]){

            printf("Bad");

            return 0;

        }

    printf("Good");

    return 0;

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

#define int long long

using namespace std;



int32_t main(){

	ios::sync_with_stdio(false); cin.tie(0);

	string n;

	cin >> n;

    for(int i = 0; i < n.size()-1; ++i){

        if(n[i] == n[i+1]){

            cout << "Bad\n";

            return 0;

        }

    }

    cout << "Good\n";

}

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

#include <cstring>

#include <algorithm>

using namespace std;

const int maxd =1e5+10;

char s[maxd];

int main()

{

    // freopen("a.in","r",stdin);

    // freopen("k.out","w",stdout);

    scanf("%s",s);

    for(int i=1;s[i];i++)

        if(s[i] == s[i-1]){

            printf("Bad");

            return 0;

        }

    printf("Good");

    return 0;

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

#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long

#define double long double

#define endl "\n"

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pb(x) push_back(x)

#define mp(a,b) make_pair(a,b)

#define ms(v,x) memset(v,x,sizeof(v))

#define pii pair<int,int>

#define ff first

#define ss second

#define frr(i,n) for(int i=0;i<n;i++)

#define td(v) v.begin(),v.end()

#define inf 1000000000 // 1e9

#define M   1000000007 // 1e9 + 7

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}

int lcm(int a,int b){return (a*b)/gcd(a,b);}

int exp(int a,int b,int m){

    if(b==0) return 1;

    if(b==1) return mod(a,m);

    int k = mod(exp(a,b/2,m),m);

    if(b&1){

        return mod(a*mod(k*k,m),m);

    }

    else return mod(k*k,m);

}

main(){

    fastio;

    string s;

	cin >> s;

	if(s[0] == s[1] || s[1]==s[2] || s[2]==s[3]){

		cout << "Bad\n";

	}

	else cout << "Good\n";

    

}


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

	}

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

#define int long long

using namespace std;



int32_t main(){

	ios::sync_with_stdio(false); cin.tie(0);

	string n;

	cin >> n;

    for(int i = 0; i < n.size()-1; ++i){

        if(n[i] == n[i+1]){

            cout << "Bad\n";

            return 0;

        }

    }

    cout << "Good\n";

}

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

	}

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

#include <cstdio>

#include <map>

using namespace std;

map<char,int> arrs;

char arr[5];

int main(){

	scanf("%s",&arr);

	int s=1;

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

		if(arr[i]==arr[i-1]){

			s=0;

			break;

		}

	}

	if(s){

		cout<<"Good"<<endl;

	}else{

		cout<<"Bad"<<endl;

	}

	return 0;

} 

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

	}

}
// Slower C++ solution:
#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";

}

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

	}

}
// Slower C++ solution:
#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;



}


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

int main(){

	int a[4];

	int m=0,n;

scanf("%d",&n);

a[3]=n%10;

a[2]=n/10%10;

a[1]=n/100%10;

a[0]=n/1000;

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

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

	m++;

	if(m>0)

	printf("Bad\n");

	else

	printf("Good\n");

	return 0;

}
// Slower C++ solution:
#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;

}

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

int main(){

	int a[4];

	int m=0,n;

scanf("%d",&n);

a[3]=n%10;

a[2]=n/10%10;

a[1]=n/100%10;

a[0]=n/1000;

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

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

	m++;

	if(m>0)

	printf("Bad\n");

	else

	printf("Good\n");

	return 0;

}
// Slower C++ solution:
#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;



}


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

}
// Slower C++ solution:
#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;

}

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

}
// Slower C++ solution:
#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;

}

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

	}

}
// Slower C++ solution:
#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;

}

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

#include<cstring>

const int MAXN=100005;



char str[MAXN];



int main()

{

	scanf("%s",str);

	int n=strlen(str),cnt=0;

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

		cnt+=str[i]=='p';

	int ans=(n/2)-cnt;

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

	

	return 0;

}
// Slower C++ solution:
#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";

}


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

#include<cstring>

const int MAXN=100005;



char str[MAXN];



int main()

{

	scanf("%s",str);

	int n=strlen(str),cnt=0;

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

		cnt+=str[i]=='p';

	int ans=(n/2)-cnt;

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

	

	return 0;

}
// Slower C++ solution:
#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;

}


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

#include<cstring>

const int MAXN=100005;



char str[MAXN];



int main()

{

	scanf("%s",str);

	int n=strlen(str),cnt=0;

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

		cnt+=str[i]=='p';

	int ans=(n/2)-cnt;

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

	

	return 0;

}
// Slower C++ solution:
#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;

}

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

#include<vector>

#include<cstring>

#include<algorithm>

using namespace std;

const int MAXN=100005;

char s[MAXN];

int main()

{

	scanf("%s",s);

	int len=strlen(s);

	int ans=0;

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

	{

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

			ans--;

	}

	for(int i=(len+1)/2;i<len;i++)

	{

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

			ans++;

	}

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

}
// Slower C++ solution:
#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";

}


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

#include<vector>

#include<cstring>

#include<algorithm>

using namespace std;

const int MAXN=100005;

char s[MAXN];

int main()

{

	scanf("%s",s);

	int len=strlen(s);

	int ans=0;

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

	{

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

			ans--;

	}

	for(int i=(len+1)/2;i<len;i++)

	{

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

			ans++;

	}

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

}
// Slower C++ solution:
#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;

}


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

#include<vector>

#include<cstring>

#include<algorithm>

using namespace std;

const int MAXN=100005;

char s[MAXN];

int main()

{

	scanf("%s",s);

	int len=strlen(s);

	int ans=0;

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

	{

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

			ans--;

	}

	for(int i=(len+1)/2;i<len;i++)

	{

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

			ans++;

	}

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

}
// Slower C++ solution:
#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;

}

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

#include<cstring>

using namespace std;

#define MAXL 100000



char s[MAXL];



int main() {

	scanf("%s",s);

	int len=strlen(s),cnt=0;

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

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

			cnt++;

	printf("%d\n",len/2-cnt);

	return 0;

}
// Slower C++ solution:
#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";

}


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

#include<cstring>

using namespace std;

#define MAXL 100000



char s[MAXL];



int main() {

	scanf("%s",s);

	int len=strlen(s),cnt=0;

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

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

			cnt++;

	printf("%d\n",len/2-cnt);

	return 0;

}
// Slower C++ solution:
#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;

}


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

#include<cstring>

using namespace std;

#define MAXL 100000



char s[MAXL];



int main() {

	scanf("%s",s);

	int len=strlen(s),cnt=0;

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

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

			cnt++;

	printf("%d\n",len/2-cnt);

	return 0;

}
// Slower C++ solution:
#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;

}


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

#include<cstring>

using namespace std;

#define MAXL 100000



char s[MAXL];



int main() {

	scanf("%s",s);

	int len=strlen(s),cnt=0;

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

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

			cnt++;

	printf("%d\n",len/2-cnt);

	return 0;

}
// Slower C++ solution:
#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);

}


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

#include<cstring>

using namespace std;

#define MAXL 100000



char s[MAXL];



int main() {

	scanf("%s",s);

	int len=strlen(s),cnt=0;

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

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

			cnt++;

	printf("%d\n",len/2-cnt);

	return 0;

}
// Slower C++ solution:
#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;

}

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

}
// Slower C++ solution:
#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";

}


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

}