

def inpl():

    return list(map(int, input().split()))





S = eval(input())



ans = 0

g = 0

p = 0

for s in S:

    if g == p:

        g += 1

        if s == "g":

            pass

        elif s == "p":

            ans -= 1

    else:

        p += 1

        if s == "g":

            ans += 1

        elif s == "p":

            pass

print(ans)

def inpl():

    return list(map(int, input().split()))





S = eval(input())



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

def inpl():
    return list(map(int, input().split()))


S = eval(input())
ans = 0
g = 0
p = 0
for s in S:
    if g == p:
        g += 1
        if s == "g":
            pass
        elif s == "p":
            ans -= 1
    else:
        p += 1
        if s == "g":
            ans += 1
        elif s == "p":
            pass
print(ans)

def inpl():
    return list(map(int, input().split()))


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

-ans = 0 -g = 0 -p = 0 -for s in S: -    if g == p: -        g += 1 -        if s == "g": -            pass -        elif s == "p": -            ans -= 1 -    else: -        p += 1 -        if s == "g": -            ans += 1 -        elif s == "p": -            pass -print(ans) +print((len(S) // 2 - S.count("p")))