AtCoDeer and his friend TopCoDeer are playing a game with N turns. Each player chooses between Rock and Paper, following the rule that the number of times a player plays Paper is less than or equal to the number of times they play Rock. The score is calculated by the number of wins minus the number of losses. AtCoDeer can predict TopCoDeer's gestures for each turn. The task is to plan AtCoDeer's gestures to maximize his score. The input is a string s representing TopCoDeer's gestures, and the output should be AtCoDeer's maximum possible score. The constraints are 1 ≤ N ≤ 10^5, N = |s|, and each character in s is either 'g' or 'p', satisfying the given condition. Two sample inputs and outputs are provided as examples.

# Buggy version:
s = input()
n = len(s)
p = 0
for e in s:
  if e == 'p':
    p += 1
print(s//2 - p)

# Fixed version:
s = input()
n = len(s)
p = 0
for e in s:
  if e == 'p':
    p += 1
print(n//2 - p)

# Buggy version:
def abc046_d():
    s = str(input())
    n = len(s)
    if n == 1: return 0
    gc = [0] * n
    pc = [0] * n
    for i, c in enumerate(s):
        gc[i] = gc[i-1] + c.count('g')
        pc[i] = pc[i-1] + c.count('p')
    print(gc)
    print(pc)
    ans = (gc[-1] - pc[-1]) // 2
    return ans

if __name__ == '__main__':
    print(abc046_d())

# Fixed version:
def abc046_d():
    s = str(input())
    n = len(s)
    if n == 1: return 0
    gc = [0] * n
    pc = [0] * n
    for i, c in enumerate(s):
        gc[i] = gc[i-1] + c.count('g')
        pc[i] = pc[i-1] + c.count('p')
    ans = (gc[-1] - pc[-1]) // 2
    return ans

if __name__ == '__main__':
    print(abc046_d())

# Buggy version:
s=input()
n=len(s)
t=0
for i in range(n):
  if s[i]==p:
    t+=1
print(int(n/2)-t)

# Fixed version:
s=input()
n=len(s)
t=0
for i in range(n):
  if s[i]=="p":
    t+=1
print(int(n/2)-t)

# Buggy version:
print(input().count('g')-(-((-len(s))//2)))

# Fixed version:
s = input()
print(s.count('g')-(-((-len(s))//2)))

# Buggy version:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    n = len(s)
    res = 0
    for i in range(n):
        if i <= n//2:
            if s[i]=='p':
                res -= 1
        else:
            if s[i] == 'g':
                res += 1
    print(res)

if __name__ == '__main__':
    main()

# Fixed version:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    n = len(s)
    res = 0
    for i in range(n):
        if i <= (n-1)//2:
            if s[i]=='p':
                res -= 1
        else:
            if s[i] == 'g':
                res += 1
    print(res)

if __name__ == '__main__':
    main()

# Buggy version:
#coding: utf-8
import math

s = input()
ans = math.ceil(len(s)/2) - s.count("p")
print(ans)

# Fixed version:
#coding: utf-8
import math

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

# Buggy version:
s=raw_input()

p=0

for i in range(len(s)):
    if s[i] == 'p':
        p += 1

print (len(s)//2 - p)

# Fixed version:
s = input()
p = 0
for i in range(len(s)):
    if s[i] == 'p': p += 1
print(-p + len(s) // 2)

# Buggy version:
s=input()
g=s.count('g')
p=s.count('p')
a=g-p+(g+p)//2
print(a)

# Fixed version:
s=input()
g=s.count('g')
p=s.count('p')
a=(-p+(g+p)//2)
print(a)

# Buggy version:
s = list(input())
n = len(s)
ans = 0
for i in range(n):
  if s[i] == "g" and flag == 0:
    flag+=1
  elif s[i] == "g" and flag != 0:
    flag -= 1
    ans += 1
  elif s[i] == "p" and flag == 0:
    flag += 1
    ans -= 1
  else:
    flag -= 1
print(ans)
    
    

# Fixed version:
s = list(input())
n = len(s)
ans = 0
flag = 0
for i in range(n):
  if s[i] == "g" and flag == 0:
    flag+=1
  elif s[i] == "g" and flag != 0:
    flag -= 1
    ans += 1
  elif s[i] == "p" and flag == 0:
    flag += 1
    ans -= 1
  else:
    flag -= 1
print(ans)

# Buggy version:
s = input()
score = 0
toUse = 0
for it in s:
  if it == 'g' and toUse > 0:
    toUse -= 1
    score += 1
    continue
  if it == 'g':
    continue
  if toUse > 0:
    toUse -= 1
  else:
    score -=1
    
print(score)


# Fixed version:
s = input()
score = 0
toUse = 0
for it in s:
  if it == 'g' and toUse > 0:
    toUse -= 1
    score += 1
    continue
  if it == 'g':
    toUse += 1
    continue
  if toUse > 0:
    toUse -= 1
  else:
    toUse += 1
    score -=1
    
print(score)

# Buggy version:
hands = input()
ans = 0
for i, h in enumerate(hands):
  if i % 2 == 1:
    if h == "p":
      ans -= 1
  else:
    if h == "g":
      ans += 1
      
print(ans)
   

# Fixed version:
hands = input()
ans = 0
for i, h in enumerate(hands):
  if i % 2 == 0:
    if h == "p":
      ans -= 1
  else:
    if h == "g":
      ans += 1
      
print(ans)

# Buggy version:
s = input()
n = len(s)

s = [i for i in s]
for i in range(n):
    if s[i] == "p":
        s[i] = 1
    else:
        s[i] = 0
print(s)

d = [0]*n
d[0] = 0
gc = 1
pc = 0
for i in range(1, n):
    if gc-1 >= pc:
        d[i] = 1
        pc += 1
    else:
        d[i] = 0
        gc += 1
print(d)

ans = 0
for i in range(n):
    ans += d[i]-s[i]

print(ans)

# Fixed version:
s = input()
n = len(s)

s = [i for i in s]
for i in range(n):
    if s[i] == "p":
        s[i] = 1
    else:
        s[i] = 0

d = [0]*n
d[0] = 0
gc = 1
pc = 0
for i in range(1, n):
    if gc-1 >= pc:
        d[i] = 1
        pc += 1
    else:
        d[i] = 0
        gc += 1

ans = 0
for i in range(n):
    ans += d[i]-s[i]

print(ans)

# Buggy version:
s = input()

score = 0
for i in range(len(s)):
  if i % 2 == 0 and s[i] = "p":
    score -= 1
  elif i % 2 != 0 and s[i] = "g":
    score += 1

print(s)

# Fixed version:
s = input()

score = 0
for i in range(len(s)):
  if i % 2 == 0 and s[i] == "p":
    score -= 1
  elif i % 2 != 0 and s[i] == "g":
    score += 1

print(score)

# Buggy version:
s = input()
print((s.count('p') - s.count('g')) // 2)

# Fixed version:
s = input()
print((s.count('g') - s.count('p')) // 2)

# Buggy version:
s=input()
g=p=a=0
for t in s:
  if t=='g':
    g+=1
  else:
    if p<g:
      p+=1
      a+=1
    else:
      g+=1
      a-=1
print(a+(g-p)//2)

# Fixed version:
s=input()
g=p=a=0
for t in s:
  if t=='g':
    g+=1
  else:
    if p<g:
      p+=1
    else:
      g+=1
      a-=1
print(a+(g-p)//2)

# Buggy version:
lis = list(input())
cou = 0
ans = 0
for i in range(len(lis)):
	if lis[i] == "g":
      if cou > 0:
        cou -= 1
        ans += 1
      else:
        cou += 1
    else:
      if cou > 0:
        cou -= 1
      else:
        cou += 1
        ans -= 1
print(max(0,ans))

# Fixed version:
lis = list(input())
cou = 0
ans = 0
for i in range(len(lis)):
	if lis[i] == "g":
		if cou > 0:
			cou -= 1
			ans += 1
		else:
			cou += 1
	else:
		if cou > 0:
			cou -= 1
		else:
			cou += 1
			ans -= 1
print(max(0,ans))

# Buggy version:
s = input()
print(len(s) / 2 - s.count('p'))

# Fixed version:
s = input()
tp = s.count("p")
print(len(s)//2-tp)

# Buggy version:
s = input()

P = 0
for c in s:
  if c == 'p':
    P += 1

print(N//2 - P)

# Fixed version:
s = input()

P = 0
for c in s:
  if c == 'p':
    P += 1

print(len(s)//2 - P)

# Buggy version:
s = input()
g = 0
p = 0
for i in s:
    if i = "g":
        g += 1
    if i = "p":
        p += 1
print((g - p) // 2)

# Fixed version:
s = input()
g = 0
p = 0
for i in s:
    if i == 'g':
        g += 1
    if i == 'p':
        p += 1
print((g - p) // 2)