s = eval(input())

n = len(s)



ans = 0

dif = 0



for i in range(n):

    if s[i] == 'g':

        if dif > 0:

            ans += 1

            dif -= 1

        else:

            dif += 1

    else:

        if dif > 0:

            dif -= 1

        else:

            ans -= 1

            dif += 1

            

print(ans)
s = eval(input())



p = 0

g = 0

res = 0



for i in range(len(s)):

    if s[i] == 'g':

        if p < g:

            p += 1

            res += 1

        else:

            g += 1

    else:

        if p < g:

            p += 1

        else:

            g += 1

            res -= 1



print(res)
s = eval(input())
n = len(s)
ans = 0
dif = 0
for i in range(n):
    if s[i] == "g":
        if dif > 0:
            ans += 1
            dif -= 1
        else:
            dif += 1
    else:
        if dif > 0:
            dif -= 1
        else:
            ans -= 1
            dif += 1
print(ans)

s = eval(input())
p = 0
g = 0
res = 0
for i in range(len(s)):
    if s[i] == "g":
        if p < g:
            p += 1
            res += 1
        else:
            g += 1
    else:
        if p < g:
            p += 1
        else:
            g += 1
            res -= 1
print(res)

-n = len(s) -ans = 0 -dif = 0 -for i in range(n): +p = 0 +g = 0 +res = 0 +for i in range(len(s)): -        if dif > 0: -            ans += 1 -            dif -= 1 +        if p < g: +            p += 1 +            res += 1 -            dif += 1 +            g += 1 -        if dif > 0: -            dif -= 1 +        if p < g: +            p += 1 -            ans -= 1 -            dif += 1 -print(ans) +            g += 1 +            res -= 1 +print(res)