S=eval(input())



G=P=0

K=0

for s in S:

    if P==G:

        if s=="p":

            K-=1

        G+=1

    else:

        if s=="g":

            K+=1

        P+=1



print(K)
S=eval(input())



K=0

for i in range(len(S)):

    if i%2==0 and S[i]=="p":

        K-=1

    elif i%2==1 and S[i]=="g":

        K+=1

print(K)
S = eval(input())
G = P = 0
K = 0
for s in S:
    if P == G:
        if s == "p":
            K -= 1
        G += 1
    else:
        if s == "g":
            K += 1
        P += 1
print(K)

S = eval(input())
K = 0
for i in range(len(S)):
    if i % 2 == 0 and S[i] == "p":
        K -= 1
    elif i % 2 == 1 and S[i] == "g":
        K += 1
print(K)

-G = P = 0 -for s in S: -    if P == G: -        if s == "p": -            K -= 1 -        G += 1 -    else: -        if s == "g": -            K += 1 -        P += 1 +for i in range(len(S)): +    if i % 2 == 0 and S[i] == "p": +        K -= 1 +    elif i % 2 == 1 and S[i] == "g": +        K += 1