def main():

    S = eval(input())

    ans = 0

    g_st = 0

    for s in S:

        if g_st == 0:

            g_st += 1

            if s == "p":

                ans -= 1

        else:

            g_st -= 1

            if s == "g":

                ans += 1

    print(ans)





if __name__ == '__main__':

    main()

def main():

    S = eval(input())

    ans = 0

    for i, s in enumerate(S):

        if i & 1:

            if s == "g":  # パー

                ans += 1

        else:

            if s == "p":

                ans -= 1

    print(ans)





if __name__ == '__main__':

    main()

def main():
    S = eval(input())
    ans = 0
    g_st = 0
    for s in S:
        if g_st == 0:
            g_st += 1
            if s == "p":
                ans -= 1
        else:
            g_st -= 1
            if s == "g":
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

def main():
    S = eval(input())
    ans = 0
    for i, s in enumerate(S):
        if i & 1:
            if s == "g":  # パー
                ans += 1
        else:
            if s == "p":
                ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

-    g_st = 0 -    for s in S: -        if g_st == 0: -            g_st += 1 +    for i, s in enumerate(S): +        if i & 1: +            if s == "g":  # パー +                ans += 1 +        else: -        else: -            g_st -= 1 -            if s == "g": -                ans += 1