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



S = list(input())

p = 0
g = 0
w = 0
for s in S:
    
    t = 'p' if p < g else 'g'
    p += 1 if t == 'p' else 0
    g += 1 if t == 'g' else 0
    
    if s != t:
        
        if s == 'p':
            w -= 1
        
        elif s == 'g':
            w += 1

print(w)

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

Solution (Python):
s = input()

x = len(s) // 2

a = 'g' * (len(s) - x) + 'p' * x
ans = 0
for i in range(len(s)):
    if s[i] == 'g' and a[i] == 'p':
        ans += 1
    elif s[i] == 'p' and a[i] == 'g':
        ans -= 1
print(ans)

Solution (Python):
import sys

s = sys.stdin.readline().rstrip()

def main():
    ans = len(s) // 2 - s.count('p')
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):

import sys


def solve(s: str):
    answer = 0
    for i in range(len(s)):
        ss = s[i]
        if i%2 == 0 and ss=='p':
            answer -= 1
        
        if i%2==1 and ss=='g':
            answer +=1
    
    print(answer)

    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 = input()










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

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

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


if __name__ == '__main__':
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    g = S.count("g")
    p = S.count("p")
    print(abs((g+p)//2 - p))
if __name__ == '__main__':
    main()

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

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

Solution (Python):
s=input()
m=s.count('g')
n=len(s)
print((m-n//2) if n%2==0 else m-1-n//2)

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

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):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
    S=input()
    C=Counter(S)
    g=C['g']; p=C['p']
    n=g+p
    print(g-(n+1)//2)
resolve()

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

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

Solution (Python):
s=input()

def ranlength(A):
    num = list(A)
    count = 1
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                table.append(count)
                count = 1
        except:
            table.append(count)
    return(table)

rl=ranlength(s)
w=0
for i in range(len(rl)//2):
    w+=(rl[i*2]-rl[i*2+1])/2

if len(rl)%2==1:
    w+=rl[-1]/2

w=int(w)
print(w)

Solution (Python):
s = list(input())
n = len(s)
ans = 0
flag = 0
for i in range(n):
  if s[i] == "g" and flag == 0:
    flag+=1
  elif s[i] == "g" and flag != 0:
    flag -= 1
    ans += 1
  elif s[i] == "p" and flag == 0:
    flag += 1
    ans -= 1
  else:
    flag -= 1
print(ans)

Solution (Python):
s = input()

p = len([c for c in s if c == 'p'])
print(len(s)//2 - p)

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

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

Solution (Python):
w=input()
num=len(w)
countp=0
countg=0
for i in range(num):
  if w[i]=="g":
    countg+=1
  else:
    countp+=1
if num%2==0:
  print(num//2-countp)
else:
  print(num//2-countp)

Solution (Python):

s=input()+"g"+"p"
import collections
S=dict(collections.Counter(s))
a=S["p"]-1
b=S["g"]-1
x=((a+b)//2)
print(x-a)

Solution (Python):
s = input()

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

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

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()
stack = []
for s in S:
    if s == 'p':
        stack.pop(0)
    else:
        stack.append('g')
        
print(len(stack)//2)

Solution (Python):
s = input()
n = len(s)
e = n//2
o = n - e
w = 0
l = 0
for i in range(o):
    p = 2*i
    if s[p] == 'p':
        l += 1
for j in range(e):
    q = 2*j + 1
    if s[q] == 'g':
        w += 1
ans = w - l
print(ans)

Solution (Python):
s = input()
num_g = s.count("g")
num_p = s.count("p")

print((num_g - num_p) // 2)

Solution (Python):
S = input()

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

Solution (Python):

import sys
input = sys.stdin.readline


S = input().rstrip()

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

print(ans)

Solution (Python):
def examD():
    St = S()
    cur = St.count("g")
    ans = cur - (len(St)+1)//2
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Solution (Python):
def solve():
    S = input()
    N = len(S)
    

    
    n = (N - 1)
    p = (n + 2 - 1) // 2

    return p - S.count("p")


if __name__ == '__main__':
    res = solve()
    print(res)

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

ans = 0
dif = 0

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

Solution (Python):
s = input().strip()
cnt = 0
for i in range(len(s)):
    a = s[i]
    if i%2==0:
        if a=="g":
            pass
        else:
            cnt -= 1
    else:
        if a=="g":
            cnt += 1
        else:
            pass
print(cnt)

Solution (Python):
s = input()
print(s[(len(s)+1)//2:].count('g') - s[:(len(s)+1)//2].count('p'))

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

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


g=0 
p=0 
ans=''
for i in s: 
    if i=='g':
        if g==p: 
            ans+='g'
            g+=1 
        else: 
            ans+='p'
            p+=1  
    if i=='p':
        if g==p: 
            ans+='g'
            g+=1 
        else: 
            ans+='p'
            p+=1 
cnt=0 

for i in range(len(s)):
    if s[i]=='g' and ans[i]=='p':
        cnt+=1 
    if s[i]=='p' and ans[i]=='g': 
        cnt-=1  
print(cnt)

Solution (Python):
s=str(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()
n = s.count('p')
l = len(s)

ans = l//2 - n
print(ans)

Solution (Python):


s = str(input())
s_cnt = s.count("p")
ans = 0

if len(s)%2 == 0:
    ans = len(s)//2 - s_cnt

else:
    ans = len(s)//2 - s_cnt
    if ans < 0:
        ans = 0
        
print(ans)

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

Solution (Python):
s = input()
n = len(s)
p = s.count("p")

print(n//2 -p)

Solution (Python):
s=input()
gu_time=0
pa_time=0
n=len(s)
score=0
for i in range(n):
    if pa_time==gu_time:
        gu_time+=1
        if s[i]=="p":
            score-=1
    elif pa_time<gu_time:
        pa_time+=1
        if s[i]=="g":
            score+=1
print(score)

Solution (Python):

import sys


def solve(s: str):
    print(max(0, (len(s)-2*s.count('p'))//2))
    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 = input()

count_p = len([_ for _ in s if _ == 'p'])
count_g = len(s) - count_p

if count_g - count_p <= 1:
    print(0)
elif len(s) % 2 == 0:
    print(count_g - len(s)//2)
else:
    print(len(s) // 2 - 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

    else:

        if p < g:
            p += 1

        else:
            g += 1
            ans -= 1

print (ans)

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

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

Solution (Python):
def main():
    S = str(input())
    num = S.count("g")-S.count("p")

    print(num//2)

if __name__ == "__main__":
    main()

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

Solution (Python):
s = input()
point = 0
count_g = 0
count_p = 0
for enemy_move in s:
  if enemy_move == "g":
    if count_g > count_p:
      point += 1
      count_p += 1
    else:
      count_g += 1
  else:
    if count_g > count_p:
      count_p += 1
    else:
      count_g += 1
      point -= 1
print(point)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
cnt = 0
g_cnt = 0
p_cnt = 0
for i in range(n):
    if g_cnt > p_cnt:
        if s[i] == 'g':
            cnt += 1
            p_cnt += 1
        else:
            p_cnt += 1
    else:
        if s[i] == 'g':
            g_cnt += 1
        else:
            cnt -= 1
            g_cnt += 1
print(cnt)

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

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()
n = len(s)

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

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

print(n // 2 - s.count("p"))

Solution (Python):
from collections import Counter
S = input()
N = len(S)
counter = Counter(S)

p_len = N // 2

print(p_len - counter['p'])

Solution (Python):
S = input()

res = 0
for i in range(len(S)):
    h = 'gp'[i % 2]
    if S[i] == 'g' and h == 'p':
        res += 1
    elif S[i] == 'p' and h == 'g':
        res -= 1
    else:
        pass

print(res)

Solution (Python):
s = input()

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

ans = len(s) // 2 - np
print(ans)

Solution (Python):
s = input()

x = 0
np = []
for i in reversed(range(len(s))):
    if s[i] == 'p':
        x += 1
    np.append(x)
np = list(reversed(np))

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

print(ans)

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

Solution (Python):
S = input().strip()
p, g = "pg"

score = sum(1 if c==g else 0 for c in S)
G, P = 0, 0

hands = []
lastp = None
for c in S:
    if P == G:
        if c == g:
            hand = g
            score -= 1
        else:
            hand = p
            hands[lastp] = g
            
            
            
            score -= 1
            P-=1
            G+=1
    else:
        hand = p
    if hand == g:
        G += 1
    else:
        P += 1
        lastp = len(hands)
    hands.append(hand)
    


print(score)

Solution (Python):
S = input()
v = ['g', 'p']
ans = 0
for i, s in enumerate(S):
    if s != v[i % 2]:
        if s == 'g':
            ans += 1
        else:
            ans -= 1
print(ans)

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

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

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

a = 0
for i, s in enumerate(S):
    if i%2==0:
        if s == "p":
            a -= 1
    if i%2==1:
        if s == "g":
            a += 1
print(a)

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

count_P = S.count('p')


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

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

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

Solution (Python):
def main():

    s = input()
    ng, np = 0, 0
    count = 0
    for c in s:
        if c == "g":
            if np + 1 <= ng:
                 count += 1
                 np += 1
            else:
                ng += 1
        else:
            if np + 1 <= ng:
                np += 1
            else:
                ng += 1
                count -= 1
    return count

if __name__ == '__main__':
    print(main())

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

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

Solution (Python):
s = input()

count_g, count_p = 0, 0


vict = 0

for i in range(len(s)):
  if s[i] == "g" and count_p >= count_g:
    
    count_g += 1
  elif s[i] == "g" and count_p < count_g:
    
    vict += 1
    count_p += 1
    
  elif s[i] == "p" and count_p >= count_g:
    
    vict -= 1
    count_g += 1
  elif s[i] == "p" and count_p < count_g:
    
    count_p += 1

print(vict)

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

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

Solution (Python):
def main():
    ls = list(input())
    cnt = 0
    ans = 0
    for i in range(len(ls)):
        if ls[i]=="g":
            if cnt>=1:
                ans +=1
                cnt -=1
            else:
                cnt +=1
        else:
            if cnt>=1:
                cnt -=1
            else:
                cnt +=1
                ans -=1
    print(ans)
                
if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict
from heapq import heappush, heappop
import math
import bisect
import random

def LI(): return list(map(int, input().split()))
def I(): return int(input())
def LIM(): return list(map(lambda x:int(x) - 1, input().split()))
def LS(): return input().split()
def S(): return input()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007



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



print(main())

Solution (Python):
s=input()

pn=s.count('p')

print(int(len(s)/2)-pn)

Solution (Python):
def main():
    s = input()
    s_list = list(s)
    stock = 0
    point = 0
    for i in s_list:
        if i == "g" and stock == 0:
            stock += 1
        elif i == "g" and stock > 0:
            stock -= 1
            point += 1
        elif i == "p" and stock == 0:
            stock += 1
            point -= 1
        elif i == "p" and stock > 0:
            stock -= 1
    print(point)

if __name__ == '__main__':
    main()

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 



s = input()

g = p = 0
ans = 0
for i in s:
    if 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()
print((s.count("g")-s.count("p"))//2)

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
    else:
        if p < g:
            p += 1
        else:
            ans -= 1
            g += 1
print(ans)

Solution (Python):
s = input()

deposit = 0
score = 0
for i in s:
    if deposit > 0 and i == "g":
        deposit -= 1
        score += 1
    elif deposit == 0 and i == "g":
        deposit += 1
    elif deposit > 0 and i == "p":
        deposit -= 1
    elif deposit == 0 and i == "p":
        deposit += 1
        score -= 1
print(score)

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

Solution (Python):
S = input()

print(len(S)//2-S.count("p"))

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

Solution (Python):
tcd = input()

cnt = 0
for i in range(len(tcd)):
    if i%2 == 0:
        if tcd[i] == "p":
            cnt -= 1
    else:
        if tcd[i] == "g":
            cnt += 1
print(cnt)

Solution (Python):
s=input()
print(s[1::2].count('g')-s[::2].count('p'))

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

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

Solution (Python):
s = list(input())
lose = 0
win = 0
g = 0
for i in s:
    if g == 0: 
        
        g += 1
        if i == 'g': 
            pass
        else:
            lose += 1
    elif g > 0: 
        
        g -= 1
        if i == 'g': 
            win += 1
        else: 
            pass

print (win - lose)

Solution (Python):

def main():
    data = list(input())
    num_g = data.count('g')
    num_p = data.count('p')
    half = len(data) // 2
    print(half - num_p)




if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(s: str):
    ret = 0
    for i, c in enumerate(s):
        if i % 2:
            if c == 'g':
                ret += 1
        else:
            if c == 'p':
                ret -= 1
    print(ret)
    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 = input()

ans = 0
cnt = 0  

for i in range(len(s)):
    if cnt == 0:
        AtCoDeer = 'g'
        cnt += 1
    else:
        AtCoDeer = 'p'
        cnt -= 1

    if AtCoDeer == 'p' and s[i] == 'g':
        ans += 1
    elif AtCoDeer == 'g' and s[i] == 'p':
        ans -= 1

print(ans)

Solution (Python):
S = input()
cnt = 0
for i in range(0, len(S)):
	if S[i] == 'g':
		cnt += 1
gandp = [0, 0]
for i in range(0, len(S)):
	if gandp[0] <= gandp[1]:
		gandp[0] += 1
		cnt -= 1
	else:
		gandp[1] += 1
print(cnt)

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right





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


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 



s = input()

g_count, p_count = 0, 0
ans = 0
for si in s:
    if si == "g":
        if p_count < g_count:
            p_count += 1
            ans += 1
        else:
            g_count += 1
    elif si == "p":
        if p_count < g_count:
            p_count += 1
        else:
            g_count += 1
            ans -= 1
print(ans)

Solution (Python):
import math

s = input()
n = len(s)
p = sum(1 for c in s if c == 'p')
print(math.floor(n / 2) - p)

Solution (Python):
s = input()
score = 0
toUse = 0
for it in s:
  if it == 'g' and toUse > 0:
    toUse -= 1
    score += 1
    continue
  if it == 'g':
    toUse += 1
    continue
  if toUse > 0:
    toUse -= 1
  else:
    toUse += 1
    score -=1
    
print(score)

Solution (Python):
s = input()

ret = 0
g, p = 0, 0
for s_ in s :
    if s_ == 'g' :
        if p < g :
            p += 1
            ret += 1
        else :
            g += 1
    else :
        if p < g :
            p += 1
        else :
            g += 1
            ret -= 1
            
print(ret)

Solution (Python):

def main():
    s = input()
    G, P, ans = 0, 0, 0
    for i in s:
        if P < G:
            P += 1
            ans += 1 if i == "g" else 0
        else:
            G += 1
            ans += 0 if i == "g" else -1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

S = list(sys.stdin.readline().rstrip())

ans = 0
for i, c in enumerate(S):
    a = i % 2
    b = 'gp'.index(c)
    if a > b:
        ans += 1
    if a < b:
        ans -= 1
print(ans)

Solution (Python):
s = input()

g_num = 1
p_num = 0

win = 0
lose = 0

if s[0] == 'p':
    lose += 1


for i in range(1, len(s)):
    if s[i] == 'p':
        if p_num < g_num:
            p_num += 1
        else:
            g_num += 1
            lose += 1
    else:
        if p_num < g_num:
            p_num += 1
            win += 1
        else:
            g_num += 1

print(win - lose)

Solution (Python):
s = input()

g_num = 0
p_num = 0

win = 0
lose = 0

for i in range(0, len(s)):
    if i == 0:
        g_num += 1
        if s[0] == 'p':
            lose += 1
    else:
        if s[i] == 'p':
            if p_num < g_num:
                p_num += 1
            else:
                g_num += 1
                lose += 1
        else:
            if p_num < g_num:
                p_num += 1
                win += 1
            else:
                g_num += 1

print(win - lose)

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

Solution (Python):
s=input().rstrip()
x=list(s)
R=0;
P=0;
ans = 0;
for i in range(0,len(x)):
    if i==0:
        R+=1;
        if x[i]=='p':
            ans-=1;
    else:
        if x[i]=='g':
            if (P+1) <= R:
                P+=1;
                ans+=1;
            else:
                R+=1;
        else:
            if (P+1) <= R:
                P+=1;

            else:
                R+=1;
                ans-=1;
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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







def main():
  s=S()

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

  myp=len(s)//2
  myg=len(s)-myp

  return myp-p

print(main())

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

s = str(input())
g,p = 0,0
ans = 0
for i in range(len(s)):
    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=raw_input()

win=lose=0
b=0
for c in s:
    t=""
    if b==0:
        t="g"
        b+=1
    else:
        t="p"
        b-=1
    if c=="g" and t=="p":win+=1
    if c=="p" and t=="g":lose+=1
print(win-lose)

Solution (Python):

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

Solution (Python):

s = input()
p = 0
for sv in s:
    if sv == "p":
        p += 1
print(len(s)//2 - p)

Solution (Python):
s = input()

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

Solution (Python):
s = input()

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

def main():
  s=S()

  gc=0
  pc=0
  p=0

  for x in s:
    if gc<pc+1:
      gc+=1

      if x=='p':
        p-=1
      
    else:
      pc+=1
      if x=='g':
        p+=1

  return p

print(main())

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    slen = len(s)

    ans = 0
    diff = 1
    for i in s[1:slen]:
        if i == 'p':
            if diff > 0:
                diff -= 1
            else:
                ans -= 1
                diff += 1
        else:
            if diff>0:
                diff -= 1
                ans += 1
            else:
                diff += 1

    
    print(ans)
        



solve()

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