s = eval(input())



l = len(s)



point = 0

cnt = 0

for i in s:

    if cnt > 0:

        cnt -= 1

        if i == 'g':

            point += 1

    else:

        cnt += 1

        if i == 'p':

            point -= 1

print(point)

s = eval(input())



l = len(s)



point = 0

for a, b in zip(s[0::2], s[1::2]):

    if a == 'p':

        point -= 1

    if b == 'g':

        point += 1

print(point)

s = eval(input())
l = len(s)
point = 0
cnt = 0
for i in s:
    if cnt > 0:
        cnt -= 1
        if i == "g":
            point += 1
    else:
        cnt += 1
        if i == "p":
            point -= 1
print(point)

s = eval(input())
l = len(s)
point = 0
for a, b in zip(s[0::2], s[1::2]):
    if a == "p":
        point -= 1
    if b == "g":
        point += 1
print(point)

-cnt = 0 -for i in s: -    if cnt > 0: -        cnt -= 1 -        if i == "g": -            point += 1 -    else: -        cnt += 1 -        if i == "p": -            point -= 1 +for a, b in zip(s[0::2], s[1::2]): +    if a == "p": +        point -= 1 +    if b == "g": +        point += 1