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
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))


from collections import Counter
def resolve():
    S=input()
    c=Counter(S)
    
    print((c["g"]-c["p"])//2)

resolve()

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

Solution (Python):
A= list(input())
p_c = 0
total = 0 
g_c = 0
for i in A:
    if i == "g" and p_c+1 <= g_c:
        total += 1
        p_c += 1
    elif i == "p" and p_c+1 <= g_c:
        p_c += 1
    elif i == "g":
        g_c += 1
    else:
        g_c += 1
        total -= 1
print(total)

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

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

ans=0
g=0
p=0
for i in range(N):
    if s[i]=="p":
        p+=1
        if p>g:
            ans-=1
            p-=1
            g+=1 
    else:
        g+=1
        val=g-p
        if val==2:
            ans+=1
            g-=1
            p+=1
print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
cnt = 0
ans = 0
size = len(s)
flag = False
for i in range(size):
    if cnt >= size - i:
        flag = True
    if s[i] == 'p':
        cnt -= 1
    if s[i] == 'g':
        if flag:
            ans += 1
        else:
            cnt += 1
if flag:
    print(ans)
else:
    print(min(cnt, 0))

Solution (Python):
s=input()
ans=0
res=0
w=0
l=0
for i in range(len(s)):
    if res==0:
        res+=1
        if s[i]=='p':
            l+=1
    else:
        if s[i]=='p':
            res-=1
        else:
            res-=1
            w+=1
print(w-l)

Solution (Python):
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

s = input()
size = len(s)
p_cnt = s.count("p")

max_p = size // 2

print(max_p - p_cnt)

Solution (Python):
s = input()

ans = 0
cnt = 0
for i in s:
    if i == "g":
        if cnt >= 1:
            cnt -= 1
            ans += 1
        else:
            cnt += 1
    else:
        if cnt >= 1:
            cnt -= 1
        else:
            cnt += 1
            ans -= 1

print(ans)

Solution (Python):
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys

input = sys.stdin.readline
_NUMINT_ALL = list(range(10))


def main():
    ans = solve()

    if ans is True or ans is False:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():
    s = iip()

    cur = -1
    ans = 0
    for i in s:
        if cur > 0:
            ans += 1
        if i == "p":
            ans -= 1
        cur *= -1
    print(ans)



def kiriage_warizan(a, b):
    return -(-a//b)


def iip(listed=True):  
    d = input().rstrip("\n").split()
    try:
        ret = [int(i) for i in d]
    except:
        ret = [int(i) if i in _NUMINT_ALL else i for i in d]
        if len(ret) == 1:
            return ret[0]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iipt(l, listed=False, num_only=True):  
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed))
    return ret


def saidai_kouyakusuu(A):  
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def make_graph_edge_flat(N):  
    ret = []
    for i in range(N-1):
        a, b, c = iip()
        a -= 1
        b -= 1
        ret[a].append((b, c))
        ret[b].append((a, c))
    return ret


def sort_tuples(l, index):  
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  
    if index >= len(l):                      
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def sortstr(s):  
    return "".join(sorted(s))


def iip_ord(startcode="a"):  
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  
    for i in s:
        print(i)


def bitall(N):  
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):  
    return power(n, mod - 2)


def power(n, p, mod_=mod):  
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


def nibutan_func(func, target, left, right, side="left"): 
    l = left
    r = right
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if func(x) == target:
            return x
        elif func(x) > target:
            r = x
        else:
            l = x

    if side == "left" or func(x) == target:
        return l
    else:
        return r


def nibutan_list(list_, target, side="left"):  
    if not isinstance(list_, list):
        list_ = list(list_)

    l = 0
    r = len(list_)
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if list_[x] == target:
            return x
        elif list_[x] > target:
            r = x
        else:
            l = x

    if side == "left" or list_[x] == target:
        return l
    else:
        return r


class UfTree():
    def __init__(self, maxnum):
        self.parent = list(range(maxnum))
        self._size = [1] * maxnum
        self.rank = [0] * maxnum

    def size(self, a):
        return self._size[self.root(a)]

    def root(self, a):
        rank = 0
        cur = a
        while True:
            if self.parent[cur] == cur:
                
                
                return cur
            else:
                self.parent[cur] = self.parent[self.parent[cur]]
                cur = self.parent[cur]
                rank += 1

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return self

        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        return self

if __name__ == "__main__":
    main()

Solution (Python):
s = input()
N = len(s)
g = s.count('g')
p = s.count('p')
ans = g-p
if N%2==1:
  ans -= 1
ans //= 2
print(ans)

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

g = 0
p = 0
score = 0

for i in range(N):
    if(g > p):
        if(s[i] == "g"):
            p += 1
            score += 1
        else:
            p += 1
    elif(g == p):
        if(s[i] == "g"):
            g += 1
        else:
            g += 1
            score -= 1
print(score)

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

