s = list(eval(input()))

count = 0

for i in s:

    if i == 'g':

        count += 1

    else:

        count -= 1

print((count//2))
s = list(eval(input()))

print(((s.count('g') - s.count('p'))//2))
s = list(eval(input()))
count = 0
for i in s:
    if i == "g":
        count += 1
    else:
        count -= 1
print((count // 2))

s = list(eval(input()))
print(((s.count("g") - s.count("p")) // 2))

-count = 0 -for i in s: -    if i == "g": -        count += 1 -    else: -        count -= 1 -print((count // 2)) +print(((s.count("g") - s.count("p")) // 2))