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=input();print(len(S)//2-S.count('p'))

Solution (Python):
S = input()
p_cnt = 0
for c in S:
    if c == 'p':
        p_cnt += 1
print(len(S)//2-p_cnt)

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

Solution (Python):
s = input()
length_s = len(s)
paper_cnt = 0
ans = 0

for i in range(length_s):
    if s[i] == 'g':
        if paper_cnt < 0:
            ans += 1
            paper_cnt += 1

        else:
            paper_cnt -= 1

    else:
        if paper_cnt < 0:
            paper_cnt += 1

        else:
            ans -= 1
            paper_cnt -= 1

print(ans)

Solution (Python):
S = input()
g = 0
p = 0

ans = 0

for i, s in enumerate(S):
    if i&1:
        m = "p"
    else:
        m = "g"
    
    if s=="g" and m=="p":
        ans += 1
    elif s=="p" and m=="g":
        ans -= 1

print(ans)

Solution (Python):

import sys


sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush

from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
import math








INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())



def run():
    S = input()
    G = 0
    P = 0
    score = 0
    for s in S:
        if s == 'g':
            if G > P:
                score += 1
                P += 1
            else:
                G += 1
        if s == 'p':
            if G > P:
                P += 1
            else:
                G += 1
                score -= 1

    print(score)

if __name__ == "__main__":
    
    run()

Solution (Python):
def main():
    s = input()
    cr = 0
    cp = 0
    score = 0
    for c in s:
        if c == 'g':
            if cr > cp:
                score += 1
                cp += 1
            else:
                cr += 1
        else:
            if cr > cp:
                cp += 1
            else:
                cr += 1
                score -= 1
    print(score)
    

if __name__ == '__main__':
    main()

Solution (Python):
s = input()
max_p = len(s) // 2
if max_p <= s.count('p'):
    print(0)
else:
    print(max_p - s.count('p'))

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

Solution (Python):
def main():
    S = list(input())
    num_stone = 0
    num_paper = 0
    ans = 0
    for c in S:
        if c == 'g':
            if num_paper < num_stone:
                num_paper += 1
                ans += 1
            else:
                num_stone += 1
        else:
            if num_paper < num_stone:
                num_paper += 1
            else:
                num_stone += 1
                ans -= 1
    print(ans)
main()

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

ans=0

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

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

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

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

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

Solution (Python):
S=input()

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

Solution (Python):
S=input()

G=P=0
K=0
for s in S:
    if P==G:
        if s=="p":
            K-=1
        G+=1
    else:
        if s=="g":
            K+=1
        P+=1

print(K)

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

Solution (Python):
from collections import Counter
s = input().rstrip()
L = len(s)
d = Counter(s)
print(L//2-d["p"])

Solution (Python):
s = input()

s = [c == 'g' for c in s]

print(sum(s[1::2]) - sum(not f for f in s[::2]))

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

if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

S = Counter(input())
print((S["g"] - S["p"]) // 2)

Solution (Python):
S = input()

cur = "g"
acd = 0
tcd = 0
for c in S:
    if cur != c:
        if cur == "p":
            acd += 1
        else:
            tcd += 1
    cur = "p" if cur == "g" else "g"
print(acd - tcd)

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

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

c+=n%1

print(c//2)

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

Solution (Python):
import sys
import math
import collections
import bisect
import itertools



sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))




def main():
    s = list(input())

    g = 0
    p = 0
    ans = 0

    for i in range(len(s)):
        if p + 1 <= g:
            a = "p"
            p += 1
        else:
            a = "g"
            g += 1

        if a == s[i]:
            continue
        elif a == "p":
            ans += 1
        else:
            ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

    N = len(s)

    
    ans = N // 2 - s.count('p')
    print(ans)

if __name__ == '__main__':
    resolve()

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

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

Solution (Python):
s= input()
g = 'gp'*(len(s)//2)+'g'*(len(s)%2)
cnt = 0
for si,gi in zip(s,g):
    if si == gi:
        continue
    elif si =='g' and gi == 'p':
        cnt += 1
    else:
        cnt -= 1
print(cnt)

Solution (Python):
s = input().strip()
N = len(s)
C = {0:0,1:0}
for i in range(N):
    if s[i]=="g":
        C[0] += 1
    else:
        C[1] += 1
n = N//2
print(n-C[1])

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

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
input = sys.stdin.readline

s = input()[:-1]
p, g = 0, 0
ans = 0

for si in s:
    if si=='g':
        if p<g:
            p += 1
            ans += 1
        else:
            g += 1
    else:
        if p<g:
            p += 1
        else:
            g += 1
            ans -= 1

print(ans)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

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

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

hand = {'g': 0, 'p': 0}
ans = 0
for i in range(N):
    if S[i] == 'g':
        if hand['g'] > hand['p']:
            hand['p'] += 1
            ans += 1
        else:
            hand['g'] += 1
    else:
        if hand['g'] > hand['p']:
            hand['p'] += 1
        else:
            hand['g'] += 1
            ans -= 1

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


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

    ans = (S.count("g") - S.count("p")) // 2

    print(ans)


if __name__ == "__main__":
    main()

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

num_g, num_p = 0, 0
score = 0
for x in s:
    if x == 'g':
        if num_g - num_p > 0:
            score += 1
            num_p += 1
        else:
            score = score
            num_g += 1
    elif x == 'p':
        if num_g - num_p > 0:
            score = score
            num_p += 1
        else:
            score -= 1
            num_g += 1

print(score)

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

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

print(ans)

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

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

Solution (Python):
def main():
    import sys
    import numpy as np
    sys.setrecursionlimit(10**6)
    s = input().strip()
    N = len(s)
    p = sum([1 if si == 'p' else 0 for si in s])
    print(N//2-p)

if __name__ == '__main__':
    main()

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

Solution (Python):

import sys

def solve(s: str):
    from collections import Counter
    from math import floor
    N = len(s)
    c = Counter(s)
    return floor(N / 2) - c["p"]


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

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):
s=(input())
pap,rk=0,0
sm=0
for el in s:
    if(el=='g'):
        if(pap+1<=rk):
            sm+=1
            pap+=1
        else:
            sm+=0
            rk+=1
    else:
        if(pap+1<=rk):
            sm+=0
            pap+=1
        else:
            sm-=1
            rk+=1
print(sm)

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


def point(c0, c1):
    if c0 == "p" and c1 == "p":
        return 0
    if c0 == "p" and c1 == "g":
        return 1
    if c0 == "g" and c1 == "p":
        return -1
    if c0 == "g" and c1 == "g":
        return 0


answer = 0
for i in range(n):
    c0 = "g" if i % 2 == 0 else "p"
    answer += point(c0, s[i])

print(answer)

Solution (Python):
s = input()
ans = 0
for t, u in zip(s[::2], s[1::2]):
    if t == 'p':
        ans -= 1
    if u == 'g':
        ans += 1
print(ans)

Solution (Python):
import  sys
s=input()

a=s.count('g')
if len(s)/2==a:
    print('0')
    sys.exit()

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
ans = 0
count = 0
for c in s:
    if c=="g":
        if count>0:
            ans += 1
            count -= 1
        else:
            count += 1
    else:
        if count>0:
            count -= 1
        else:
            ans -= 1
            count += 1
print(ans)

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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 power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


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 make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

ans = 0
s = sr()
for i,c in enumerate(s):
    if i%2 == 0:
        if c == 'p':
            ans-=1
    else:
        if c == 'g':
            ans+=1
print(ans)

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

Solution (Python):
s = input()
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):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



s = input()

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

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    s = in_s()
    N = len(s)

    cnt_g = 0
    cnt_p = 0
    score = 0

    for i in range(N):

        if s[i] == 'g':
            if cnt_p < cnt_g:
                cnt_p += 1
                score += 1
            else:
                cnt_g += 1
        else:
            if cnt_p < cnt_g:
                cnt_p += 1
            else:
                cnt_g += 1
                score -= 1

    print(score)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate
S = input()
dic =  {"g":0, "p":1}







As = [dic[s] for s in S]
cnt = 0
for i,s in enumerate(S):
    a = i % 2
    b = dic[s]
    cnt += (a-b)
print(cnt)

Solution (Python):



def main():
    S = list(input())
    ret = 0
    for i, a in enumerate(S):
        if i%2==0:
            
            if a=='p':
                ret -= 1
        else:
            if a=='g':
                ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Solution (Python):
S=input()
P=0
for i in range(len(S)):
  P+=(i&1)-(S[i]=='p')
print(P)

Solution (Python):
S = input()

g_cnt, p_cnt = 0, 0
ans = 0
for s in S:
    if p_cnt < g_cnt:
        if s == "g":
            p_cnt += 1
            ans += 1
        elif s == "p":
            p_cnt += 1
    else:
        if s == "g":
            g_cnt += 1
        elif s == "p":
            g_cnt += 1
            ans -= 1
print(ans)

Solution (Python):
S = input()

cnt = 0
for s in S:
  if s == 'g':
    cnt += 1

if len(S) % 2 == 1:
  print(cnt-len(S)//2-1)
else:
  print(cnt-len(S)//2)

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

Solution (Python):
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


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

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



if __name__ == "__main__":
    main()

Solution (Python):


import sys
readline = sys.stdin.readline
read = sys.stdin.read


s = input()
n = len(s)
t = "gp"*((n+2)//2)

ans = 0
for i,j in zip(s,t):
    if i != j:
        if i=="g": ans += 1
        else: 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
    if i%2 == 1:
        if s[i] == "g":
            ans += 1
            
print(ans)

Solution (Python):
s=list(input())
n=len(s)
from collections import defaultdict
d=defaultdict(int)
t=['g' if i%2==0 else 'p' for i in range(n)]
pnt=0
for i in range(n):
    if s[i]==t[i]:
        continue
    elif s[i]=='g':
        pnt+=1
    else:
        pnt-=1
print(pnt)

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

Solution (Python):
s = input()
gcnt = 0
pcnt = 0
res = 0

for c in s:
    if pcnt<gcnt:
        pcnt += 1
        if c=="g":
            res += 1
    else:
        gcnt += 1
        if c=="p":
            res -= 1
print(res)

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

Solution (Python):
from collections import Counter
s = input()
cnt = Counter(s)
n_p = cnt['p']
print(len(s) // 2 - n_p)

Solution (Python):
def main():
    S = input()
    gu = 0
    par = 0
    ans = 0
    for s in S:
        if s == 'g':
            if par < gu:
                ans += 1
                par += 1
            else:
                gu += 1
        else:
            if par < gu:
                par += 1
            else:
                ans -= 1
                gu += 1

    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):


S = input()
N = len(S)

num = 0
ans = 0
for i in range(N):
    if S[i] == 'g':
        if num > 0:
            num -= 1
            ans += 1
        else:
            num += 1
    else:
        if num > 0:
            num -= 1
        else:
            num += 1
            ans -= 1


print(ans)

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

Solution (Python):
from collections import Counter

s = input()
n = len(s)
c = Counter(s)
can_p = n // 2
print(can_p-c['p'])

Solution (Python):
from collections import defaultdict
s = input()
n = len(s)

cnt = defaultdict(int)
for x in s:
    cnt[x] += 1

can_p = n//2
print(can_p-cnt['p'])

Solution (Python):
s = input()

ans = 0
np = 0
ng = 0

for ss in s:
    if ng > np:
        if ss == 'g':
            ans += 1
        np += 1
    else:
        if ss == 'p':
            ans -= 1
        ng += 1
print(ans)

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

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

ans = 0
cnt_g = 0
cnt_p = 0
for i in range(n):
    if cnt_p + 1 <= cnt_g:
        cnt_p += 1
        if s[i] == 'g':
            ans += 1
    else:
        cnt_g += 1
        if s[i] == 'p':
            ans -= 1

print(ans)

Solution (Python):
s = input()
n = len(s)
nowp = 0
nowg = 0
ans = 0

for i in range(n):
    if s[i] == "g":
        if nowp < nowg:
            nowp += 1
            ans += 1
        elif nowp == nowg:
            nowg += 1
    elif s[i] == "p":
        if nowp < nowg:
            nowp += 1
        elif nowp == nowg:
            nowg += 1
            ans -= 1
print(ans)

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

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    s = input()
    N = len(s)
    gnum = 0
    pnum = 0
    for i in range(N):
        if s[i] == 'g':
            gnum += 1
        else:
            pnum += 1
    print((gnum-pnum)//2)

if __name__ == "__main__":
    main()

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

print(N // 2 - S.count('p'))

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = SI()
    N = len(S)
    A = "gp" * (N//2 + 1)
    ans = 0
    for i in range(N):
        if S[i] == A[i]:
            continue
        if S[i] == "g":
            ans += 1
            continue
        ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
s = input()

res = 0
g_stock = 0
for i in s:
    if i == 'g':
        g_stock += 1
    else:
        if g_stock > 0:
            g_stock -= 1
        else:
            res -= 1
res += g_stock//2
print(res)

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

S = readline().rstrip()









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

Solution (Python):
S = list(input())
N = len(S)
p = sum([1 if s == "p" else 0 for s in S])
print(N//2-p)

Solution (Python):
s = str(input())
n, p = len(s), s.count('p')

print(n // 2 - p)

Solution (Python):
s = str(input())
n, g, p = len(s), s.count('g'), s.count('p')

print(n // 2 - p)

Solution (Python):
s = str(input())
n, g, p = len(s), s.count('g'), s.count('p')

print(g - (n - n // 2))

Solution (Python):
s = str(input())
n, g, p = len(s), s.count('g'), s.count('p')

print(g - (n - n // 2))

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

if __name__ == "__main__":
    main()

Solution (Python):
import sys

import math






s=input()
n=len(s)
count=[0,0]
for i in s:
    if i=="g":
        count[0]+=1
    else:
        count[1]+=1
print((count[0]-count[1])//2)

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

Solution (Python):
s = input()

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

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

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = list(input())
    c = Counter(S)
    ans = (c["g"] - c["p"]) // 2
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
s = input()
tcd_g = s.count("g")
tcd_p = len(s) - tcd_g

acd_p = len(s)//2
acd_g = len(s) - acd_p

if tcd_g >= acd_p:
    print(acd_p - tcd_p)
else:
    print(tcd_g - acd_g)

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

print(cnt//2)

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


risou = math.ceil((a+b)/2)

print(((a+b)-risou)-a)

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

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

print((g-p)//2)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()

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

Solution (Python):
def solve():
    S = input()
    even = S[0::2]
    odd = S[1::2]
    ans = odd.count('g')-even.count('p')
    return ans
print(solve())

Solution (Python):
s = input()
ans = 0
for i,t in enumerate(s):
  if i&1 == 0 and t == 'p':
    ans -= 1
  elif i&1 == 1 and t == 'g':
    ans += 1
print(ans)

Solution (Python):
s = input()
ans = 0
for i,t in enumerate(s):
  if i&1 == 0 and t == 'p':
    ans -= 1
  elif i&1 == 1 and t == 'g':
    ans += 1
print(ans)

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

Solution (Python):
s = input()
p = sum(1 for i in s if i == 'p')
l = len(s)
print(l // 2 - p)

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

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

Solution (Python):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**5
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    s = sys.stdin.readline().rstrip()
    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):
import sys

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

n = len(s)
p_n = s.count("p")
ans = n // 2 - p_n
print(ans)

Solution (Python):
s = input()
N = len(s)
pc = 0
gc = 0
wp = 0
lp = 0
for i in range(N):
  if s[i] == "g":
    if pc+1 <= gc:
      pc += 1
      wp += 1
    else:
      gc += 1  
  if s[i] == "p":  
    if pc+1 <= gc:
      pc += 1
    else:
      gc += 1  
      lp += 1
print(wp-lp)

Solution (Python):
s_str = input()
s_list = list(s_str)
g_count = 0
p_count = 0
score = 0
for s in s_list:
  if p_count >= g_count:
    if s == "p":
      score -= 1
    g_count += 1
  else:
    if s == "g":
      score += 1
    p_count += 1
print(score)

Solution (Python):

import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode("utf-8").rstrip()
sp = [int(h == "p") for h in S]


def solve():
    g = p = 0
    score = 0
    for is_p in sp:
        if g == p:
            hand = 0
            g += 1
        else:
            hand = 1
            p += 1
        if hand > is_p:
            score += 1
        elif hand < is_p:
            score -= 1
    return score


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

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