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.

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    s = input()
    n = len(s)
    par_counter = s.count('p')
    print(n // 2 - par_counter)


if __name__ == "__main__":
    main()

Solution (Python):
s = input()

p = 0
for x in s:
  if x == 'p':
    p += 1
    
print(len(s)//2 - p)

Solution (Python):
s = input()
p = 0
cnt = 0
for i in s:
    if i == 'g':
        if p > 0:
            cnt += 1
            p -= 1
        else:
            p += 1
    elif i == 'p':
        if p > 0:
            p -= 1
        else:
            cnt -= 1
            p += 1
print(cnt)

Solution (Python):
s=input()

cnt=0
result=0

hand=["g","p"]

for index,ss in enumerate(s):
    if ss!=hand[index%2]:
        if ss=="g":
            result+=1
        else:
            result-=1

print(result)

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

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

g, p = 0, 0
ans = 0
for i in range(n):
  if g == p:
    g += 1
    if s[i] == "p":
      ans -= 1
  else:
    p += 1
    if s[i] == "g":
      ans += 1

print(ans)

Solution (Python):
s = input()

g = 0
p = 0
win = 0
lose = 0

for hand in s:
    if p == g:
        g += 1
        if hand == 'p':
            lose += 1
    else:
        p += 1
        if hand == 'g':
            win += 1

print(win-lose)

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

Solution (Python):
s = input()

ans = 0

for i in range(len(s)):
    if s[i] == 'g':
        ans += 1
    else:
        ans -= 1
        
print(ans//2)

Solution (Python):
s = list(input())

n = len(s)

p = n//2

opp_p = s.count("p")

print(p-opp_p)

Solution (Python):
s=input()
N=len(s)
gcount=0
pcount=0

def janken(me,you):
    if (me=="g")and(you=="p"):
        return -1
    elif (me=="p")and(you=="g"):
        return 1
    else:
        return 0
score=0
for i in range(N):
    if gcount==pcount:
        score=score+janken("g",s[i])
        gcount=gcount+1
    else:
        score=score+janken("p",s[i])
        pcount=pcount+1
print(score)

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

Solution (Python):
s = input()
N = len(s)
ans = N//2
for i in range(N):
  if(s[i] == 'p'):
    ans -= 1
print(ans)

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

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

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

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

Solution (Python):
s = input()

ctr = {"g": 0, "p": 0}
ans = 0
for i in range(len(s)):
    if s[i] == "g":
        if ctr["p"] < ctr["g"]:
            ctr["p"] += 1
            ans += 1
        else:
            ctr["g"] += 1
    else:
        
        if ctr["p"] < ctr["g"]:
            ctr["p"] += 1
        else:
            ctr["g"] += 1
            ans -= 1
            
print(ans)

Solution (Python):
s = input()
N = len(s)
ans = 0
for c in s:
    if c == "p":
        ans -= 1
ans += N // 2
print(ans)

Solution (Python):
s=input()

atd=''
tpd=''
for i, t in enumerate(s):
  
  if t=='g':
      tpd+='0'
  else:
      tpd+='1'
      
  if i%2==0:
      atd+='0'
  else:
      atd+='1'

point=0
for a, t in zip(atd, tpd):
  
    x=int(a)-int(t)
    
    if x==1:
        point+=1
    elif x==-1:
      point-=1
      
      
print(point)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



s = input()
cntg = s.count("g")
cntp = s.count("p")
ans = max(0, cntg - cntp) // 2
print(ans)

Solution (Python):
def main():
  s = input()
  cc_g = cc_p = 0
  for c in s:
    if c == 'g': cc_g += 1
    else: cc_p += 1
  print((cc_g - cc_p) // 2)
  return

if __name__ == '__main__':
  main()

Solution (Python):
s = input()
l = len(s)
cp = s.count("p")
cg = l - cp
pmax = l//2
print(pmax-cp)

Solution (Python):
ans = 0

for i,c in enumerate(input()):
  if i%2 == 0 and c == "p": ans -= 1
  elif i%2 == 1 and c == "g": ans += 1

print(ans)

Solution (Python):
T = input().strip()
n = len(T)

p = n // 2
g = n - p

A = 'g' * g + 'p' * p

ans = 0
for a, t in zip(A, T):
    if a == 'p' and t == 'g':
        ans += 1
    if a == 'g' and t == 'p':
        ans -= 1

print(ans)

Solution (Python):
S = input()
N = len(S)
print(N // 2 - sum([int(s == 'p') for s in S]))

Solution (Python):
s = input()

gs = 0
ps = 0

for ss in s:
    if ss == 'g':
        gs += 1
    else:
        ps += 1

print(max(0,(gs - ps) // 2))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    s = input().rstrip()
    n = len(s)
    res = 0
    for i in range(n):
        if i <= (n-1)//2:
            if s[i]=='p':
                res -= 1
        else:
            if s[i] == 'g':
                res += 1
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
s = input()
slist = list(s)

gs = slist.count("g")
ps = slist.count("p")

if len(slist) % 2==0:
    res = (gs-ps)//2
    
else:
    res= (gs-1-ps)//2

print(res)

Solution (Python):
s = input()
r = 0
p = 0
score = 0
for x in s:
    if x == "g":
        if p < r:
            p += 1
            score += 1
        else:
            r += 1
    else:
        if p < r:
            p += 1
        else:
            score -= 1
            r += 1
print(score)

Solution (Python):
from collections import Counter
s = input()
count = Counter(s)
ans = 0
for i in s[::-1]:
    if i == 'g':
        if count['g'] >= count['p'] + 2:
            ans += 1
            count['g'] -= 1
            count['p'] += 1
print(ans)

Solution (Python):
S = input()

g = 0
p = 0
cnt = 0
for s in S:
    if s == 'g':
        if g > p:
            p += 1
            cnt += 1
        else:
            g += 1
    else:
        if g > p:
            p += 1
        else:
            g += 1
            cnt -= 1

print(cnt)

Solution (Python):

import io
data=input()
g=data.count('g')
p=data.count('p')
result=(-p+(g+p)//2)
print(result)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = input()[:-1]

po = 0

for i in range(len(s)):
    if s[i] == "p":
        po += 1
    

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

Solution (Python):

import math

s = input()
ans = math.floor(len(s)/2) - s.count("p")
print(ans)

Solution (Python):
S = input()
print(len(S) // 2 - S.count("p"))

Solution (Python):
s = list(input())
T_g = s.count("g")
T_p = s.count("p")

if T_g == T_p or T_g == T_p+1:
  result = 0
  print(result)
  exit()
else:
  P = (T_g + T_p) // 2
  result = P - T_p
  print(result)

Solution (Python):
s = str(input().rstrip())

def battle(s1, s2):
    l = {'g': {'g': 0, 'p': -1}, 'p': {'g': 1, 'p': 0}}
    return l[s1][s2]

hist = ['g']

g = 1
p = 0
ans = 0
if s[0] == 'p':
    ans = -1
for i in range(1, len(s)):
    cur = 'g'
    if s[i] == 'g':
        if p < g:
            cur = 'p'
    if s[i] == 'p':
        if p < g:
            cur = 'p'

    if cur == 'p':
        p += 1
    else:
        g += 1
    hist.append(cur)
    ans += battle(cur, s[i])



print(ans)

Solution (Python):
s=input()

s= list(s)

ans = 0

for i ,j in enumerate(s):
    if i%2==0 and j == 'p':
        ans -= 1
    elif i%2==1 and j == 'g':
        ans += 1
print(ans)

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

Solution (Python):
s = input()

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

Solution (Python):
s=input()

cnt=0
ans=0
for i in range(len(s)):
    if s[i]=='g':
        if cnt>0:
            ans+=1
            cnt-=1
        elif cnt==0:
            cnt+=1
    else:
        if cnt==0:
            ans-=1
            cnt+=1
        else:
            cnt-=1
print(ans)

Solution (Python):
S=input().strip()
print(len(S)//2-S.count('p'))

Solution (Python):
s=input()
n=len(s)
r=0
p=0
ans=0
for i in s:
    if i=='g':
        if r>=p+1:
            ans+=1
            p+=1
        else:
            r+=1
    else:
        
        if r>=p+1:
            p+=1
        else:
            r+=1
            ans-=1
print(ans)

Solution (Python):
s = input()
g_c = s.count("g")
p_c = s.count("p")
g_c = g_c - p_c
print(int(g_c / 2))

Solution (Python):
s=input()
N=len(s)
par=N//2
for i in range(0,N):
    if s[i]=='p':
        par-=1
print(par)

Solution (Python):
S = input()
counter = 0
for i in range(len(S)):
  if i%2==1:
    if S[i]=='g':
      counter += 1
  else:
    if S[i] =='p':
      counter -= 1
print(counter)

Solution (Python):
S = input()
cp, cg = 0, 0
ans = 0
for s in S:
    if s == 'g':
        if cp < cg:
            cp += 1
            ans += 1
        else:
            cg += 1
    elif s == 'p':
        if cp < cg:
            cp += 1
        else:
            cg += 1
            ans -= 1
print(ans)

Solution (Python):
s = list(str(input()))

T = 0
for i in range(len(s)):
    if s[i] == "p":
        T += 1

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

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

Solution (Python):

from sys import stdin
from operator import itemgetter
import math


s = stdin.readline().rstrip()

v = [s[i] for i in range(0, len(s))]

g = v.count('g')
p = v.count('p')

print((g-p)//2)

Solution (Python):

from sys import stdin
from operator import itemgetter
import math


s = stdin.readline().rstrip()

v = [s[i] for i in range(0, len(s))]

g = v.count('g')
p = v.count('p')

print((g-p)//2)

Solution (Python):
import collections
s = input()
t = list(s)

ssgn=lambda x:(x*2+1)//2
gg = round(ssgn(len(t)/2))
pp = len(t) - gg

d = collections.Counter(t)
Top_g = d['g']
Top_p = d['p']
print(pp - Top_p)

Solution (Python):
s=input()
print(s.count("g")-(len(s)+1)//2)

Solution (Python):
s=input()
g=s.count("g")
l=len(s)
print(l//2+g-l)

Solution (Python):
s=input()
c=False
a=0
for i in s:
    if i=="g" and c:
        a+=1
    elif i=="p" and not c:
        a-=1
    c=not c
print(a)

Solution (Python):
s=str(input())
cnt=0
ans=0
for i in range(len(s)):
  if cnt<=((i+1)//2 if i%2==0 else (i+1)//2-1):
    cnt+=1
    if s[i]=='p':
      ans-=1
  else:
    if s[i]=='g':
      if i+1<=len(s)-1 and s[i+1]=='p' and cnt<=((i+2)//2 if (i+1)%2==0 else (i+2)//2-1):
        cnt+=1
      else:
        ans+=1
    else:
      pass
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
INF = 10**10
MOD = 10**9 + 7
sys.setrecursionlimit(100000000)
from functools import lru_cache
from itertools import permutations
from math import factorial


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

if __name__=='__main__':
    main()

Solution (Python):


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    s=input()
    ng=s.count("g")
    np=len(s)-ng
    print((ng-np)//2)
    

main()

Solution (Python):
s = input()

countP = s.count('p')
half = len(s)//2
ans = half - countP

print(ans)

Solution (Python):
s = input()
n = len(s)
wc = 0
lc = 0
gc = 0
pc = 0
for i in range(n):
    if s[i] == 'g':
        if pc+1 <= gc:
            wc += 1
            pc += 1
        else:
            gc += 1
    else:
        if pc+1 <= gc:
            pc += 1
        else:
            lc += 1
            gc += 1
print(wc-lc)

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

Solution (Python):





s = input()
ans = 0
for i, ss in enumerate(s):
    if i & 1:
        
        ans += ss == 'g'  
    else:
        
        ans -= ss == 'p'  
print(ans)

Solution (Python):





s = input()
ans = 0
for i, ss in enumerate(s):
    if i & 1:
        
        ans += ss == 'g'  
    else:
        
        ans -= ss == 'p'  
print(ans)

Solution (Python):
s = input()

hand = 0
ans = 0
for x in s:
    o = 0
    if x == 'p':
        o = 1
    if hand < o:
        ans -= 1
    if hand > o:
        ans += 1
    hand = 1 - hand
print(ans)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline

s = readline().rstrip().decode('utf-8')
n = len(s)
g = s.count("g")
p = s.count("p")

if p == n//2:
    print(0)
else:
    print((n//2-p))

Solution (Python):
s = list(input())
countg = 0
countp = 0
for i in s:
    if i == 'g':
        countg += 1
    else:
        countp += 1

print(int((countg-countp)/2))

Solution (Python):
s = input()

print(max((s.count('g') * 2 - len(s)) // 2, 0))

Solution (Python):
import sys
input = sys.stdin.readline

s = list(input().rstrip())

G = 0 
P = 0 
ans = 0 

for i in range(len(s)):
    if i == 0:
        if s[i] == "g":
            G += 1
        else:
            ans -= 1
            G += 1
    else:
        if s[i] == "g":
            if G > P:
                ans += 1
                P += 1
            else:
                G += 1
        else:
            if G > P:
                P += 1
            else:
                ans -= 1
                G += 1

print(ans)

Solution (Python):
s = input()

g = s.count('g')
p = s.count('p')

t = list(s)
for i in range(len(s) -1, -1, -1):
  if t[i] == 'g' and g > p + 1:
    t[i] = 'p'
    g -= 1
    p += 1
t = ''.join(t)

result = 0
for i in range(len(s)):
  if t[i] == 'p' and s[i] == 'g':
    result += 1
  elif t[i] == 'g' and s[i] == 'p':
    result -= 1
print(result)

Solution (Python):


s =list(input())
n = len(s)
h = [0,0]
point = 0

for i in range(n):
    if h[0] < h[1]:
        h[0] += 1
        if s[i] == "g":
            point += 1
    
    else:
        h[1] += 1
        if s[i] == "p":
            point -= 1
        
print(point)

Solution (Python):
s = input()

l = len(s)

q, r = divmod(l, 2)
hand = "g" * (q + r) + "p" * q

score = 0
for e1, e2 in zip(s, hand):
	if e1 == "g" and e2 == "p":
		score += 1
	elif e1 == "p" and e2 == "g":
		score -= 1

print(score)

Solution (Python):
s = input()

g = len(s.replace('p', ''))
p = len(s) - g

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

Solution (Python):
s = input()
g = 0
p = 0
for i in s:
    if i == "g":
        g += 1
    if i == "p":
        p += 1
print((g - p) // 2)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    S = input().strip()

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


if __name__ == '__main__':
    main()

Solution (Python):





s = str(input())

point = 0
stock = 0

for i in range(len(s)):
  if s[i] == 'g':
    if stock == 0:
      stock+=1
    elif stock>0:
      stock-=1
      point+=1
  elif s[i] == 'p':
    if stock == 0:
      stock+=1
      point-=1
    elif stock>0:
      stock-=1
print(int(point))

Solution (Python):

import sys
INF = float("inf")


def solve(s: str):
    N = len(s)
    P = s.count("p")
    print(N//2-P)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)


if __name__ == '__main__':
    main()

Solution (Python):
s=[0 if i=='g' else 1 for i in input()]
print(s[1::2].count(0)-sum(s[0::2]))

Solution (Python):
s = input()

num = len(s)
g_len = s.count('g')
g_num = -(-num // 2)

g_len -= g_num
print(g_len)

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

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

Solution (Python):
s = input()

g, p = 0, 0
for val in s:
    if val == 'g':
        g += 1
    else:
        p += 1

ans = 0
while g > p + 1:
    g -= 1
    p += 1
    ans += 1

print(ans)

Solution (Python):

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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

import sys


def solve(s: str):
    print(len(s) // 2 - s.count('p'))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)


if __name__ == '__main__':
    main()

Solution (Python):
gp = input()
p = gp.count('p')
g = gp.count('g')

print((g-p)//2)

Solution (Python):
s = input()

g = 0;p = 0
total = 0

for i in range(len(s)):
    if s[i] == 'g':
        if p < g:
            p += 1
            total += 1
        else:
            g += 1
    elif s[i] == 'p':
        if p < g:
            p += 1
        else:
            g += 1
            total -= 1

print(total)

Solution (Python):
import collections
s = list(str(input()))

c = collections.Counter(s)
appear_g = c["g"]
appear_p = c["p"]

if appear_g - appear_p < 2:
	print(0)
else:
	print((appear_g - appear_p) // 2)

Solution (Python):
s = input()
gcnt = 0
pcnt = 0
ans = 0
for c in s:
  if c=='g':
    gcnt += 1
  else:
    pcnt += 1
print((gcnt-pcnt)//2)

Solution (Python):
S = input()
N = len(S)
W = ['p']*N
g, p = 0, 0
d = 0

last = None
w = 0
for i in range(N):
    p += 1
    if p <= g:
        if S[i] == 'g':
            w+=1
    else:
        W[i] = 'g'
        p -= 1
        g += 1
        if S[i] == 'p':
            w-=1
print(w)

Solution (Python):
s = input()

g = 0
score = 0
for c in s:
    if c == 'g':
        if g:
            score += 1
            g -= 1
        else:
            g += 1
    else:
        if g:
            g -= 1
        else:
            g += 1
            score -= 1
print(score)

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

Answer = counter

print(Answer)

Solution (Python):
S = input()
print((S.count("g")-S.count("p"))//2)

Solution (Python):
s=list(input())
a=s.count('p')
b=s.count('g')

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

Solution (Python):
s = input()
rock = 0
ans = 0
for i in s:
    if i == 'g':
        if rock:
            rock -=1
            ans += 1
        else:
            rock += 1
    else:
        if rock:
            rock-=1
        else:
            rock+= 1
            ans -= 1
print(ans)

Solution (Python):
s = input()

win = 0
lose = 0
for i in range(len(s)):
    if i%2 == 0:
        if s[i] == "g":
            pass
        else:
            lose += 1
    else:
        if s[i] == "g":
            win += 1
        else:
            pass

print(win - lose)

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

Solution (Python):





import sys

sys.setrecursionlimit(10 ** 8)


s = input()
dp = {}


def rec(i, cur_g, cur_p, g, p):
    if i in dp:
        return dp[i]
    if i == len(s):
        ret = p - g
        dp[i] = ret
        return ret
    if cur_g > cur_p:
        
        if s[i] == "g":
            ret = max(
                rec(i + 1, cur_g, cur_p + 1, g, p + 1),
                rec(i + 1, cur_g + 1, cur_p, g, p),
            )
            dp[i] = ret
            return ret
        elif s[i] == "p":
            ret = max(
                rec(i + 1, cur_g, cur_p + 1, g, p),
                rec(i + 1, cur_g + 1, cur_p, g + 1, p),
            )
            dp[i] = ret
            return ret
    else:
        
        if s[i] == "g":
            ret = rec(i + 1, cur_g + 1, cur_p, g, p)
            dp[i] = ret
            return ret
        elif s[i] == "p":
            ret = rec(i + 1, cur_g + 1, cur_p, g + 1, p)
            dp[i] = ret
            return ret


print(rec(0, 0, 0, 0, 0))

Solution (Python):
s = input()
g, p = 0, 0
ans = 0
for e in s:
    if e == "g":
        if p+1 <= g:
            p += 1
            ans += 1
        else:
            g += 1
    else:
        if p+1 <= g:
            p += 1
        else:
            g += 1
            ans -= 1

print(ans)

Solution (Python):
s = input()
N = len(s)

win = lose = 0
g = p = 0

for i in range(N):
    if s[i]=="g":
        if p < g:
            p += 1
            win += 1
        else:
            g += 1
    else: 
        if p < g:
            p += 1
        else:
            g += 1
            lose += 1
print(win-lose)

Solution (Python):
import sys
input = sys.stdin.readline
s=input().strip()
g=0
p=0
cnt=0
for i in range(len(s)):
    if s[i]=="g":
        if g>p:
            p+=1
            cnt+=1
        else:
            g+=1
    else:
        if g>p:
            p+=1
        else:
            g+=1
            cnt-=1
    
print(cnt)

Solution (Python):
import collections
n=input()
c = collections.Counter(n)
print(len(n)//2-int(c['p']))

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

Solution (Python):
s=input()
g=0
p=0
ans=0
for i in s:
  if i=="g":
    if p<g:
      ans+=1
      p+=1
    else:
      g+=1
  elif i=="p":
    if p<g:
      p+=1
    else:
      g+=1
      ans-=1
print(ans)

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()

C = Counter(S)
ans = (C['g'] - C['p']) // 2
print(ans)

Solution (Python):
s = str(input())

g_count = 0
p_count = 0
point = 0
for i in range(len(s)):
    
    if g_count == p_count:
        g_count += 1
        if s[i] == 'g':
            pass
        else:
            point -= 1
    
    elif s[i] == 'g':
        p_count += 1
        point += 1
    elif s[i] == 'p':
        p_count += 1

ans = point
print(ans)

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

Solution (Python):
s = input()
n = len(s)
ans = 0
for i in range(0, n, 2):
    if s[i] == 'p': ans-=1

for i in range(1, n, 2):
    if s[i] == 'g': ans += 1
print(ans)

Solution (Python):
S=str(input())
point = 0
N=len(S)
if N%2==0:
  A=[0,1]*(N//2)
else:
  A=[0,1]*(N//2)+[0]

T=[]
for i in range(N):
  if S[i]=='g':
    T +=[0]
  else:
    T +=[1]

count=0
for i in range(N):
  count +=A[i]-T[i]
print(count)

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

Solution (Python):


import sys
input = sys.stdin.readline

s = input()

gtime = 0
ptime = 0

N = len(s) - 1


res = 0

for i in range(N):
    temp = s[i]
    if ptime >= gtime:
        gtime += 1
        if temp == 'p':
            res -= 1
    else:
        if temp == 'p':
            ptime += 1
        elif temp == 'g':
            ptime += 1
            res += 1
    
    

print(res)

Solution (Python):
def main():
    S = input()
    ans = 0
    for i, s in enumerate(S):
        if i & 1:
            if s == "g":  
                ans += 1
        else:
            if s == "p":
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
s = list(input())

g = s.count("g")

if len(s) % 2 == 0:
   print(g - len(s) // 2)
else:
   print(g - len(s) // 2 - 1)

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

Solution (Python):
s = input()

g = s.count('g')
p = s.count('p')

print((g-p)//2)

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