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-----
gpg

-----Sample Output-----
0

Playing the same gesture as the opponent in each turn results in the score of 0, which is the maximum possible score.

Difficulty: interview

Starter code:

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

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


def __starting_point():
    main()

__starting_point()

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)

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)

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

def __starting_point():
    main()

__starting_point()

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

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

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

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

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)


import sys
def v():
    pt=[5,0,1,2]
    s=list(['0' if x=='g' else '1' for x in 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)
def __starting_point():v()

__starting_point()

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

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)

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)

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)


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


def __starting_point():
    main()

__starting_point()

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)
  return
  
if p==0 and gu==0:
  print(-g)
  return
  
if pa==0 and g==0:
  print(gu)
  return

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

def __starting_point():
    main()

__starting_point()

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

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


def __starting_point():
    main()


__starting_point()

s = input()

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

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

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)

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)


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

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


def __starting_point():
    main()

__starting_point()

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)


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)
      
    
     
  
  


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

def __starting_point():
  main()
__starting_point()

s = input()
slist = list(s)

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

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

print(res)

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


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

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)

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

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

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

T = input().strip()
n = len(T)

p = n // 2
g = n - p

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

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

print(ans)




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

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

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

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

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

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

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


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

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

# 同じものを含む順列
def permutation_with_duplicates(L):

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

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

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

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

        return ret


# ここから書き始める
s = input()
cntg = s.count("g")
cntp = s.count("p")
ans = max(0, cntg - cntp) // 2
print(ans)

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

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

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


s = input()

gs = 0
ps = 0

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

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

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)

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)

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

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

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

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)


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


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


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)

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)

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)


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

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


def __starting_point():
    main()
__starting_point()

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


ans = 0

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

print(ans)

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)

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


def __starting_point():
    main()

__starting_point()

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

def __starting_point():
    print(abc046_d())
__starting_point()

#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return list(map(int, input().split()))
    def mi_0():  return [int(x)-1 for x in input().split()]
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list([int(x)-1 for x in input().split()])
    def li():    return list(input())
    
    
    s = input()
    n = len(s)
    par_counter = s.count('p')
    print((n // 2 - par_counter))


def __starting_point():
    main()

__starting_point()

import sys
import math
def v():
    pt=[5,0,1,2]
    N=100000
    s=list(['0' if x=='g' else '1' for x in 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(list(range(n)),s,ss):
        d=int(b)-int(a)
        res = res if d==0 else res+d
    print(res)
def __starting_point():v()

__starting_point()

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


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)

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

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


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)

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

s = list(input())

n = len(s)

p = n//2

opp_p = s.count("p")

print(p-opp_p)

s = input()
n = len(s)

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

print(ans)

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

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

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
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()  # ignore trailing spaces

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)


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

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

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

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

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

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
#print(gcnt,pcnt)
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
#print(ans)
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)

def main():
    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
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

def __starting_point():
    main()
__starting_point()

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


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


s = input()

ans = 0

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

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

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)

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

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

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


s=input()

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

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

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

#coding: utf-8
import math

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

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)

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)


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


def __starting_point():
    resolve()

__starting_point()

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)

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

import sys
def v():
    pt=[5,0,1,2]
    s=list(['0' if x=='g' else '1' for x in 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)
def __starting_point():v()

__starting_point()

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

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

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)

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)