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 math
s = input()
n = len(s)
print(math.floor(n/2) - s.count("p"))

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

Solution (Python):
import math
s = input()
 
ans = 0
 
r = 0
p = 0
c = 0
for j in s:
  c = r-p
  if j == 'g':
    if c > 0:
      p += 1
      ans += 1
    else:
      r += 1
  else:
    if c > 0:
      p += 1
    else:
      r += 1
      ans -= 1
print (ans)

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

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





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

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

s = ns()
ans = 0
ct = 0
for i in range(len(s)):
    if ct == 0:
        ct += 1
        if s[i] == 'p':
            ans -= 1
    else:
        ct -= 1
        if s[i] == 'g':
            ans += 1
print(ans)

Solution (Python):
from math import floor 
s = input()
n = len(s)
p = s.count('p')
print(floor(n/2)-p)

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

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

Solution (Python):
from collections import Counter
s = input()

n = len(s)

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    S = input()
    gp = [0, 0]
    ans = 0
    for c in S:
        if gp[0] > gp[1] and c == 'g':
            ans += 1
            gp[1] += 1
        elif gp[0] > gp[1] and c == 'p':
            gp[1] += 1
        elif c == 'g':
            gp[0] += 1
        else:
            ans -= 1
            gp[0] += 1
    print(ans)




if __name__ == "__main__":
    main()

Solution (Python):
S = input()
from collections import defaultdict as dd
Hand = dd(lambda:0)
for s in S:
    Hand[s] += 1
ans = len(S)//2 - Hand['p']
print(ans)

Solution (Python):
s = input()
gu = 1
pa = 0
point = 0
if s[0] == "p":
  point -= 1
  
for hand in s[1:]:
  if hand == "g":
    if pa<gu:
      point += 1
      pa += 1
    else:
      gu += 1
  elif hand == "p":
    if pa<gu:
      pa += 1
    else:
      gu += 1
      point -= 1
print(point)

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

t = 'gp' * (n//2)
if n% 2== 1:
    t += 'g'

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

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

Solution (Python):






S = list(input())
N = len(S)
a = S.count("p")
b = N // 2
ans = -a + b
print(ans)

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

Solution (Python):
s = list(input())
g = 0
p = 0
ans = 0
for i in range(len(s)):
    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):
c = 0 
r = 0
t = []
for l in raw_input():
	if l == 'g':
		if c:
			r +=1
			c -=1
		else:
			c+=1
	elif l == 'p':
		if c:
			c-=1
		else:
			r -=1
			c +=1

print r

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

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

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

for s in S:
  if s=="p":
    if p+1<=g:
      a+=0
      p+=1
    else:
      a-=1
      g+=1
  else:
    if p+1<=g:
      a+=1
      p+=1
    else:
      a+=0
      g+=1

print(a)

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

Solution (Python):
from math import ceil
s=input()
gu=s.count('g')
pa=s.count('p')

p=len(s)//2
g=int(ceil(len(s)/2))

gu,g=gu-min(gu,g),g-min(gu,g)
pa,p=pa-min(pa,p),p-min(pa,p)

if g==0 and gu==0 and p==0 and pa==0:
  print(0)
  exit()
  
if p==0 and gu==0:
  print(-g)
  exit()
  
if pa==0 and g==0:
  print(gu)
  exit()

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

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

Solution (Python):

import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode().rstrip()
N = len(S)
p_cnt = S.count('p')
p = N//2
print(p-p_cnt)

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

print(count)

Solution (Python):
s = input()
N = len(s)
D = {"g":0, "p":0}
for i in range(N):
    D[s[i]] += 1
my_p = N//2
score = my_p - D["p"]
print(score)

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

