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

using namespace std;

string s;

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

int main()

{

    cin>>s;

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

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

     else{y++; if(s[i]=='g') ans++;}

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

    return 0;

}

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

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

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.2377748798815176x):
#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

int main(){

	char s[100100];scanf("%s",s+1);

	int n=strlen(s+1),ans=0;

	for(int i=1,x=0,y=0;i<=n;i++)

		if(x==y) ans+=(s[i]=='g')-1,x++;

		else ans+=(s[i]=='g'),y++;

	cout<<ans;

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

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.2377748798815176x):
#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

int main(){

	char s[100100];scanf("%s",s+1);

	int n=strlen(s+1),ans=0;

	for(int i=1,x=0,y=0;i<=n;i++)

		if(x==y) ans+=(s[i]=='g')-1,x++;

		else ans+=(s[i]=='g'),y++;

	cout<<ans;

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

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.251776871781421x):
#include <bits/stdc++.h>

using namespace std;

string a;

int main()

{

	cin>>a;

	int l=a.size();

	int t1=0,t2=0,score=0;

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

		if(t1==t2)

		{

			t1++;

			if(a[i]=='p') score--;

		}else

		{

			t2++;

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

		}

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

	return 0;

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

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.251776871781421x):
#include <bits/stdc++.h>

using namespace std;

string a;

int main()

{

	cin>>a;

	int l=a.size();

	int t1=0,t2=0,score=0;

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

		if(t1==t2)

		{

			t1++;

			if(a[i]=='p') score--;

		}else

		{

			t2++;

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

		}

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

	return 0;

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

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.2513110605543913x):
#include <bits/stdc++.h>

#define ri register int

#define ll long long

using namespace std;

int read()

{

	int num=0;

	int flg=1;

	char c=getchar();

	while(!isdigit(c))

	{

		if(c=='-')

		{

			flg=-1;

		}

		c=getchar();

	}

	while(isdigit(c))

	{

		num=(num<<1)+(num<<3)+(c^48);

		c=getchar();

	}

	return num*flg;

}

const int maxn=1e6+7;

char str[maxn];

int main()

{

	scanf("%s",str);

	int tot=strlen(str);

	int stone=0;

	for(ri i=0; i<tot;i++)

	{

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

		{

			stone++;//对面出石头的数量

		}

	}

	int towel=tot>>1;//没法，只能硬核翻译了

	int win=min(towel,stone);

	int lose=min(tot-towel,tot-stone);

	return 0&printf("%d",win-lose);

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

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.2513110605543913x):
#include <bits/stdc++.h>

#define ri register int

#define ll long long

using namespace std;

int read()

{

	int num=0;

	int flg=1;

	char c=getchar();

	while(!isdigit(c))

	{

		if(c=='-')

		{

			flg=-1;

		}

		c=getchar();

	}

	while(isdigit(c))

	{

		num=(num<<1)+(num<<3)+(c^48);

		c=getchar();

	}

	return num*flg;

}

const int maxn=1e6+7;

char str[maxn];

int main()

{

	scanf("%s",str);

	int tot=strlen(str);

	int stone=0;

	for(ri i=0; i<tot;i++)

	{

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

		{

			stone++;//对面出石头的数量

		}

	}

	int towel=tot>>1;//没法，只能硬核翻译了

	int win=min(towel,stone);

	int lose=min(tot-towel,tot-stone);

	return 0&printf("%d",win-lose);

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

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.227353408685497x):
#include<bits/stdc++.h>

using namespace std;

int main() {

	string s;

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

	cin>>s;

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

		if (x==y) {

			x++;

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

		} else {

			y++;

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

		}

	}

	cout<<ans<<endl;

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

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.227353408685497x):
#include<bits/stdc++.h>

using namespace std;

int main() {

	string s;

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

	cin>>s;

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

		if (x==y) {

			x++;

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

		} else {

			y++;

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

		}

	}

	cout<<ans<<endl;

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

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.25040555952302x):
#include<bits/stdc++.h> 

