s = eval(input())



g_num = s.count("g")

print((g_num - (len(s)+1)//2))
s = eval(input())

print((len(s)//2 - s.count("p")))
s = eval(input())
g_num = s.count("g")
print((g_num - (len(s) + 1) // 2))

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

-g_num = s.count("g") -print((g_num - (len(s) + 1) // 2)) +print((len(s) // 2 - s.count("p")))