Problem:


Score : 300 points

Problem Statement

AtCoDeer the deer and his friend TopCoDeer is playing a game.
The game consists of N turns.
In each turn, each player plays one of the two gestures, Rock and Paper, as in Rock-paper-scissors, under the following condition:

(※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock).

Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors.

(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)

With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts.
Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score.

The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is g, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in p, TopCoDeer will play Paper in the i-th turn.

Constraints

1≦N≦10^5

N=|s|

Each character in s is g or p.

The gestures represented by s satisfy the condition (※).

Input

The input is given from Standard Input in the following format:

s

Output

Print the AtCoDeer's maximum possible score.

Sample Input 1

gpg

Sample Output 1

0

Playing the same gesture as the opponent in each turn results in the score of 0, which is the maximum possible score.

Sample Input 2

ggppgggpgg

Sample Output 2

2

For example, consider playing gestures in the following order: Rock, Paper, Rock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three victories and suffers one defeat, resulting in the score of 2, which is the maximum possible score.



Sample input:
gpg


Sample output:
0

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

int main()
{
  int N,T=0;
  string S;
  
  cin >> S;
  REP(i,S.size()){
    if(i%2 == 1){
      if(S[i] == 'g'){
        T++;
      }else
        continue;
    }else{
      if(S[i] == 'g'){
        continue;
      }else{
        T--;
      }
    }
  }
  cout << T << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
s = input()

score = 0
for i in range(len(s)):
  if i % 2 == 0 and s[i] = "p":
    score -= 1
  elif i % 2 != 0 and s[i] = "g":
    score += 1

print(s)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    N = len(S)

    @lru_cache(maxsize=None)
    def f(i, g):
        r = -sys.maxsize
        if i == N:
            return 0
        if g > 0:
            r = max(r, f(i+1, g-1) + (1 if S[i] == 'g' else 0))

        r = max(r, f(i+1, g+1) + (-1 if S[i] == 'p' else 0))

        return r

    return f(0, 0)


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
lis = list(input())
cou = 0
ans = 0
for i in range(len(lis)):
	if lis[i] == "g":
		if cou > 0:
        	cou -= 1
        	ans += 1
		else:
        	cou += 1
	else:
		if cou > 0:
        	cou -= 1
		else:
			cou += 1
			ans -= 1
print(max(0,ans))

Submission status: Runtime Error

Solution code:
lis = list(input())
cou = 0
ans = 0
for i in range(len(lis)):
	if lis[i] == "g":
      if cou > 0:
        cou -= 1
        ans += 1
      else:
        cou += 1
    else:
      if cou > 0:
        cou -= 1
      else:
        cou += 1
        ans -= 1
print(max(0,ans))

Submission status: Runtime Error

Solution code:
s = input()

P = 0
for c in s:
  if c == 'p':
    P += 1

print(N//2 - P)

Submission status: Runtime Error

Solution code:
#coding:utf-8

def win(p,e):
    if p=="g" and e=="p":
        return -1
    elif p=="p" and e=="g":
        return 1
    else:
        return 0

def f(e_str,pt,gt,i): 
    if len(e_str)<=i:
        return 0
    
    if pt+1<=gt:
        point_p=f(e_str,pt+1,gt,i+1)+win("p",e_str[i])
    else:
        point_p=-0xffff
        
    point_g=f(e_str,pt,gt+1,i+1)+win("g",e_str[i])
    return max(point_p,point_g)
    
e_str=list(input())
print(f(e_str,0,0,0))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

s = str(input())
n = len(s)

dic = dict()
for c in s:
	dic[c] = dic.get(c, 0) + 1

ans = (dic['g'] - dic['p']) // 2

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

s = str(input())
n = len(s)

G = 0
P = 0

dic = dict()
for c in s:
	dic[c] = dic.get(c, 0) + 1

if n % 2 == 0:
	ans = (dic['g'] - dic['p']) / 2
else:
	ans = (dic['g'] - dic['p'] - 1) / 2

print(int(ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

s = str(input())
n = len(s)

G = 0
P = 0

dic = dict()
for c in s:
	dic[c] = dic.get(c, 0) + 1

if n % 2 == 0:
	ans = n / 2 - dic['p']
else:
	ans = (n - 1) / 2 - dic['p']

print(int(ans))