using namespace std;

char a[100007];

int main()

{

  scanf("%s",a);

  int l=strlen(a),x=0,i;

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

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

	  x++;

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

  return 0;

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

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.25040555952302x):
#include<bits/stdc++.h> 

using namespace std;

char a[100007];

int main()

{

  scanf("%s",a);

  int l=strlen(a),x=0,i;

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

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

	  x++;

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

  return 0;

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

using namespace std;

#define int long long

#define fi first

#define se second

#define pb push_back

#define mp make_pair

#define endl "\n"

#define pque priority_queue



const int mod = 1000000007;



signed main(){

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	string s;

	cin >> s;

	int n = s.length(), cnt = 0;

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

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

		else cnt--;

	}

	cnt /= 2;

	cout << cnt;

}


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

#include<cstring>

#include<algorithm>

#include<cmath>

#define SF scanf

#define PF printf

#define MAXN 100010

char s[MAXN];

int main(){

	SF("%s",s);

	int n=strlen(s);

	int ans=0;

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

		if(i%2==0&&s[i]=='p')

			ans--;

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

			ans++;

	}

	PF("%d",ans);

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

#include <vector>

#include <stdio.h>

#include <string>



using namespace std;



typedef vector<int> vi;



string s;

int num = 0, res = 0;



int main()

{

    //freopen("inp.txt", "r", stdin);

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

    cin >> s;

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

    {

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

        {

            if (num == 0)

            {

                ++num;

            }

            else

            {

                ++res;

                --num;

            }

        }

        else

        {

            if (num == 0)

            {

                ++num;

                --res;

            }

            else

            {

                --num;

            }

        }

    }

    printf("%d",res);

    return 0;

}


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

#include<cstring>

#include<algorithm>

#include<cmath>

#define SF scanf

#define PF printf

#define MAXN 100010

char s[MAXN];

int main(){

	SF("%s",s);

	int n=strlen(s);

	int ans=0;

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

		if(i%2==0&&s[i]=='p')

			ans--;

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

			ans++;

	}

	PF("%d",ans);

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

#include <string.h>

using namespace std;



int main(){

    string s;

    int ans = 0;

    cin >> s;

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

    if(s.length() % 2 == 0) cout << (s.length() / 2) - ans;

    else cout << (s.length() - 1) / 2 - ans;

    return 0;

}

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

#include<cstring>

#include<algorithm>

#include<cmath>

#define SF scanf

#define PF printf

#define MAXN 100010

char s[MAXN];

int main(){

	SF("%s",s);

	int n=strlen(s);

	int ans=0;

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

		if(i%2==0&&s[i]=='p')

			ans--;

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

			ans++;

	}

	PF("%d",ans);

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

#include <algorithm>

#include <cstring>

using namespace std;

main ()

{

	char s[100005];

	int p=0, g=0, ans=0;

	cin >> s;

	int n = strlen (s);

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

	{

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

		{

			if (g>p)

			{

				ans++;

				p++;

			}

			else g++; 

		}

		else

		{

			if (g>p) p++;

			else

			{

				g++;

				ans--;

			}

		}

	}

	cout << ans;

}

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

#include<cstring>

#include<algorithm>

#include<cmath>

#define SF scanf

#define PF printf

#define MAXN 100010

char s[MAXN];

int main(){

	SF("%s",s);

	int n=strlen(s);

	int ans=0;

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

		if(i%2==0&&s[i]=='p')

			ans--;

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

			ans++;

	}

	PF("%d",ans);

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

using namespace std;

#define int long long

#define fi first

#define se second

#define pb push_back

#define mp make_pair

#define endl "\n"

#define pque priority_queue



const int mod = 1000000007;



signed main(){

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	string s;

	cin >> s;

	int n = s.length(), cnt = 0;

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

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

		else cnt--;

	}

	cnt /= 2;

	cout << cnt;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=1e5+5;

