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: Accepted

Solution code:
s = input().rstrip()

gnum, pnum = 0,0
point = 0
for c in s:
    if c == "g":
        if gnum >= pnum+1:
            point += 1
            pnum += 1 
        else:
            gnum += 1
    elif c == "p":
        if gnum >= pnum+1:
            pnum += 1 
        else:
            gnum += 1
            point -= 1

print(point)

Submission status: Accepted

Solution code:
def atcodeer_and_rock_paper(s: str) -> int:
    score = 0
    for i, c in enumerate(s):
        if i % 2 == 0 and c == 'p':
            score -= 1
        elif i % 2 == 1 and c == 'g':
            score += 1
    return score


if __name__ == "__main__":
    s = input()
    ans = atcodeer_and_rock_paper(s)
    print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()

g = s.count("g")
p = s.count("p")
print(len(s)//2 - p)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()

g = s.count("g")
p = s.count("p")
if len(s) % 2 == 0:
	print(int(len(s)/2 - p))
else:
	print(int((len(s)-1)/2 - p))

Submission status: Accepted

Solution code:
s=[i for i in input()];g,p=s.count("g"),s.count("p");print((g-p)//2)

Submission status: Accepted

Solution code:
s = input()
a = 0
cg, cp = 0, 0
for c in s:
  if c == "p":
    if cg > cp:
      cp += 1
    else:
      cg += 1
      a -= 1
  else:
    if cg > cp:
      cp += 1
      a += 1
    else:
      cg += 1
print(a)

Submission status: Accepted

Solution code:
def main():
    s = input()
    ans = len(s)//2
    for c in s:
        if c == "p":
            ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()

ans = 0
for i in range(len(s)):
    if i % 2 == 0:  # グーを出す
        if s[i] == 'p': ans -= 1
    else:  # パーを出す
        if s[i] == 'g': ans += 1

print( ans )

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import copy
S=list(input())
N=len(S)
point=0
hand=copy.deepcopy(S)
panum=sum([j=="p" for j in hand])
pamax=N//2#ポイントの上限
pa=0
for i in range(N):
    if S[i]=="g" and pa<(i+1)//2 and point<pamax-panum:
        hand[i]="p"
        point+=1
    if point>=pamax-panum:
        break
    if hand[i]=="p":
        pa+=1
print(point)

Submission status: Accepted

Solution code:
s = input()
cnt_g = s.count("g")
cnt_p = s.count("p")

max_p = len(s)//2
print(max_p-cnt_p)

Submission status: Accepted

Solution code:
s = list(input())

n = len(s)
m = s.count('g')
x = n // 2 + n % 2

print(m - x)

Submission status: Accepted

Solution code:
s=input()
ct=0
for i in range(len(s)):
  if s[i]=='p':ct+=1
print((len(s)//2)-ct)

Submission status: Accepted

Solution code:
s = input()
print(len(s)//2 - s.count('p'))

Submission status: Accepted

Solution code:
s = input()
pa = 0
gu = 0
for i in range(len(s)):
  if s[i] == 'p':
    pa += 1
  else:
    gu += 1
print((gu-pa)//2)

Submission status: Accepted

Solution code:
s=input()
count=0
st=0
for i in s:
    if i == 'g':
        if st>0:
            count+=1
            st-=1
        else:
            st+=1
    else:
        if st>0:
            st-=1
        else:
            count-=1
            st+=1
print(count)

Submission status: Accepted

Solution code:
s = input()
g = 'g'
p = 'p'

last_p = s.rfind(p)
if last_p == -1:
    print(len(s) // 2)
else:
    tail_g_num = len(s) - last_p - 1
    s_to_last_p = s[:last_p+1]
    diff = s_to_last_p.count(g) - s_to_last_p.count(p)
    print((diff + tail_g_num) // 2)

Submission status: Accepted

Solution code:
hands = input()
ans = 0
for i, h in enumerate(hands):
  if i % 2 == 0:
    if h == "p":
      ans -= 1
  else:
    if h == "g":
      ans += 1
      
print(ans)

Submission status: Accepted

Solution code:
x=input()
n=int(len(x)/2)
a=0
for i in x:
     if i=='p':
          a+=1
print(n-a)

Submission status: Accepted

Solution code:
x=input()
n=int(len(x)/2)
a=0
ls=[]
def fun():
     for i in range(2):
          ls.append(i)
for i in x:
     if i=='p':
          a+=1
print(n-a)

Submission status: Accepted

Solution code:
used_g=0
ans=0

for i,j in enumerate(input()):
    if j=="g":
        if i-used_g<used_g:
            ans+=1
        else:
            used_g+=1
    else:
        if not i-used_g<used_g:
            ans-=1
            used_g+=1

print(ans)

Submission status: Accepted

Solution code:
s = input()
print(len(s) // 2 - s.count("p"))

Submission status: Accepted

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
N = len(S)

T = 'gp' * (N//2) + 'g' * (N%2)
cnt = 0
for i in range(N):
    if S[i] == 'g' and T[i] == 'p':
        cnt += 1
    elif S[i] == 'p' and T[i] == 'g':
        cnt -= 1
print(cnt)

Submission status: Accepted

Solution code:
tList = input().strip()

buffer = 0
ans = 0
for t in tList:
    if(buffer > 0):
        if(t == "g"):
            ans += 1
            buffer -= 1
        if(t == "p"):
            buffer -= 1
    else:
        if(t == "p"):
            ans -= 1
            buffer += 1
        if(t == "g"):
            buffer += 1
print(ans)

Submission status: Accepted

Solution code:
s=input()
print(-s.count('p')+len(s)//2)

Submission status: Accepted

Solution code:
S = input()
X = [('g' if i % 2 == 0 else 'p') for i in range(len(S))]

ans = 0
for s, x in zip(S, X):
    if s == 'g' and x == 'p':
        ans += 1

    if s == 'p' and x == 'g':
        ans -= 1

print(ans)

Submission status: Accepted

Solution code:
s = input()

p_count = 0
g_count = 0
win = 0

for i in list(s):
    if i == "g" and p_count + 1 <= g_count:
        p_count += 1
        win += 1
    elif i == "g":
        g_count += 1
    elif i == "p" and p_count + 1 <= g_count:
        p_count += 1
    else:
        g_count += 1
        win -= 1

print(win)

Submission status: Accepted

Solution code:
S = input()

cntP = 0
for s in S:
    if s=="p":
        cntP += 1

print(len(S)//2 - cntP)

Submission status: Accepted

Solution code:
s = [0 if i == 'g' else 1 for i in input()]
l = [0,1]
ans = 0
for i,v in enumerate(s):
    w = l[i%2]
    if w > v:
        ans += 1
    elif w < v:
        ans -= 1

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)

s = [i for i in s]
for i in range(n):
    if s[i] == "p":
        s[i] = 1
    else:
        s[i] = 0

d = [0]*n
d[0] = 0
gc = 1
pc = 0
for i in range(1, n):
    if gc-1 >= pc:
        d[i] = 1
        pc += 1
    else:
        d[i] = 0
        gc += 1

ans = 0
for i in range(n):
    ans += d[i]-s[i]

print(ans)

Submission status: Accepted

Solution code:
s = input()
ans = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == "p":
            ans -= 1
    else:
        if s[i] == "g":
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
s = input()
N = len(s)
if N % 2 == 0:
    print(N//2 - s.count('p'))

else:
    print(N//2 - s.count('p'))

Submission status: Accepted

Solution code:
s=input()

NOW=0
SCORE=0
for i in range(len(s)):
    if NOW==i-NOW:
        if s[i]=="g":
            SCORE+=0
        else:
            SCORE-=1

    else:
        if s[i]=="g":
            SCORE+=1
            NOW+=1
        else:
            SCORE+=0
            NOW+=1

print(SCORE)

Submission status: Accepted

Solution code:
s=input()
budet=0
point=0

for i in s:
  if i == "g":
    if budet==0:
      budet+=1
    else:
      budet-=1
      point+=1
  elif i =="p":
    if budet==0:
      budet+=1
      point-=1
    else:
      budet-=1
print(point)

Submission status: Accepted

Solution code:
s = input()
g_count = 0
p_count = 0
for c in s:
    if c == 'g':
        g_count += 1
    else:
        p_count += 1
print((g_count - p_count) // 2)

Submission status: Accepted

Solution code:
S = [1 if _ == 'p' else 0 for _ in input()]
N = len(S)
print(N // 2 - sum(S))

Submission status: Accepted

Solution code:
S = [1 if _ == 'p' else 0 for _ in input()]
N = len(S)
count_g = 0
count_p = 0
score = 0
for hand_t in S:
    if count_p < count_g:
        count_p += 1
        hand_a = 1
    else:
        count_g += 1
        hand_a = 0
    score += hand_a - hand_t

print(score)

Submission status: Accepted

Solution code:
import math
s=input()
l=len(s)
a="g"*math.ceil(l/2)+"p"*(l//2)
ans=0
for i in range(l):
  if a[i]==s[i]:
    pass
  elif a[i]=="g" and s[i]=="p":
    ans-=1
  else:
    ans+=1
print(ans)

Submission status: Accepted

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(score)

Submission status: Accepted

Solution code:
S=input()
p=0
g=0
for i in range(len(S)):
    if S[i]=="p":
        p+=1
    elif S[i]=="g":
        g+=1

if len(S)%2==0:
    print(int(len(S)/2)-p)
else:
    print(int((len(S)-1)/2)-p)

Submission status: Accepted

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

s = input()
print(len(s) // 2 - s.count('p'))

Submission status: Accepted

Solution code:
s=input()
N=len(s)
L=[0]*N
g=0
p=0
for i in range(N):
    if g<=p:
        L[i]='g'
        g+=1
    else:
        L[i]='p'
        p+=1
point=0
for i in range(N):
    if s[i]=='g' and L[i]=='p':
        point+=1
    elif s[i]=='p' and L[i]=='g':
        point-=1
print(point)

Submission status: Accepted

Solution code:
s=list(input())
print((len(s)-s.count('p')*2)//2)

Submission status: Accepted

Solution code:
s = list(input())
print((s.count('g') - s.count('p'))//2)

Submission status: Accepted

Solution code:
s = list(input())
count = 0
for i in s:
    if i == 'g':
        count += 1
    else:
        count -= 1
print(count//2)

Submission status: Accepted

Solution code:
def solve(s):
    return len(s) // 2 - s.count("p")


if __name__ == "__main__":
    print(solve(input()))

Submission status: Accepted

Solution code:
s = input()
p = g = win = lose = 0
for x in s:
    if x == 'g':
        if p < g:
            p += 1
            win += 1
        else:
            g += 1
    elif x == 'p':
        if p < g:
            p += 1
        else:
            g += 1
            lose += 1
print(win - lose)

Submission status: Accepted

Solution code:
S = input()
p = 0
N = len(S)
for i in range(N):
    if S[i] == "p":
        p += 1

print(N // 2 - p)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
from math import floor,ceil
S = 'g'*ceil(n/2)+'p'*floor(n/2)
ans = 0
for i in range(len(s)):
    if s[i]=='g' and S[i]=='p':
        ans += 1
    elif s[i]=='p' and S[i]=='g':
        ans -= 1
print(ans)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
res=0
tg,tp=0,0
for i in range(n):
    if s[i]=="g":
        if tg>tp:
            tp+=1
            res+=1
        else:
            tg+=1
    else:
        if tg>tp:
            tp+=1
        else:
            tg+=1
            res-=1
print(res)

Submission status: Accepted

Solution code:
ar = list(input())
g = 0
p = 0
count = 0
for a in ar:
    if a == "g" and p + 1 <= g:
        count += 1
        p += 1
    elif a == "g" and p == g:
        g += 1
    elif a == "p" and p + 1 <= g:
        p += 1
    elif a == "p" and p == g:
        count -= 1
        g += 1
print(count)

Submission status: Accepted

Solution code:
#len(s)//2-s.count("p")
def 解():
    iG = 0
    iR = 0
    for s in input().rstrip():
        if s == "g" :
            if 0 < iG:
                iR += 1
                iG -= 1
            else:
                iG += 1
        else:
            if 0 < iG:
                iG -= 1
            else:
                iR -= 1
                iG += 1
    print(iR)
解()

Submission status: Accepted

Solution code:
#len(s)//2-s.count("p")
iG = 0
iR = 0
for s in input().rstrip():
    if s == "g" :
        if 0 < iG:
            iR += 1
            iG -= 1
        else:
            iG += 1
    else:
        if 0 < iG:
            iG -= 1
        else:
            iR -= 1
            iG += 1
print(iR)

Submission status: Accepted

Solution code:
#len(s)//2-s.count("p")
iG = 0
iR = 0
for g in [int(_) for _ in list(input().rstrip().replace("g","1").replace("p","0"))]:
    if g :
        if 0 < iG:
            iR += 1
            iG -= 1
        else:
            iG += 1
    else:
        if 0 < iG:
            iG -= 1
        else:
            iR -= 1
            iG += 1
print(iR)

Submission status: Accepted

Solution code:
#len(s)//2-s.count("p")

iG = 0
iP = 0
iR = 0
for s in input().rstrip():
    if s == "g":
        if iP < iG:
            iR += 1
            iP += 1
        else:
            iG += 1
    else:
        if iP < iG:
            iP += 1
        else:
            iR -= 1
            iG += 1

print(iR)

Submission status: Accepted

Solution code:
a=input()
x=0;y=0
ans=0
for i in range(len(a)):
    if(x==y):
        x=x+1
        if(a[i]=='p'):
            ans=ans-1
    else:
        y=y+1
        if(a[i]=='g'):
            ans=ans+1
print(ans)

Submission status: Accepted

Solution code:
s = input().rstrip()

iG = 0
iP = 0
iR = 0
for i in range(len(s)):
    if s[i] == "g":
        if iP < iG:
            iR += 1
            iP += 1
        else:
            iG += 1
    elif s[i] == "p":
        if iP < iG:
            iP += 1
        else:
            iR -= 1
            iG += 1

print(iR)

Submission status: Accepted

Solution code:
s=input()
ans=0
y=0
for i in range(len(s)):
    if(s[i]=='g'):
        if(y>0):
            ans=ans+1
            y=y-1
        else:
            y=y+1
    else:
        if(y>0):
            y=y-1
        else:
            y=y+1
            ans=ans-1
print(ans)

Submission status: Accepted

Solution code:
s = input()
print((s.count("g")-s.count("p"))//2)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    S = input()

    ans = 0
    for i, c in enumerate(S):
        if i < ceil(len(S), 2):
            h = "g"
        else:
            h = "p"

        if c == h:
            continue
        elif c == "g" and h == "p":
            ans += 1
        elif c == "p" and h == "g":
            ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
P = 0
for i in range(len(s)):
    if s[i] == "p":
        P += 1
print(len(s) //2 - P)

Submission status: Accepted

Solution code:
s = input()
paa,goo = 0,0
res = 0

for c in s:
    if c=='g':
        if paa+1<=goo:
            res += 1
            paa += 1
        else:
            goo += 1
    else:
        if paa+1<=goo:
            paa += 1
        else:
            goo += 1
            res -= 1

print(res)

Submission status: Accepted

Solution code:
S = list(input())
G = 0
P = 0
w = 0
l = 0
d = 0
for i in range(len(S)):
    if G == P: #G only
        G += 1
        if S[i] == "p":
            l += 1
        if S[i] == "g":
            d += 1
    elif S[i] == "g":
        P += 1
        w += 1
    elif S[i] == "p":
        P += 1
        d += 1
print(w - l)

Submission status: Accepted

Solution code:
s=input()
p_count=0 #パーが何回出せるか
total=0
for i in range(len(s)):
    if s[i]=="g" and p_count>=1:
        p_count-=1
        total+=1
    elif s[i]=="g" and p_count==0:
        p_count+=1
    elif s[i]=="p" and p_count==0:
        p_count+=1
        total-=1
    elif s[i]=="p" and p_count>=1:
        p_count-=1
print(total)

Submission status: Accepted

Solution code:
s = input()
print((s.count('g') - s.count('p')) // 2)

Submission status: Accepted

Solution code:
S = input()
import collections
print((len(S) // 2) - collections.Counter(S)['p'])

Submission status: Accepted

Solution code:
s = input()

g, p = 0, 0
ans = 0
for s_i in s:
    if s_i == 'g':
        if g > p:
            p += 1
            ans += 1
        else:
            g += 1
    else:
        if g > p:
            p += 1
        else:
            g += 1
            ans -= 1
print(ans)

Submission status: Accepted

Solution code:
S = input()
score = 0
g = 0
for s in S:
    if s == 'g':
        if g > 0:
            g -= 1
            score += 1
        else:
            g += 1
    else:
        if g > 0:
            g -= 1
        else:
            g += 1
            score -= 1
print(score)

Submission status: Accepted

Solution code:
import math
s = input()
np = 0
for i in range(len(s)):
    if s[i] == 'p':
        np += 1
print(math.floor(len(s) / 2) - np)

Submission status: Accepted

Solution code:
def d_atcodeer_and_rock_paper(S):
    return len(S) // 2 - S.count('p')

S = input().strip()
print(d_atcodeer_and_rock_paper(S))

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    S = input()

    np = S.count("p")

    print((len(S) // 2) - np)


main()

Submission status: Accepted

Solution code:
s = input()

count = 0
for i in s:
    if i == "p":
        count += 1

print(len(s)//2 - count)

Submission status: Accepted

Solution code:
s = input()
n = len(s)

ret = 0
for i, si in enumerate(s):
    if i % 2 == 0:
        ret += -1 if si == 'p' else 0
    else:
        ret += 1 if si == 'g' else 0

print(ret)

Submission status: Accepted

Solution code:
S = input()
score = 0
for i,c in enumerate(S):
    if i%2:
        score += int(c=='g')
    else:
        score += int(c=='g') - 1
print(score)

Submission status: Accepted

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):
    p = S.count('p')
    return len(S)//2 - p


def main():
    S = read_str()
    print(slv(''.join(S)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 11 15:57:04 2018
ABC046D
@author: maezawa
"""
import collections

s = input()
n = len(s)
np = n // 2
ng = n - np

c = collections.Counter(s)
#print(c)
win = (c['g'] - ng -(c['p'] - np))//2
print(win)

Submission status: Accepted

Solution code:
s=input()
g=p=a=0
for t in s:
  if t=='g':
    g+=1
  else:
    if p<g:
      p+=1
    else:
      g+=1
      a-=1
print(a+(g-p)//2)

Submission status: Accepted

Solution code:
s = list(raw_input())

one = s.count("p")
zero = s.count("g")

print (zero - one)/2

Submission status: Accepted

Solution code:
s = input()
p = 0
g = 0
score = 0
for i in range(len(s)):
    if (g - p) >= 1:
        p += 1
        if s[i] == 'g':
            score += 1
    else:
        g += 1
        if s[i] == 'p':
            score -= 1
print(score)

Submission status: Accepted

Solution code:
s = list(input())
print(len(s)//2 - s.count('p'))

Submission status: Accepted

Solution code:
s = input()

g_num = s.count("g")
print(g_num - (len(s)+1)//2)

Submission status: Accepted

Solution code:
s = input()
l = len(s)
i = 0
ans = 0
while i < l:
  if i%2==0 and s[i]=='p':
    ans += -1
  elif i%2==1 and s[i]=='g':
    ans += 1
  i += 1
print(ans)

Submission status: Accepted

Solution code:
s = input()

p_point = 0
point = 0

for j in s:
  if j == 'g':
    if p_point > 0:
      point += 1
      p_point -= 1
    else:
      p_point += 1
  else:
    if p_point > 0:
      p_point -= 1
    else:
      point -= 1
      p_point += 1

print(point)

Submission status: Accepted

Solution code:
t=input()
tp=t.count("p")
ap=len(t)//2
print(ap-tp)

Submission status: Accepted

Solution code:
s = input()
n = len(s)

ans = 0
for i in range(1, n):
    if i%2 != 0:
        if s[i] == 'g':
            ans += 1
    else:
        if s[i] == 'p':
            ans -= 1
print(ans)

Submission status: Accepted

Solution code:
S=input()
g=S.count("g")
p=len(S)-g
print((g-p)>>1)

Submission status: Accepted

Solution code:
s = input()

g = 0
ans = 0

for h in s:
  if g > 0:
    if h == 'g':
      ans += 1
    g -= 1
  else:
    if h == 'p':
      ans -= 1
    g += 1
    
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return list(map(int, input().split()))

S = input()
A = len(S)//2
C = Counter(S)
print(A - C["p"])

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem D


if __name__ == '__main__':
    s = input()
    print(len(s) // 2 - s.count('p'))

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem D


def execute_janken(self, other):
    if self == 'p' and other == 'g':
        return 1
    elif self == 'g' and other == 'p':
        return -1
    else:
        return 0


if __name__ == '__main__':
    s = input()
    p_count = 0
    g_count = 0
    score = 0
    hand = ''

    for si in s:
        if p_count == g_count:
            hand = 'g'
            g_count += 1
        elif p_count < g_count:
            hand = 'p'
            p_count += 1

        score += execute_janken(self=hand, other=si)

    print(score)

Submission status: Accepted

Solution code:
s = input()
ans = 0
for i in range(len(s)):
  if i % 2 == 0 and s[i] == 'p':
    ans -= 1
  elif not i % 2 == 0 and s[i] == 'g':
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
S = input()
score = 0
for i,b in enumerate(S):
    a = 'gp'[i%2]
    if (a,b) == ('p','g'):
        score += 1
    elif (a,b) == ('g','p'):
        score -= 1
print(score)

Submission status: Accepted

Solution code:
from collections import Counter
c = Counter(list(input().strip()))
print((c['g']-c['p'])//2)

Submission status: Accepted

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

s = list(str(input()))
num_paper = len(s) // 2
print(num_paper - s.count('p'))

Submission status: Accepted

Solution code:
TopCoDeer = list(input())
n = len(TopCoDeer)
p_num = TopCoDeer.count("p")

print((n // 2) - p_num)

Submission status: Accepted

Solution code:
s = input()
print(len(s) // 2 - s.count('p'))

Submission status: Accepted

Solution code:
cp,score = 0,0
for s in input():
    if s == "g":
        if cp > 0:
            score += 1
            cp -= 1
        else:
            cp += 1
    elif s == "p":
        if cp > 0:
            cp -= 1
        else:
            score -= 1
            cp += 1
print(score)

Submission status: Accepted

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: Accepted

Solution code:
s = input()
answer = 0
for i in range(len(s)):
	if i%2==0: x="g"
	else: x="p"
	if s[i]=="g" and x=="p": answer += 1
	elif s[i]=="p" and x=="g": answer -= 1
print(answer)

Submission status: Accepted

Solution code:
S=raw_input()
len=len(S)
str=""

if len%2==0:
	str="g"*(len/2)+"p"*(len/2)
else:
	str="g"*(len/2+1)+"p"*(len-(len/2+1))

ans=0
for i in range(len):
	if S[i]=="g" and str[i]=="p":
		 ans+=1
	elif S[i]=="p" and str[i]=="g":
		 ans-=1
	else:
		pass
print ans

Submission status: Accepted

Solution code:
S = list(input())

cnt_g = 0
cnt_p = 0
ans = 0

for s in S:
    if cnt_p < cnt_g:
        if s == "g":
            cnt_p += 1
            ans += 1
        else:
            cnt_p += 1
    else:
        if s == "g":
            cnt_g += 1
        else:
            cnt_g += 1
            ans -= 1

print(ans)

Submission status: Accepted

Solution code:
s = input()
dic = { 'g' : 0 ,'p' : 0 }
for ch in s:
	if ch == 'g':
		dic['g'] += 1
	else:
		dic['p'] += 1

print((dic['g'] - dic['p']) // 2)

Submission status: Accepted

Solution code:
S=input()

ans=0
for i in range(len(S)):
  if i%2==0:
    if S[i]=='p':
      ans-=1
  else:
    if S[i]=='g':
      ans+=1

print(ans)

Submission status: Accepted

Solution code:
def d_AtCoDeer_and_RockPaper(S):
    # 解説どおり
    n = len(S)  # ターン数
    p = 0  # 相手がパーを出した回数
    for c in S:
        if c == 'p':
            p += 1
    return n // 2 - p

S = input().strip()
print(d_AtCoDeer_and_RockPaper(S))

Submission status: Accepted

Solution code:
s = input()
tp = s.count("p")
print(len(s)//2-tp)

Submission status: Accepted

Solution code:
s=input()
N=len(s)
P=s.count('p')
print(N//2-P)