cp,score = 0,0

for s in eval(input()):

    if s == "g":

        if cp > 0:

            score += 1

            cp -= 1

        else:

            cp += 1

    elif s == "p":

        if cp > 0:

            cp -= 1

        else:

            score -= 1

            cp += 1

print(score)
S = eval(input())



cntP = 0

for s in S:

    if s=="p":

        cntP += 1



print((len(S)//2 - cntP))

cp, score = 0, 0
for s in eval(input()):
    if s == "g":
        if cp > 0:
            score += 1
            cp -= 1
        else:
            cp += 1
    elif s == "p":
        if cp > 0:
            cp -= 1
        else:
            score -= 1
            cp += 1
print(score)

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

-cp, score = 0, 0 -for s in eval(input()): -    if s == "g": -        if cp > 0: -            score += 1 -            cp -= 1 -        else: -            cp += 1 -    elif s == "p": -        if cp > 0: -            cp -= 1 -        else: -            score -= 1 -            cp += 1 -print(score) +S = eval(input()) +cntP = 0 +for s in S: +    if s == "p": +        cntP += 1 +print((len(S) // 2 - cntP))