char s[N];

int main()

{

    int n;

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

    n=strlen(s+1);

    int cnt=0;

    int ans=0;

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

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

            if(cnt)

                ans++,cnt--;

            else

                cnt++;

        else

            if(cnt)

                cnt--;

            else

                ans--,cnt++;

    }

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

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

#include <vector>

#include <stdio.h>

#include <string>



using namespace std;



typedef vector<int> vi;



string s;

int num = 0, res = 0;



int main()

{

    //freopen("inp.txt", "r", stdin);

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

    cin >> s;

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

    {

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

        {

            if (num == 0)

            {

                ++num;

            }

            else

            {

                ++res;

                --num;

            }

        }

        else

        {

            if (num == 0)

            {

                ++num;

                --res;

            }

            else

            {

                --num;

            }

        }

    }

    printf("%d",res);

    return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=1e5+5;

char s[N];

int main()

{

    int n;

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

    n=strlen(s+1);

    int cnt=0;

    int ans=0;

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

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

            if(cnt)

                ans++,cnt--;

            else

                cnt++;

        else

            if(cnt)

                cnt--;

            else

                ans--,cnt++;

    }

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

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

#include <string.h>

using namespace std;



int main(){

    string s;

    int ans = 0;

    cin >> s;

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

    if(s.length() % 2 == 0) cout << (s.length() / 2) - ans;

    else cout << (s.length() - 1) / 2 - ans;

    return 0;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=1e5+5;

char s[N];

int main()

{

    int n;

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

    n=strlen(s+1);

    int cnt=0;

    int ans=0;

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

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

            if(cnt)

                ans++,cnt--;

            else

                cnt++;

        else

            if(cnt)

                cnt--;

            else

                ans--,cnt++;

    }

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

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

#include <algorithm>

#include <cstring>

using namespace std;

main ()

{

	char s[100005];

	int p=0, g=0, ans=0;

	cin >> s;

	int n = strlen (s);

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

	{

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

		{

			if (g>p)

			{

				ans++;

				p++;

			}

			else g++; 

		}

		else

		{

			if (g>p) p++;

			else

			{

				g++;

				ans--;

			}

		}

	}

	cout << ans;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;

const int N=1e5+5;

char s[N];

int main()

{

    int n;

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

    n=strlen(s+1);

    int cnt=0;

    int ans=0;

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

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

            if(cnt)

                ans++,cnt--;

            else

                cnt++;

        else

            if(cnt)

                cnt--;

            else

                ans--,cnt++;

    }

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

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

using namespace std;

#define int long long

#define fi first

#define se second

#define pb push_back

#define mp make_pair

#define endl "\n"

#define pque priority_queue



const int mod = 1000000007;



signed main(){

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	string s;

	cin >> s;

	int n = s.length(), cnt = 0;

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

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

		else cnt--;

	}

	cnt /= 2;

	cout << cnt;

}


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

#include<cstring>



#define MAXN 100000

char str[MAXN+5];



int main(){

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

    int N=strlen(str+1),Ans=0,r=0,p=0;

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

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

            if(p<r) Ans++,p++;

            else r++;

        }

        else{

            if(p<r) p++;

            else Ans--,r++;

        }

    }

    printf("%d",Ans);

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

#include <vector>

#include <stdio.h>

#include <string>



using namespace std;



typedef vector<int> vi;



string s;

int num = 0, res = 0;



int main()

{

    //freopen("inp.txt", "r", stdin);

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

    cin >> s;

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

    {

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

        {

            if (num == 0)

            {

                ++num;

            }

            else

            {

                ++res;

                --num;

            }

        }

        else

        {

            if (num == 0)

            {

                ++num;

                --res;

            }

            else

            {

                --num;

            }

        }

    }

    printf("%d",res);

    return 0;

}


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

#include<cstring>



#define MAXN 100000

char str[MAXN+5];



int main(){

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

    int N=strlen(str+1),Ans=0,r=0,p=0;

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

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

            if(p<r) Ans++,p++;

            else r++;

        }

        else{

            if(p<r) p++;

            else Ans--,r++;

        }

    }

    printf("%d",Ans);

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