if n % 2 == 0:
    print(s[n//2:].count('g') - s[:n//2].count('p'))
else:
    print(s[n//2+1:].count('g') - s[:n//2+1].count('p'))

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

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

Solution (Python):
def janken(a,b):
  if a==b:
    return 0
  elif a=="g" and b=="p":
    return 1
  else:
    return -1
s=0
S=list(input())
for i in range(len(S)):
  if i%2==0:
    k="g"
    s+=janken(S[i],k)
  else:
    k="p"
    s+=janken(S[i],k)
print(s)

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

n = len(s)

g_num = 0
p_num = 0
win = 0
lose = 0



for i in range(n):
    if s[i] == "g" and g_num >= p_num+1:
        p_num+=1
        win+=1
    elif s[i] == "g":
        g_num +=1
    elif s[i] == "p" and g_num >= p_num+1:
        p_num +=1
    else:
        g_num +=1
        lose+=1


print(win-lose)

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

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

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

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

if __name__ == '__main__':
    main()

Solution (Python):
def abc046_d():
    s = str(input())
    n = len(s)
    if n == 1: return 0
    gc = [0] * n
    pc = [0] * n
    for i, c in enumerate(s):
        gc[i] = gc[i-1] + c.count('g')
        pc[i] = pc[i-1] + c.count('p')
    ans = (gc[-1] - pc[-1]) // 2
    return ans

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

Solution (Python):
from collections import Counter

s=input()
c=Counter(s)
if len(s)%2==0:
    print(len(s)//2-c["p"])
else:
    print((len(s)-1)//2-c["p"])

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

p = 0
ans = 0

for i in range(n):
    s1 = s[i]
    if s1 == 'g':
        p += 1
    else:
        p -= 1
    n -= 1
    if p >= n:
        break

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

print(ans)

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

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

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    ans = len(S) // 2 - S.count('p')

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    g, p = 0, 0
    ans = 0
    for c in S:
        if g > p:
            p += 1
            if c == 'g':
                ans += 1
        else:
            g += 1
            if c == 'p':
                ans -= 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def LS2(): return list(sys.stdin.readline().rstrip())  

s = LS2()

a,b = 0,0
for i in s:
    if i == 'g':
        a += 1
    else:
        b += 1

print((a-b)//2)

Solution (Python):
s=input()
n=len(s)
pcnt,gcnt=0,0
ans=[""]*n
for i in range(n):
    if s[i]=="g":
        if gcnt>pcnt:
            ans[i]="p"
            pcnt+=1
        else:
            ans[i]="g"
            gcnt+=1
    if pcnt==n//2 or gcnt==-(-n//2):
        break
i,j=0,0

while -(-n//2)>gcnt:
    if ans[i]=="":
        ans[i]="g"
        gcnt+=1
    i+=1
while n//2>pcnt:
    if ans[j]=="":
        ans[j]="p"
        pcnt+=1
    j+=1
score=0

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

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
s=SI()
n=len(s)
count=0
for i in range(n):
    if s[i]=="p":
        count+=1
if n%2==0:
    pos=n//2
else:
    pos=(n-1)//2
ans=pos-count
print(ans)

Solution (Python):
def judge(mygp,yourgp):
  if mygp=='g' and yourgp=='p':
    return -1
  elif mygp=='p' and yourgp=='g':
    return 1
  else:
    return 0

s=[x for x in input()]
t=[['g','p'][x%2] for x in range(len(s))]
print(sum([judge(a,b) for a,b in zip(t,s)]))

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

Solution (Python):
S = list(input())
N = len(S)
gp = ["g","p"]
out = 0
for i in range(N):
    if i%2==0:
        hand = "g"
    else:
        hand = "p"
    if hand==S[i]:
        out += 0
    elif hand=="p" and S[i]=="g":
        out += 1
    elif hand=="g" and S[i]=="p":
        out += -1
print(out)

Solution (Python):
def solve():
    opponent = input()
    p_amt = len(opponent) // 2
    me = "p" * p_amt + "g" * (len(opponent) - p_amt)

    ans = 0
    for i in range(len(opponent)):
        if opponent[i] == "g" and me[i] == "p":
            ans += 1
        
        if opponent[i] == "p" and me[i] == "g":
            ans -= 1
    
    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    ro = 0
    pa = 0
    score = 0

    for hand in s:
        if hand == "g":
            if pa < ro:
                pa += 1
                score += 1
            else:
                ro += 1
        else:
            if pa < ro:
                pa += 1
            else:
                ro += 1
                score -= 1

    print(score)

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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


def 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)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




S = S()
ans = 0
for s in S:
  if s == "g":
    ans -= 1
  else:
    ans += 1
print(-ans//2)

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    T A
    ---

    0 0 0
    1 1 0
    0 0 1

    number of 0s >= number of 1s
    p = 1
    g = 0

    N <= 10**5

    0 0
    0 0
    1 0
    1 0
    0 0
    0 1
    0 1
    1 1
    0 1
    0 1

    1. N/2 1's will be used
    """
    s = input().strip()
    N = len(s)
    score = 0
    for i in range((N+1)//2):
        if s[i] == 'p':
            score -= 1
    for i in range((N+1)//2, N):
        if s[i] == 'g':
            score += 1
    return score



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

Solution (Python):

def resolve():
    S = list(input())
    n_p = S.count("p")
    max_p = len(S)//2 if len(S)%2==0 else (len(S)-1)//2
    print(max_p-n_p)

if __name__ == '__main__':
    resolve()

Solution (Python):
def main():
    print(sum((1 - (-1) ** i) // 2 if j == 'g' else (1 - (-1) ** i) // 2 - 1 for i, j in enumerate(input())))


if __name__ == '__main__':
    main()

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

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

if __name__ == '__main__':
    main()

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()

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


if __name__ == '__main__':
    resolve()

Solution (Python):
s=input()
np=0
ng=0
ans=0
for si in s:
  if si=='g' and np<ng:
    ans+=1
    np+=1
  elif si=='g' and np>=ng:
    ng+=1
  elif si=='p' and np<ng:
    np+=1
  elif si=='p' and np>=ng:
    ans-=1
    ng+=1
print(ans)

Solution (Python):
s = input()

p = 0
g = 0
res = 0

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

print(res)

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

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

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

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






S = input()
N = len(S)

def counter(str, index):
    n_s = len(str)
    cnt = 0
    if n_s == 1 and index == N - 1:
        if str == 'g':
            cnt += 1
    

    elif n_s == 2:
        if str == 'gg':
            cnt += 1
        
        elif str == 'pp':
            cnt -= 1
    return cnt

ans = 0
for i in range(-1, N, 2):
    str_S = S[max(0, i):min(N - 1, i + 1) + 1]
    ans += counter(str_S, i)
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    s=SI()
    print(len(s)//2-s.count("p"))

main()

Solution (Python):
def main():
    S = input()
    p = sum([1 for c in S if c == 'p'])
    print(len(S) // 2 - p)


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
def v():
    pt=[5,0,1,2]
    s=list(map(lambda x: '0' if x=='g' else '1', sys.stdin.readline().strip()))
    n=len(s)
    p=pt[n%4]
    for _ in range(n//4):p=(p<<4)+5
    ss=list(format(p,'b').zfill(n))
    res=0
    for a,b in zip(s,ss):
        d=int(b)-int(a)
        res = res if d==0 else res+d
    print(res)
if __name__=='__main__':v()

Solution (Python):
import sys
def v():
    pt=[5,0,1,2]
    s=list(map(lambda x: '0' if x=='g' else '1', list(sys.stdin.readline().strip())))
    n=len(s)
    p=pt[n%4]
    for _ in range(n//4):p=(p<<4)+5
    ss=list(format(p,'b').zfill(n))
    res=0
    for a,b in zip(s,ss):
        d=int(b)-int(a)
        res = res if d==0 else res+d
    print(res)
if __name__=='__main__':v()

Solution (Python):
import sys
import math
def v():
    pt=[5,0,1,2]
    N=100000
    s=list(map(lambda x: '0' if x=='g' else '1', list(sys.stdin.readline().strip())))
    n,x=len(s),int(''.join(s),2)
    s=list(format(x<<(N-n),'0100000b'))
    p=pt[n%4]
    for _ in range(n//4):p=(p<<4)+5
    ss=list(format(p<<(N-n),'010000b'))
    res=0
    for _,a,b in zip(range(n),s,ss):
        d=int(b)-int(a)
        res = res if d==0 else res+d
    print(res)
if __name__=='__main__':v()

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

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

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

Solution (Python):
s = input()
ls = len(s)
cnt = [0, 0]
for c in list(s):
    cnt[c != "g"] += 1

if ls % 2 == 1:
    ls -= 1

print(ls//2-cnt[1])

Solution (Python):
import numpy as np
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

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

Solution (Python):
S = input()
ans = 0
hand = ['g', 'p']

def do(s, t):
  if s == t:
    return 0
  elif s == 'g':
    return 1
  else:
    return -1

for i, s in enumerate(S):
  ans += do(s, hand[i%2])

print(ans)

Solution (Python):
z = 0
for i, c in enumerate(input().replace("g", "r")):
    if i % 2 == 0 and c == "r":
        pass
    elif i % 2 == 0 and c == "p":
        z -= 1
    elif c == "p":
        pass
    else:
        z += 1
print(z)

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

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

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

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

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

Solution (Python):
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

s = list(input().rstrip())
g = 0
p = 0
res = []
ans = 0

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

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

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

surplus = ng - np
print(surplus // 2)

Solution (Python):
def main():
    s = input()
    score = 0
    diff = 0
    for i in range(len(s)):
        if s[i] == "g":
            if diff == 0:
                diff += 1
            else:
                diff -= 1
                score += 1
        else:
            if diff == 0:
                diff = 1
                score -= 1
            else:
                diff -= 1
    print(max(score, 0))


if __name__ == '__main__':
    main()

Solution (Python):
g = 0
p = 0

ans = 0
for i in input():
    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()

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

max_p = (g+p)//2
max_g = g+p-(g+p)//2

print(max_p-(max_g-(g-max_p)))

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

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

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

print(answer)

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

num_g=num_p=0
answer=0
for i in range(len(s)):
  if num_g==num_p:
    num_g+=1
    if s[i]=="p":
      answer-=1
  else:
    num_p+=1
    if s[i]=="g":
      answer+=1

print(answer)

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

Solution (Python):
s=input()
pcount,gcount=0,0
pp=False
res=0
for ele in s:
  if pcount<gcount:
    pp=True
  else:pp=False
  if pp :
    pcount+=1
    if ele=="g":
          res+=1
  else:
      gcount+=1
      if ele=="p":
          res-=1
print("{}".format(res))

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

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

print(score)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=input()
    ans=0
    for i,s in enumerate(S):
        if i%2==0 and s=='p':
            ans-=1
        if i%2==1 and s=='g':
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()