AtCoDeer the deer and his friend TopCoDeer is playing a game.
The game consists of N turns.
In each turn, each player plays one of the two gestures, Rock and Paper, as in Rock-paper-scissors, under the following condition:
(※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock).
Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors.
(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)
With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts.
Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score.
The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is g, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in p, TopCoDeer will play Paper in the i-th turn.

-----Constraints-----
 - 1≦N≦10^5
 - N=|s|
 - Each character in s is g or p.
 - The gestures represented by s satisfy the condition (※).

-----Input-----
The input is given from Standard Input in the following format:
s

-----Output-----
Print the AtCoDeer's maximum possible score.

-----Sample Input-----
gpg

-----Sample Output-----
0

Playing the same gesture as the opponent in each turn results in the score of 0, which is the maximum possible score.

Difficulty: MEDIUM

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


s = str(input())
gn = int(s.count('g'))
pn = int(s.count('p'))
print((gn - pn) // 2)


s = input()
N = len(s)
Np = 0
for i in s:
	if i == 'p':
		Np += 1
ans = N // 2 - Np
print(ans)


from collections import Counter
s = input()
c = Counter(s)
g = c['g']
p = c['p']
print((g - p) // 2)


s = list(input())
ans = 0
for i in range(len(s)):
	if i % 2 == 0:
		if s[i] == 'p':
			ans -= 1
	elif s[i] == 'g':
		ans += 1
print(ans)


T = input().strip()
n = len(T)
p = n // 2
g = n - p
A = 'g' * g + 'p' * p
ans = 0
for (a, t) in zip(A, T):
	if a == 'p' and t == 'g':
		ans += 1
	if a == 'g' and t == 'p':
		ans -= 1
print(ans)


s = input()
n = len(s)
ans = 0
for i in range(0, n, 2):
	if s[i] == 'p':
		ans -= 1
for i in range(1, n, 2):
	if s[i] == 'g':
		ans += 1
print(ans)


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


s = input()
gcnt = 0
pcnt = 0
ans = 0
for c in s:
	if c == 'g':
		gcnt += 1
	else:
		pcnt += 1
print((gcnt - pcnt) // 2)


def main():
	s = input()
	print(len(s) // 2 - s.count('p'))

def __starting_point():
	main()
__starting_point()


import numpy as np
import sys

def sinput():
	return sys.stdin.readline()

def iinput():
	return int(sinput())

def imap():
	return map(int, sinput().split())

def fmap():
	return map(float, sinput().split())

def iarr():
	return list(imap())

def farr():
	return list(fmap())

def sarr():
	return sinput().split()
s = input()
p = g = ans = 0
for i in s:
	if i == 'p':
		if p < g:
			p += 1
		else:
			ans -= 1
			g += 1
	if i == 'g':
		if p < g:
			ans += 1
			p += 1
		else:
			g += 1
print(ans)


S = input()
counter = 0
for i in range(len(S)):
	if i % 2 == 1:
		if S[i] == 'g':
			counter += 1
	elif S[i] == 'p':
		counter -= 1
print(counter)


s = input()
g = p = 0
for c in s:
	if c == 'g':
		g += 1
	else:
		p += 1
if (g + p) % 2 == 0:
	print((g - p) // 2)
else:
	print((g - p - 1) // 2)


s = [i for i in input()]
(g, p) = (s.count('g'), s.count('p'))
print((g - p) // 2)


def judge(mygp, yourgp):
	if mygp == 'g' and yourgp == 'p':
		return -1
	elif mygp == 'p' and yourgp == 'g':
		return 1
	else:
		return 0
s = [x for x in input()]
t = [['g', 'p'][x % 2] for x in range(len(s))]
print(sum([judge(a, b) for (a, b) in zip(t, s)]))


S = input()
PossiblePaper = 0
Score = 0
for s in S:
	if s == 'g':
		if PossiblePaper == 0:
			Score += 0
			PossiblePaper += 1
		else:
			Score += 1
			PossiblePaper -= 1
	elif PossiblePaper == 0:
		Score -= 1
		PossiblePaper += 1
	else:
		Score += 0
		PossiblePaper -= 1
print(Score)


s = list(input())
answer = 0
for i in range(len(s)):
	if i % 2 == 0 and s[i] == 'p':
		answer -= 1
	elif i % 2 == 1 and s[i] == 'g':
		answer += 1
print(answer)


def main():
	s = input()
	cc_g = cc_p = 0
	for c in s:
		if c == 'g':
			cc_g += 1
		else:
			cc_p += 1
	print((cc_g - cc_p) // 2)
	return

def __starting_point():
	main()
__starting_point()


def main():
	S = input()
	p = sum([1 for c in S if c == 'p'])
	print(len(S) // 2 - p)
main()


s = input()
n_s = len(s)
n_g = n_s - 1
n_p = n_s // 2
print(n_p - s.count('p'))


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


s = input()
atd = ''
tpd = ''
for (i, t) in enumerate(s):
	if t == 'g':
		tpd += '0'
	else:
		tpd += '1'
	if i % 2 == 0:
		atd += '0'
	else:
		atd += '1'
point = 0
for (a, t) in zip(atd, tpd):
	x = int(a) - int(t)
	if x == 1:
		point += 1
	elif x == -1:
		point -= 1
print(point)


S = input()
p = 0
g = 0
a = 0
for s in S:
	if s == 'p':
		if p + 1 <= g:
			a += 0
			p += 1
		else:
			a -= 1
			g += 1
	elif p + 1 <= g:
		a += 1
		p += 1
	else:
		a += 0
		g += 1
print(a)


s = input()
pn = s.count('p')
print(int(len(s) / 2) - pn)


z = 0
for (i, c) in enumerate(input().replace('g', 'r')):
	if i % 2 == 0 and c == 'r':
		pass
	elif i % 2 == 0 and c == 'p':
		z -= 1
	elif c == 'p':
		pass
	else:
		z += 1
print(z)


import sys

def v():
	pt = [5, 0, 1, 2]
	s = list(['0' if x == 'g' else '1' for x in list(sys.stdin.readline().strip())])
	n = len(s)
	p = pt[n % 4]
	for _ in range(n // 4):
		p = (p << 4) + 5
	ss = list(format(p, 'b').zfill(n))
	res = 0
	for (a, b) in zip(s, ss):
		d = int(b) - int(a)
		res = res if d == 0 else res + d
	print(res)

def __starting_point():
	v()
__starting_point()


p = 0
g = 0
S = list(input())
ans = 0
for i in range(len(S)):
	if S[i] == 'g' and p < g:
		ans += 1
		p += 1
	elif S[i] == 'g' and p == g:
		g += 1
	if S[i] == 'p' and p < g:
		p += 1
	elif S[i] == 'p' and p == g:
		ans -= 1
		g += 1
print(ans)


s = input()
cnt_g = s.count('g')
cnt_p = s.count('p')
max_p = len(s) // 2
print(max_p - cnt_p)


s = input()
g_count = 0
p_count = 0
for c in s:
	if c == 'g':
		g_count += 1
	else:
		p_count += 1
print((g_count - p_count) // 2)


import math
s = input()
n = len(s)
p = sum((1 for c in s if c == 'p'))
print(math.floor(n / 2) - p)


s = input()
r = 0
p = 0
score = 0
for x in s:
	if x == 'g':
		if p < r:
			p += 1
			score += 1
		else:
			r += 1
	elif p < r:
		p += 1
	else:
		score -= 1
		r += 1
print(score)


from collections import Counter

def inpl():
	return list(map(int, input().split()))
S = input()
A = len(S) // 2
C = Counter(S)
print(A - C['p'])


s = input()
N = len(s)
ans = 0
for c in s:
	if c == 'p':
		ans -= 1
ans += N // 2
print(ans)


s = input()
N = len(s)
ans = 0
for i in range(N):
	if s[i] == 'g' and i % 2 == 1:
		ans += 1
	elif s[i] == 'p' and i % 2 == 0:
		ans -= 1
print(ans)


S = input()
g = 0
p = 0
for i in range(len(S)):
	if S[i] == 'g':
		g += 1
	else:
		p += 1
print(len(S) // 2 - p)


s = input()
c_g = 0
c_p = 0
win = 0
lose = 0
g_ = len(list(filter(lambda x: x == 'g', s)))
p_ = len(list(filter(lambda x: x == 'p', s)))
print((g_ - p_) // 2)


import math
s = input()
ans = 0
r = 0
p = 0
c = 0
for j in s:
	c = r - p
	if j == 'g':
		if c > 0:
			p += 1
			ans += 1
		else:
			r += 1
	elif c > 0:
		p += 1
	else:
		r += 1
		ans -= 1
print(ans)


s = input()
dic = {'g': 0, 'p': 0}
for ch in s:
	if ch == 'g':
		dic['g'] += 1
	else:
		dic['p'] += 1
print((dic['g'] - dic['p']) // 2)


s = input()
N = len(s)
D = {'g': 0, 'p': 0}
for i in range(N):
	D[s[i]] += 1
my_p = N // 2
score = my_p - D['p']
print(score)


s = input()
score = 0
for i in range(len(s)):
	if i % 2 == 0:
		if s[i] == 'p':
			score -= 1
	elif s[i] == 'g':
		score += 1
print(score)


s = str(input())
k = 0
p = 0
for i in range(len(s)):
	if k > 0:
		if s[i] == 'g':
			k -= 1
			p += 1
		else:
			k -= 1
	elif s[i] == 'g':
		k += 1
	else:
		k += 1
		p -= 1
print(p)


s = input()
m = s.count('g')
n = len(s)
print(m - n // 2 if n % 2 == 0 else m - 1 - n // 2)


S = input()
N = len(S)
P = S.count('p')
print(N // 2 - P)


ans = 0
for (i, c) in enumerate(input()):
	if i % 2 == 0 and c == 'p':
		ans -= 1
	elif i % 2 == 1 and c == 'g':
		ans += 1
print(ans)


import sys

def main():
	mod = 1000000007
	inf = float('inf')
	sys.setrecursionlimit(10 ** 6)

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

	def ii():
		return int(input())

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

	def mi_0():
		return [int(x) - 1 for x in input().split()]

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

	def lmi_0():
		return list([int(x) - 1 for x in input().split()])

	def li():
		return list(input())
	s = input()
	n = len(s)
	par_counter = s.count('p')
	print(n // 2 - par_counter)

def __starting_point():
	main()
__starting_point()


def main():
	s = input()
	score = 0
	diff = 0
	for i in range(len(s)):
		if s[i] == 'g':
			if diff == 0:
				diff += 1
			else:
				diff -= 1
				score += 1
		elif diff == 0:
			diff = 1
			score -= 1
		else:
			diff -= 1
	print(max(score, 0))

def __starting_point():
	main()
__starting_point()


s = input()
gs = 0
ps = 0
for ss in s:
	if ss == 'g':
		gs += 1
	else:
		ps += 1
print(max(0, (gs - ps) // 2))


s = input()
print(s.count('g') - -(-len(s) // 2))


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	S = readline().strip()
	ans = len(S) // 2 - S.count('p')
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


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


S = input()
score = 0
for (i, c) in enumerate(S):
	if i % 2:
		score += int(c == 'g')
	else:
		score += int(c == 'g') - 1
print(score)


s = input()
a = s.count('p')
print(int(len(s) // 2 - a))


s = input()
ans = 0
for i in range(len(s)):
	ans -= i % 2 == 0 and s[i] == 'p'
	ans += i % 2 == 1 and s[i] == 'g'
print(ans)


S = input()
P = 0
for i in range(len(S)):
	if i & 1:
		if S[i] == 'g':
			P += 1
	elif S[i] == 'p':
		P -= 1
print(P)


s = 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
	elif gcount > pcount:
		pcount += 1
	else:
		gcount += 1
		score -= 1
print(score)


from math import floor
s = input()
n = len(s)
p = s.count('p')
print(floor(n / 2) - p)


s = input()
slist = list(s)
gs = slist.count('g')
ps = slist.count('p')
if len(slist) % 2 == 0:
	res = (gs - ps) // 2
else:
	res = (gs - 1 - ps) // 2
print(res)


s = input()
n = len(s)
p_cnt = s.count('p')
print(n // 2 - p_cnt)


s = input()
countP = s.count('p')
half = len(s) // 2
ans = half - countP
print(ans)


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


s = input()
N = len(s)
if N % 2 == 0:
	print(N // 2 - s.count('p'))
else:
	print(N // 2 - s.count('p'))


s = input()
(g_cnt, p_cnt) = (0, 0)
ans = 0
for c in s:
	if c == 'g':
		if g_cnt > p_cnt:
			ans += 1
			p_cnt += 1
		else:
			g_cnt += 1
	elif g_cnt > p_cnt:
		p_cnt += 1
	else:
		ans -= 1
		g_cnt += 1
print(ans)


s = input()
g = 0
ans = 0
for h in s:
	if g > 0:
		if h == 'g':
			ans += 1
		g -= 1
	else:
		if h == 'p':
			ans -= 1
		g += 1
print(ans)


import io
data = input()
g = data.count('g')
p = data.count('p')
result = -p + (g + p) // 2
print(result)


from collections import Counter
s = input()
count = Counter(s)
ans = 0
for i in s[::-1]:
	if i == 'g':
		if count['g'] >= count['p'] + 2:
			ans += 1
			count['g'] -= 1
			count['p'] += 1
print(ans)


def main():
	print(sum(((1 - (-1) ** i) // 2 if j == 'g' else (1 - (-1) ** i) // 2 - 1 for (i, j) in enumerate(input()))))
main()


S = sorted(list(input()))
p = len(S) // 2
g = len(S) // 2
if len(S) % 2 == 1:
	g += 1
T = ['g'] * g + ['p'] * p
ans = 0
for i in range(len(S)):
	if T[i] == 'g' and S[i] == 'p':
		ans -= 1
	if T[i] == 'p' and S[i] == 'g':
		ans += 1
print(ans)


s = input()
ls = len(s)
cnt = [0, 0]
for c in list(s):
	cnt[c != 'g'] += 1
if ls % 2 == 1:
	ls -= 1
print(ls // 2 - cnt[1])


s = input()
print(s[1::2].count('g') - s[::2].count('p'))


s = list(input())
print((s.count('g') - s.count('p')) // 2)


gp = input()
p = gp.count('p')
g = gp.count('g')
print((g - p) // 2)


S = input().strip()
N = len(S)
gn = len([1 for i in range(N) if S[i] == 'g'])
gm = int((N + 1) / 2)
print(gn - gm)


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
	S = readline().strip()
	(g, p) = (0, 0)
	ans = 0
	for c in S:
		if g > p:
			p += 1
			if c == 'g':
				ans += 1
		else:
			g += 1
			if c == 'p':
				ans -= 1
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


S = input()
g = S.count('g')
p = len(S) - g
print(g - p >> 1)


S = input()
v = ['g', 'p']
ans = 0
for (i, s) in enumerate(S):
	if s != v[i % 2]:
		if s == 'g':
			ans += 1
		else:
			ans -= 1
print(ans)


S = input()
import collections
print(len(S) // 2 - collections.Counter(S)['p'])


s = input()
n = len(s)
print(s[(n + 1) // 2:].count('g') - s[:(n + 1) // 2].count('p'))


S = list(input())
a = 0
for (i, s) in enumerate(S):
	if i % 2 == 0:
		if s == 'p':
			a -= 1
	if i % 2 == 1:
		if s == 'g':
			a += 1
print(a)


from collections import Counter
s = input()
counter = Counter(s)
print(len(s) // 2 - counter['p'])


S = input()
print((S.count('g') - S.count('p')) // 2)


s = input()
N = len(s)
print(int(N / 2) - s.count('p'))


s = input()
num = len(s)
g_len = s.count('g')
g_num = -(-num // 2)
g_len -= g_num
print(g_len)


s = input()
P = 0
for c in s:
	if c == 'p':
		P += 1
print(len(s) // 2 - P)


s = input()
np = 0
ng = 0
ans = 0
for si in s:
	if si == 'g' and np < ng:
		ans += 1
		np += 1
	elif si == 'g' and np >= ng:
		ng += 1
	elif si == 'p' and np < ng:
		np += 1
	elif si == 'p' and np >= ng:
		ans -= 1
		ng += 1
print(ans)


import sys
s = sys.stdin.readline().rstrip()

def main():
	ans = len(s) // 2 - s.count('p')
	return ans
ans = main()
print(ans)


def d_atcodeer_and_rock_paper(S):
	return len(S) // 2 - S.count('p')
S = input().strip()
print(d_atcodeer_and_rock_paper(S))


s = input()
(g, p) = (0, 0)
for val in s:
	if val == 'g':
		g += 1
	else:
		p += 1
ans = 0
while g > p + 1:
	g -= 1
	p += 1
	ans += 1
print(ans)


s = input()
g_c = s.count('g')
p_c = s.count('p')
g_c = g_c - p_c
print(int(g_c / 2))


g = 0
p = 0
ans = 0
for i in input():
	if i == 'g':
		if p < g:
			ans += 1
			p += 1
		else:
			g += 1
	elif p < g:
		p += 1
	else:
		g += 1
		ans -= 1
print(ans)


s = input()
n = len(s)
p = 0
ans = 0
for i in range(n):
	s1 = s[i]
	if s1 == 'g':
		p += 1
	else:
		p -= 1
	n -= 1
	if p >= n:
		break
for i in range(n):
	if s[-i - 1] == 'g':
		ans += 1
print(ans)


s = list(str(input()))
T = 0
for i in range(len(s)):
	if s[i] == 'p':
		T += 1
print(len(s) // 2 - T)


s = list(input())
n = len(s)
p = n // 2
opp_p = s.count('p')
print(p - opp_p)


s = str(input())
n = len(s)
g_num = 0
p_num = 0
win = 0
lose = 0
for i in range(n):
	if s[i] == 'g' and g_num >= p_num + 1:
		p_num += 1
		win += 1
	elif s[i] == 'g':
		g_num += 1
	elif s[i] == 'p' and g_num >= p_num + 1:
		p_num += 1
	else:
		g_num += 1
		lose += 1
print(win - lose)


s = input()
n = len(s)
ans = n // 2 - s.count('p')
print(ans)


s = input() + 'g' + 'p'
import collections
S = dict(collections.Counter(s))
a = S['p'] - 1
b = S['g'] - 1
x = (a + b) // 2
print(x - a)


s = input()
p = len([c for c in s if c == 'p'])
print(len(s) // 2 - p)


s = list(input())
num_g = num_p = 0
answer = 0
for i in range(len(s)):
	if num_g == num_p:
		num_g += 1
		if s[i] == 'p':
			answer -= 1
	else:
		num_p += 1
		if s[i] == 'g':
			answer += 1
print(answer)


s = input()
n = len(s)
g_count = 0
p_count = 0
for i in range(n):
	if s[i] == 'g':
		g_count += 1
	else:
		p_count += 1
print((g_count - p_count) // 2)


def main():
	S = str(input())
	num = S.count('g') - S.count('p')
	print(num // 2)
main()


s = input()
c = False
a = 0
for i in s:
	if i == 'g' and c:
		a += 1
	elif i == 'p' and (not c):
		a -= 1
	c = not c
print(a)


s = input()
p = 0
for sv in s:
	if sv == 'p':
		p += 1
print(len(s) // 2 - p)


from collections import Counter
s = input()
n = len(s)
c = Counter(s)
print(n // 2 - c['p'])


def main():
	s = input()
	n = len(s)
	g = s.count('g')
	p = n - g
	ans = n // 2 - p
	print(ans)

def __starting_point():
	main()
__starting_point()


s = list(input())
g = s.count('g')
if len(s) % 2 == 0:
	print(g - len(s) // 2)
else:
	print(g - len(s) // 2 - 1)


s = input()
P = s.count('p')
print(max(0, len(s) // 2 - P))


x = input()
n = int(len(x) / 2)
a = 0
for i in x:
	if i == 'p':
		a += 1
print(n - a)


s = input()
l = len(s)
cp = s.count('p')
cg = l - cp
pmax = l // 2
print(pmax - cp)


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

def __starting_point():
	print(abc046_d())
__starting_point()


x = input()
n = int(len(x) / 2)
a = 0
ls = []

def fun():
	for i in range(2):
		ls.append(i)
for i in x:
	if i == 'p':
		a += 1
print(n - a)


s = str(input())
n = len(s)
G = s.count('g')
P = s.count('p')
ans = (G - P) // 2
print(ans)


s = input()
N = len(s)
Np = s.count('p')
r = N // 2 - Np
print(r)


s = input()
print(max((s.count('g') * 2 - len(s)) // 2, 0))


S = input()
print(len(S) // 2 - S.count('p'))


S = input()
p = 0
N = len(S)
for i in range(N):
	if S[i] == 'p':
		p += 1
print(N // 2 - p)


n = input()
a = n.count('g')
b = n.count('p')
print((a - b) // 2)


s = str(input())
n = len(s)
L = []
c = 0
ans = 0
for i in range(n):
	if c - 1 >= 0:
		if s[i] == 'g':
			ans += 1
			c -= 1
		else:
			c -= 1
	elif s[i] == 'g':
		c += 1
	else:
		ans -= 1
		c += 1
print(ans)


from collections import Counter
S = input()
N = len(S)
counter = Counter(S)
p_len = N // 2
print(p_len - counter['p'])


hands = input()
ans = 0
for (i, h) in enumerate(hands):
	if i % 2 == 0:
		if h == 'p':
			ans -= 1
	elif h == 'g':
		ans += 1
print(ans)


s = input()
n = len(s)
charge = 0
score = 0
for i in range(n):
	if s[i] == 'g':
		if charge > 0:
			score += 1
			charge -= 1
		else:
			charge += 1
	elif charge > 0:
		charge -= 1
	else:
		score -= 1
		charge += 1
print(score)


S = input()
li = [0] * len(S)
g = 0
p = 0
for v in S:
	if v == 'g':
		g += 1
	else:
		p += 1
print((g - p) // 2)


S = input()
ans = 0
hand = ['g', 'p']

def do(s, t):
	if s == t:
		return 0
	elif s == 'g':
		return 1
	else:
		return -1
for (i, s) in enumerate(S):
	ans += do(s, hand[i % 2])
print(ans)


N = input()
p = N.count('p')
print(len(N) // 2 - p)


s = input()
ans = 0
for i in range(len(s)):
	if s[i] == 'g':
		ans += 1
	else:
		ans -= 1
print(ans // 2)


s = input()
num = s.count('g') - s.count('p')
print((num - len(s) % 2) // 2)


s = input()
s = list(s)
ans = 0
for (i, j) in enumerate(s):
	if i % 2 == 0 and j == 'p':
		ans -= 1
	elif i % 2 == 1 and j == 'g':
		ans += 1
print(ans)


s = input()
num_g = s.count('g')
num_p = s.count('p')
print((num_g - num_p) // 2)


S = list(input())
count_P = S.count('p')
print(len(S) // 2 - count_P)


from collections import Counter
s = input()
c = Counter(s)
if len(s) % 2 == 0:
	print(len(s) // 2 - c['p'])
else:
	print((len(s) - 1) // 2 - c['p'])


s = list(input())
if len(s) % 2 == 1:
	ans = (s.count('g') - (s.count('p') + 1)) // 2
else:
	ans = (s.count('g') - s.count('p')) // 2
print(ans)


S = [1 if _ == 'p' else 0 for _ in input()]
N = len(S)
print(N // 2 - sum(S))


from collections import Counter
gp = Counter(input())
n = sum(gp.values())
print(n // 2 - gp['p'])


s = input()
c = s.count('p')
l = len(s)
ans = l // 2 - c
print(ans)


from collections import Counter
c = Counter(list(input().strip()))
print((c['g'] - c['p']) // 2)


s = input()
n = len(s)
(pcnt, gcnt) = (0, 0)
ans = [''] * n
for i in range(n):
	if s[i] == 'g':
		if gcnt > pcnt:
			ans[i] = 'p'
			pcnt += 1
		else:
			ans[i] = 'g'
			gcnt += 1
	if pcnt == n // 2 or gcnt == -(-n // 2):
		break
(i, j) = (0, 0)
while -(-n // 2) > gcnt:
	if ans[i] == '':
		ans[i] = 'g'
		gcnt += 1
	i += 1
while n // 2 > pcnt:
	if ans[j] == '':
		ans[j] = 'p'
		pcnt += 1
	j += 1
score = 0
for i in range(n):
	if ans[i] == 'p' and s[i] == 'g':
		score += 1
	elif ans[i] == 'g' and s[i] == 'p':
		score -= 1
print(score)


def main():
	s = input()
	ans = len(s) // 2
	for c in s:
		if c == 'p':
			ans -= 1
	print(ans)
main()


s = input()
gp = [1, 0]
p = 0
if s[0] == 'p':
	p -= 1
for i in range(1, len(s)):
	if s[i] == 'g':
		if gp[0] > gp[1]:
			gp[1] += 1
			p += 1
		else:
			gp[0] += 1
	if s[i] == 'p':
		if gp[0] > gp[1]:
			gp[1] += 1
		else:
			gp[0] += 1
			p -= 1
print(p)


S = input()
from collections import defaultdict as dd
Hand = dd(lambda : 0)
for s in S:
	Hand[s] += 1
ans = len(S) // 2 - Hand['p']
print(ans)


s = list(input())
countg = 0
countp = 0
for i in s:
	if i == 'g':
		countg += 1
	else:
		countp += 1
print(int((countg - countp) / 2))


S = input()
score = 0
for (i, b) in enumerate(S):
	a = 'gp'[i % 2]
	if (a, b) == ('p', 'g'):
		score += 1
	elif (a, b) == ('g', 'p'):
		score -= 1
print(score)


s = list(str(input()))
num_paper = len(s) // 2
print(num_paper - s.count('p'))


s = list(input())
a = s.count('p')
b = s.count('g')
print(len(s) // 2 - a)


s = list(input())
count = 0
for i in s:
	if i == 'g':
		count += 1
	else:
		count -= 1
print(count // 2)


S = input()
offsets = 0
for moji in S:
	if moji == 'p':
		offsets = offsets + 1
nagasa = len(S)
ans = nagasa // 2 - offsets
print(ans)


import collections
n = input()
c = collections.Counter(n)
print(len(n) // 2 - int(c['p']))


s = input()
g = s.count('g')
l = len(s)
print(g - (l + 1) // 2)


s = input()
p = 0
for x in s:
	if x == 'p':
		p += 1
print(len(s) // 2 - p)


s = input()
l = len(s)
i = 0
ans = 0
while i < l:
	if i % 2 == 0 and s[i] == 'p':
		ans += -1
	elif i % 2 == 1 and s[i] == 'g':
		ans += 1
	i += 1
print(ans)


s = input()
gu = 1
pa = 0
point = 0
if s[0] == 'p':
	point -= 1
for hand in s[1:]:
	if hand == 'g':
		if pa < gu:
			point += 1
			pa += 1
		else:
			gu += 1
	elif hand == 'p':
		if pa < gu:
			pa += 1
		else:
			gu += 1
			point -= 1
print(point)


s = input()
ng = s.count('g')
np = s.count('p')
surplus = ng - np
print(surplus // 2)


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 7)
	from collections import Counter, deque
	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
	s = input().rstrip()
	n = len(s)
	res = 0
	for i in range(n):
		if i <= (n - 1) // 2:
			if s[i] == 'p':
				res -= 1
		elif s[i] == 'g':
			res += 1
	print(res)

def __starting_point():
	main()
__starting_point()


def solve(s):
	return len(s) // 2 - s.count('p')
print(solve(input()))


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


s = input()
N = len(s)
P = s.count('p')
print(N // 2 - P)


s = input()
pa = 0
gu = 0
for i in range(len(s)):
	if s[i] == 'p':
		pa += 1
	else:
		gu += 1
print((gu - pa) // 2)


s = input()
s0 = s[::2]
s1 = s[1::2]
print(s1.count('g') - s0.count('p'))


s = input()
g = len(s.replace('p', ''))
p = len(s) - g
print(len(s) // 2 - p)


s = input()
l = len(s) // 2
p = list(s).count('p')
ans = l - p
print(ans)


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


s = input()
N = len(s)
ans = N // 2
for i in range(N):
	if s[i] == 'p':
		ans -= 1
print(ans)


s = input()
s_count = s.count('p')
s_len = len(s)
max_p = s_len // 2
ans = max_p - s_count
print(ans)


l = input()
g = list(filter(lambda s: s == 'g', l))
p = list(filter(lambda s: s == 'p', l))
print(int((len(g) - len(p)) / 2))


t = input()
tp = t.count('p')
ap = len(t) // 2
print(ap - tp)


import sys
import math

def v():
	pt = [5, 0, 1, 2]
	N = 100000
	s = list(['0' if x == 'g' else '1' for x in list(sys.stdin.readline().strip())])
	(n, x) = (len(s), int(''.join(s), 2))
	s = list(format(x << N - n, '0100000b'))
	p = pt[n % 4]
	for _ in range(n // 4):
		p = (p << 4) + 5
	ss = list(format(p << N - n, '010000b'))
	res = 0
	for (_, a, b) in zip(list(range(n)), s, ss):
		d = int(b) - int(a)
		res = res if d == 0 else res + d
	print(res)

def __starting_point():
	v()
__starting_point()


TopCoDeer = list(input())
n = len(TopCoDeer)
p_num = TopCoDeer.count('p')
print(n // 2 - p_num)


s = list(input())
n = len(s)
m = s.count('g')
x = n // 2 + n % 2
print(m - x)


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


s = input()
n = len(s) // 2
m = s.count('p')
print(n - m)


s = list(input())
T_g = s.count('g')
T_p = s.count('p')
if T_g == T_p or T_g == T_p + 1:
	result = 0
	print(result)
	return
else:
	P = (T_g + T_p) // 2
	result = P - T_p
	print(result)


S = input()
cntP = 0
for s in S:
	if s == 'p':
		cntP += 1
print(len(S) // 2 - cntP)


import math
s = input()
np = 0
for i in range(len(s)):
	if s[i] == 'p':
		np += 1
print(math.floor(len(s) / 2) - np)


import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	s = input()
	n = len(s) // 2
	p = s.count('p')
	print(n - p)

def __starting_point():
	resolve()
__starting_point()


S = input()
N = len(S)
print(N // 2 - sum([int(s == 'p') for s in S]))


S = input()
cp = 0
cg = 0
point = 0
for s in S:
	if s == 'g':
		if cp + 1 <= cg:
			point += 1
			cp += 1
		else:
			cg += 1
	elif cp + 1 <= cg:
		cp += 1
	else:
		point -= 1
		cg += 1
print(point)


from math import ceil
s = input()
gu = s.count('g')
pa = s.count('p')
p = len(s) // 2
g = int(ceil(len(s) / 2))
(gu, g) = (gu - min(gu, g), g - min(gu, g))
(pa, p) = (pa - min(pa, p), p - min(pa, p))
if g == 0 and gu == 0 and (p == 0) and (pa == 0):
	print(0)
	return
if p == 0 and gu == 0:
	print(-g)
	return
if pa == 0 and g == 0:
	print(gu)
	return


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, bisect
from operator import itemgetter
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
stdin = sys.stdin
ni = lambda : int(ns())
nf = lambda : float(ns())
na = lambda : list(map(int, stdin.readline().split()))
nb = lambda : list(map(float, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
s = ns()
ans = 0
ct = 0
for i in range(len(s)):
	if ct == 0:
		ct += 1
		if s[i] == 'p':
			ans -= 1
	else:
		ct -= 1
		if s[i] == 'g':
			ans += 1
print(ans)


s = input()
g = s.count('g')
p = s.count('p')
max_p = (g + p) // 2
max_g = g + p - (g + p) // 2
print(max_p - (max_g - (g - max_p)))


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


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