#include <string.h>

using namespace std;



int main(){

    string s;

    int ans = 0;

    cin >> s;

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

    if(s.length() % 2 == 0) cout << (s.length() / 2) - ans;

    else cout << (s.length() - 1) / 2 - ans;

    return 0;

}

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

#include<cstring>



#define MAXN 100000

char str[MAXN+5];



int main(){

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

    int N=strlen(str+1),Ans=0,r=0,p=0;

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

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

            if(p<r) Ans++,p++;

            else r++;

        }

        else{

            if(p<r) p++;

            else Ans--,r++;

        }

    }

    printf("%d",Ans);

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

#include <algorithm>

#include <cstring>

using namespace std;

main ()

{

	char s[100005];

	int p=0, g=0, ans=0;

	cin >> s;

	int n = strlen (s);

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

	{

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

		{

			if (g>p)

			{

				ans++;

				p++;

			}

			else g++; 

		}

		else

		{

			if (g>p) p++;

			else

			{

				g++;

				ans--;

			}

		}

	}

	cout << ans;

}

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

#include<cstring>



#define MAXN 100000

char str[MAXN+5];



int main(){

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

    int N=strlen(str+1),Ans=0,r=0,p=0;

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

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

            if(p<r) Ans++,p++;

            else r++;

        }

        else{

            if(p<r) p++;

            else Ans--,r++;

        }

    }

    printf("%d",Ans);

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

using namespace std;

#define int long long

#define fi first

#define se second

#define pb push_back

#define mp make_pair

#define endl "\n"

#define pque priority_queue



const int mod = 1000000007;



signed main(){

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	string s;

	cin >> s;

	int n = s.length(), cnt = 0;

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

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

		else cnt--;

	}

	cnt /= 2;

	cout << cnt;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

#define N 100000

char s[N+5];

int a[N+5];

int main()

{

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

	int lens=strlen(s+1);

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

	{

		if(s[i]=='g') a[i]=1;

		else a[i]=-1;

	}

	int sum=0;

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

	sum+=a[i];

	printf("%d",sum/2);

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

#include <vector>

#include <stdio.h>

#include <string>



using namespace std;



typedef vector<int> vi;



string s;

int num = 0, res = 0;



int main()

{

    //freopen("inp.txt", "r", stdin);

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

    cin >> s;

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

    {

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

        {

            if (num == 0)

            {

                ++num;

            }

            else

            {

                ++res;

                --num;

            }

        }

        else

        {

            if (num == 0)

            {

                ++num;

                --res;

            }

            else

            {

                --num;

            }

        }

    }

    printf("%d",res);

    return 0;

}


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

#include<cstring>

#include<algorithm>

using namespace std;

#define N 100000

char s[N+5];

int a[N+5];

int main()

{

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

	int lens=strlen(s+1);

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

	{

		if(s[i]=='g') a[i]=1;

		else a[i]=-1;

	}

	int sum=0;

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

	sum+=a[i];

	printf("%d",sum/2);

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

#include <string.h>

using namespace std;



int main(){

    string s;

    int ans = 0;

    cin >> s;

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

    if(s.length() % 2 == 0) cout << (s.length() / 2) - ans;

    else cout << (s.length() - 1) / 2 - ans;

    return 0;

}

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

#include<cstring>

#include<algorithm>

using namespace std;

#define N 100000

char s[N+5];

int a[N+5];

int main()

{

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

	int lens=strlen(s+1);

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

	{

		if(s[i]=='g') a[i]=1;

		else a[i]=-1;

	}

	int sum=0;

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

	sum+=a[i];

	printf("%d",sum/2);

}