S = eval(input())



count = 0

for s in S :

    if s == 'p' :

        count += 1



ans = -count + len(S) // 2

print(ans)
S = eval(input())



now = 0

ans = 0

for s in S:

    if now == 0:

        now += 1

        if s == 'p':

            ans -= 1

        continue

    if s == 'g':

        ans += 1

    now -= 1



print(ans)

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

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

-count = 0 +now = 0 +ans = 0 -    if s == "p": -        count += 1 -ans = -count + len(S) // 2 +    if now == 0: +        now += 1 +        if s == "p": +            ans -= 1 +        continue +    if s == "g": +        ans += 1 +    now -= 1