s = eval(input())

n = len(s)

gcount = 0

pcount = 0

score = 0

for i in range(n):

    if s[i] == "g":

        if gcount > pcount:

            pcount += 1

            score += 1

        else:

            gcount += 1

    else:

        if gcount > pcount:

            pcount += 1

        else:

            gcount += 1

            score -= 1

print(score)
import math

s = eval(input())

n = len(s)

print((math.floor(n/2) - s.count("p")))
s = eval(input())
n = len(s)
gcount = 0
pcount = 0
score = 0
for i in range(n):
    if s[i] == "g":
        if gcount > pcount:
            pcount += 1
            score += 1
        else:
            gcount += 1
    else:
        if gcount > pcount:
            pcount += 1
        else:
            gcount += 1
            score -= 1
print(score)

import math

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

+import math + -gcount = 0 -pcount = 0 -score = 0 -for i in range(n): -    if s[i] == "g": -        if gcount > pcount: -            pcount += 1 -            score += 1 -        else: -            gcount += 1 -    else: -        if gcount > pcount: -            pcount += 1 -        else: -            gcount += 1 -            score -= 1 -print(score) +print((math.floor(n / 2) - s.count("p")))