s = input().rstrip()



iG = 0

iP = 0

iR = 0

for i in range(len(s)):

    if s[i] == "g":

        if iP < iG:

            iR += 1

            iP += 1

        else:

            iG += 1

    elif s[i] == "p":

        if iP < iG:

            iP += 1

        else:

            iR -= 1

            iG += 1



print(iR)

#len(s)//2-s.count("p")



iG = 0

iP = 0

iR = 0

for s in input().rstrip():

    if s == "g":

        if iP < iG:

            iR += 1

            iP += 1

        else:

            iG += 1

    else:

        if iP < iG:

            iP += 1

        else:

            iR -= 1

            iG += 1



print(iR)

s = input().rstrip()
iG = 0
iP = 0
iR = 0
for i in range(len(s)):
    if s[i] == "g":
        if iP < iG:
            iR += 1
            iP += 1
        else:
            iG += 1
    elif s[i] == "p":
        if iP < iG:
            iP += 1
        else:
            iR -= 1
            iG += 1
print(iR)

# len(s)//2-s.count("p")
iG = 0
iP = 0
iR = 0
for s in input().rstrip():
    if s == "g":
        if iP < iG:
            iR += 1
            iP += 1
        else:
            iG += 1
    else:
        if iP < iG:
            iP += 1
        else:
            iR -= 1
            iG += 1
print(iR)

-s = input().rstrip() +# len(s)//2-s.count("p") -for i in range(len(s)): -    if s[i] == "g": +for s in input().rstrip(): +    if s == "g": -    elif s[i] == "p": +    else: