# -*- coding: utf-8 -*-



import sys, re

from collections import deque, defaultdict, Counter

from math import sqrt, hypot, factorial, pi, sin, cos, radians

from heapq import heappop, heappush, heapify, heappushpop

from bisect import bisect_left, bisect_right

from itertools import permutations, combinations, product

from operator import itemgetter, mul

from copy import deepcopy

from functools import reduce, partial

from fractions import Fraction

from string import ascii_lowercase, ascii_uppercase, digits



def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

MOD = 10 ** 9 + 7



S = eval(input())

N = len(S)



T = 'gp' * (N//2) + 'g' * (N%2)

cnt = 0

for i in range(N):

    if S[i] == 'g' and T[i] == 'p':

        cnt += 1

    elif S[i] == 'p' and T[i] == 'g':

        cnt -= 1

print(cnt)

# -*- coding: utf-8 -*-



import sys

from collections import Counter



def input(): return sys.stdin.readline().strip()

def list2d(a, b, c): return [[c] * b for i in range(a)]

def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1): return int(-(-x // y))

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes(): print('Yes')

def No(): print('No')

def YES(): print('YES')

def NO(): print('NO')

sys.setrecursionlimit(10 ** 9)

INF = 10 ** 18

MOD = 10 ** 9 + 7



S = eval(input())



C = Counter(S)

ans = (C['g'] - C['p']) // 2

print(ans)

# -*- coding: utf-8 -*-
import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST():
    return list(map(int, input().split()))


sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
S = eval(input())
N = len(S)
T = "gp" * (N // 2) + "g" * (N % 2)
cnt = 0
for i in range(N):
    if S[i] == "g" and T[i] == "p":
        cnt += 1
    elif S[i] == "p" and T[i] == "g":
        cnt -= 1
print(cnt)

# -*- coding: utf-8 -*-
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def list2d(a, b, c):
    return [[c] * b for i in range(a)]


def list3d(a, b, c, d):
    return [[[d] * c for j in range(b)] for i in range(a)]


def list4d(a, b, c, d, e):
    return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]


def ceil(x, y=1):
    return int(-(-x // y))


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def LIST(N=None):
    return list(MAP()) if N is None else [INT() for i in range(N)]


def Yes():
    print("Yes")


def No():
    print("No")


def YES():
    print("YES")


def NO():
    print("NO")


sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
S = eval(input())
C = Counter(S)
ans = (C["g"] - C["p"]) // 2
print(ans)

-import sys, re -from collections import deque, defaultdict, Counter -from math import sqrt, hypot, factorial, pi, sin, cos, radians -from heapq import heappop, heappush, heapify, heappushpop -from bisect import bisect_left, bisect_right -from itertools import permutations, combinations, product -from operator import itemgetter, mul -from copy import deepcopy -from functools import reduce, partial -from fractions import Fraction -from string import ascii_lowercase, ascii_uppercase, digits +import sys +from collections import Counter + + +def list2d(a, b, c): +    return [[c] * b for i in range(a)] + + +def list3d(a, b, c, d): +    return [[[d] * c for j in range(b)] for i in range(a)] + + +def list4d(a, b, c, d, e): +    return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] + + +def ceil(x, y=1): +    return int(-(-x // y)) -def LIST(): -    return list(map(int, input().split())) +def LIST(N=None): +    return list(MAP()) if N is None else [INT() for i in range(N)] + + +def Yes(): +    print("Yes") + + +def No(): +    print("No") + + +def YES(): +    print("YES") + + +def NO(): +    print("NO") -INF = float("inf") +INF = 10**18 -N = len(S) -T = "gp" * (N // 2) + "g" * (N % 2) -cnt = 0 -for i in range(N): -    if S[i] == "g" and T[i] == "p": -        cnt += 1 -    elif S[i] == "p" and T[i] == "g": -        cnt -= 1 -print(cnt) +C = Counter(S) +ans = (C["g"] - C["p"]) // 2 +print(ans)