s = eval(input())



x = 0

np = []

for i in reversed(list(range(len(s)))):

    if s[i] == 'p':

        x += 1

    np.append(x)

np = list(reversed(np))



y = 0

ans = 0

for i in range(len(s)):

    if s[i] == 'g':

        if y > np[i]:

            ans += 1

            y -= 1

        else:

            y += 1

    else:

        y -= 1

# print(np)

print(ans)

s = eval(input())



np = 0

for i in range(len(s)):

    if s[i] == 'p':

        np += 1



ans = len(s) // 2 - np

print(ans)

s = eval(input())
x = 0
np = []
for i in reversed(list(range(len(s)))):
    if s[i] == "p":
        x += 1
    np.append(x)
np = list(reversed(np))
y = 0
ans = 0
for i in range(len(s)):
    if s[i] == "g":
        if y > np[i]:
            ans += 1
            y -= 1
        else:
            y += 1
    else:
        y -= 1
# print(np)
print(ans)

s = eval(input())
np = 0
for i in range(len(s)):
    if s[i] == "p":
        np += 1
ans = len(s) // 2 - np
print(ans)

-x = 0 -np = [] -for i in reversed(list(range(len(s)))): +np = 0 +for i in range(len(s)): -        x += 1 -    np.append(x) -np = list(reversed(np)) -y = 0 -ans = 0 -for i in range(len(s)): -    if s[i] == "g": -        if y > np[i]: -            ans += 1 -            y -= 1 -        else: -            y += 1 -    else: -        y -= 1 -# print(np) +        np += 1 +ans = len(s) // 2 - np