s=eval(input())

c=False

a=0

for i in s:

    if i=="g" and c:

        a+=1

    elif i=="p" and not c:

        a-=1

    c=not c

print(a)
s=eval(input())

g=s.count("g")

l=len(s)

print((l//2+g-l))
s = eval(input())
c = False
a = 0
for i in s:
    if i == "g" and c:
        a += 1
    elif i == "p" and not c:
        a -= 1
    c = not c
print(a)

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

-c = False -a = 0 -for i in s: -    if i == "g" and c: -        a += 1 -    elif i == "p" and not c: -        a -= 1 -    c = not c -print(a) +g = s.count("g") +l = len(s) +print((l // 2 + g - l))