Solution (Python):
def resolve():
    s=str(input())
    val=len(s)
    cntg=0
    cntp=0
    w=0
    l=0
    for i in range(len(s)):
        if cntg-cntp<=0:
            cntg+=1
            if s[i]=='p':
                l+=1
        else:
            if s[i]=='g':
                cntp+=1
                w+=1
            else:
                cntp+=1
    print(w-l)



resolve()

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

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

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

    y[i] = cnt

print(y[-1] // 2)

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

    y[i] = cnt

print(y[-1] // 2)

Solution (Python):
from sys import stdin
def main():
    readline=stdin.readline
    s=readline().strip()

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

if __name__=="__main__":
    main()

Solution (Python):
S = input()

now = 0
ans = 0
for s in S:
    if now == 0:
        now += 1
        if s == 'p':
            ans -= 1
        continue
    if s == 'g':
        ans += 1
    now -= 1

print(ans)

Solution (Python):

dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

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

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

s = STR()
n = len(s)
pcnt = 0
gcnt = 0
ans = 0
for i in range(n):
    pcnt += 1
    if pcnt <= gcnt and s[i] == 'g':
        ans += 1
    elif pcnt <= gcnt and s[i] == 'p':
        continue
    elif pcnt > gcnt and s[i] == 'p':
        pcnt -= 1
        gcnt += 1
        ans -= 1
    elif pcnt > gcnt and s[i] == 'g':
        pcnt -= 1
        gcnt += 1
print(ans)

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

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

plst=[1 if c=='p' else 0 for c in s]
p=sum(plst)

print(n//2-p)

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

Solution (Python):
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

s = input()
N = len(s)
p = 0
g = 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:
            ans -= 1
            g += 1
print(ans)

Solution (Python):
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

s = input()
N = len(s)
p = 0
g = 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:
            ans -= 1
            g += 1
print(ans)

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

ans = 0

for i in range(len(s)):
    ans += i & 1

for c in s:
    if c == 'p':
        ans -= 1

print(ans)

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

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

Solution (Python):
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys


import copy
"""
from collections import *
S=input()

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

Solution (Python):
s = input()
p, g = 0, 0
ans = 0
for e in s:
    if e == "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):
A=input()
cntg=0
cntp=0
cnt=0
for i in A:
  if i=='g':
    if cntg==cntp:
      cntg+=1
    else:
      cntp+=1
      cnt+=1
  else:
    if cntg==cntp:
      cntg+=1
      cnt-=1
    else:
      cntp+=1
print(cnt)

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

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

Solution (Python):
s = input()

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


print(ans // 2)

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

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



S = str(input())

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

print(ans)

Solution (Python):
s = input()
p_cnt=0
for te in s:
    if te=="p":
        p_cnt+=1
best_p=len(s)//2
diff = best_p - p_cnt
print(diff)

Solution (Python):
s = input()

g_cnt=0
for te in s:
    if te=="g":
        g_cnt+=1
p_cnt=len(s)-g_cnt
best_p=len(s)//2
diff = best_p - p_cnt
print(diff)

Solution (Python):
s = input()

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

print((g-p)//2)

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

Solution (Python):
s = input()
ans = len(s)//2 - sum(c=='p' for c in s)
print(ans)

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

cnt_g=0
cnt_p=0

for i in range(N):
    if S[i]=="g":
        cnt_g+=1
    else:
        cnt_p+=1

ans=(cnt_g-cnt_p)//2

print(ans)

Solution (Python):

import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7

def main():
    S = cin.string()
    g,p = 0,0
    ans = 0
    for s in S:
        if p + 1 <= g:
            if s == "g":
                ans += 1
            p +=1
        else:
            if s == "p":
                ans -= 1
            g+=1
    print(ans)
    return

if __name__ == "__main__":
    main()

Solution (Python):
import sys

use_clipboard=True
bbn=1000000007
	


		
def main():
	s = input()
	n=len(s)
	m=n//2
	ret = s.count('p') - m
	
	print(-ret)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
class input_clipboard:
	def __init__(self,s):
		self.input_l=s.splitlines()
		self.ii=0
		
	def input(self):
		ret = self.input_l[self.ii]
		self.ii+=1
		return ret

if __name__ == "__main__":
	if sys.platform =='ios':
		if use_clipboard:
			import clipboard
			input_text=clipboard.get()
			ic=input_clipboard(input_text)
			input = lambda : ic.input()
		else:
			sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations
from itertools import accumulate
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

s=input()

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

Solution (Python):
S = input()
pd = len(S) // 2
pt = S.count("p")

print(pd- pt)

Solution (Python):
S = input()
pd = len(S) // 2
gd = len(S) - pd
pt = S.count("p")
gt = len(S) - pt

score = min(pd,gt) - min(pt,gd)
print(score)

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):
s = input().strip()
dp = [[0]]
print(len(s)//2-s.count('p'))

Solution (Python):
s=input()

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

print(ans)

Solution (Python):
import sys


stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) 
rs = lambda: stdin.readline().rstrip()  

S = list(rs())
p_cnt = S.count('p')
g_cnt = len(S) - p_cnt
possible = (g_cnt-p_cnt) // 2
print(possible)

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

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

print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline
s = list(input())[: -1]
res = 0
g = s.count("g")
p = s.count("p")
print((g + p) // 2 - p)

Solution (Python):
S = input()

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

print(ans)

Solution (Python):
def main():
    S = input()
    m = len(S) // 2
    print(-S[:len(S) - m].count('p') + S[len(S) - m:].count('g'))

main()

Solution (Python):
def main():
    s = input()
    g = s.count('g')
    p = s.count('p')
    if (g + p) % 2 == 0:
        return g - (g + p)//2
    else:
        return g - (g + p + 1)//2
print(main())

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

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

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

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

Solution (Python):
s=list(input())
ans=0
g_c,p_c=0,0
for i in range(len(s)):
    if i==0:
        g_c+=1
        if s[i]=='p':
            ans-=1
        continue
    if s[i]=='g':
        if p_c<g_c:
            p_c+=1
            ans+=1
        else:
            g_c+=1
    else:
        if p_c<g_c:
            p_c+=1
        else:
            g_c+=1
            ans-=1
print(ans)

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

Solution (Python):
def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])

def main():
    s = input()
    NG = 1
    NP = 0
    did = ["g"]
    point = 0
    for i in range(1,len(s)):
        if s[i] == "g":
            if NP + 1 <= NG:
                did.append("p")
                NP += 1
                point += 1
            else:
                did.append("g")
                NG += 1
        else:
            if NP + 1 <= NG:
                did.append("p")
                NP += 1
            else:
                did.append("g")
                NG += 1
                point -= 1
    print(point)

if __name__ == "__main__":
    main()

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

g=0
p=0
for i in range(N):
  if S[i]=="g":
    g+=1
  else:
    p+=1
    
print(g-(N+1)//2)

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

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

Solution (Python):
import collections
S=list(input())
_S=collections.Counter(S)
count=(_S["g"]-_S["p"])//2
print(count)

Solution (Python):
from collections import Counter
s = list(input())
lens = len(s)
cs = Counter(s)

gp = cs["g"] - cs["p"]

print(gp // 2)

Solution (Python):
from sys import stdin
s = (stdin.readline().rstrip())
g = s.count("g")
p = s.count("p")
c = len(s)//2
print(c-p)

Solution (Python):
s = input()

s_list = list(s)

from collections import Counter

counter = Counter(s_list)

times = len(s_list)

half = times // 2
print(min(counter["g"] - half, half-counter["p"]))

Solution (Python):
S = input()

p_count = 0

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

print(int(len(S)/2) - p_count)

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

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

Solution (Python):
if __name__ == "__main__":
    s = input()

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

    print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines























def main():
    s=input().rstrip().decode('utf-8')
    s0=s[::2]
    s1=s[1::2]
    print(s1.count("g")-s0.count("p"))



if __name__ == '__main__':
    main()

Solution (Python):
s = input()
len_s = len(s)
cnt = 0
enemy = []
me = []
INF = 1e10
for i, _s in enumerate(s):
    if _s == "p":
        cnt += 1
    enemy.append(cnt)
    me.append((i+1) // 2)
    diff = (i + 1) // 2 - cnt
print(diff)

Solution (Python):
import sys


def slove():
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    g = 0
    p = 0
    for i in range(len(s)):
        if s[i] == "g":
            g += 1
        else:
            p += 1
    pp = len(s) // 2
    cnt = 0
    for i in range(len(s)):
        if pp != 0:
            pp -= 1
            if s[i] == "g":
                cnt += 1
        else:
            if s[i] == "p":
                cnt -= 1
    print(cnt)


if __name__ == '__main__':
    slove()

Solution (Python):

import math
S = list(str(input()))
N = len(S)

count = 0
n = math.ceil(N/2)
for i in range(N):
    if i < n:
        if S[i] == "p":
            count-=1
    else:
        if S[i] == "g":
            count+=1
            
print(count)

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

Solution (Python):
S = input()

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

Solution (Python):
s = input()

g = 0
p = 0

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

print((g-p)//2)

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

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

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

def main():
    s = input().strip()
    ans = 0
    x = 0 
    for c in s:
        if x > 0: 
            x -= 1
            if c == "g":
                ans += 1
        else: 
            x += 1
            if c == "p":
                ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

def main():
    
    S = input().rstrip()
    ans = len(S) // 2 - S.count("p")
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
s = str(input())
n = len(s)
hand = 0
point = 0
for i in range(n):
    if i==0:
        hand +=1
        continue
    if s[i]=="p" and hand>0:
        hand -=1
    elif s[i]=="p" and hand ==0:
        hand +=1
        point-=1
    elif s[i]=="g" and hand>0:
        hand -=1
        point +=1
    elif s[i]=="g" and hand==0:
        hand +=1
print(point)

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

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