ar = list(eval(input()))

g = 0

p = 0

count = 0

for a in ar:

    if a == "g":

        if g == p:

            g += 1

        else:

            p += 1

            count += 1

    else:

        if g == p:

            g += 1

            count -= 1

        else:

            p += 1

print(count)
s = eval(input())

l = len(s)

g = s.count('g')

p = s.count('p')

if g >= p:

    print(((g - p) // 2))

else:

    print((-(p - g) // 2))
ar = list(eval(input()))
g = 0
p = 0
count = 0
for a in ar:
    if a == "g":
        if g == p:
            g += 1
        else:
            p += 1
            count += 1
    else:
        if g == p:
            g += 1
            count -= 1
        else:
            p += 1
print(count)

s = eval(input())
l = len(s)
g = s.count("g")
p = s.count("p")
if g >= p:
    print(((g - p) // 2))
else:
    print((-(p - g) // 2))

-ar = list(eval(input())) -g = 0 -p = 0 -count = 0 -for a in ar: -    if a == "g": -        if g == p: -            g += 1 -        else: -            p += 1 -            count += 1 -    else: -        if g == p: -            g += 1 -            count -= 1 -        else: -            p += 1 -print(count) +s = eval(input()) +l = len(s) +g = s.count("g") +p = s.count("p") +if g >= p: +    print(((g - p) // 2)) +else: +    print((-(p - g) // 2))