Problem:
 Score : 300 points    Problem Statement 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 1 gpg      Sample Output 1 0  Playing the same gesture as the opponent in each turn results in the score of 0 , which is the maximum possible score.       Sample Input 2 ggppgggpgg      Sample Output 2 2  For example, consider playing gestures in the following order: Rock, Paper, Rock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three victories and suffers one defeat, resulting in the score of 2 , which is the maximum possible score.

Solution (Python):

from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007


"""
a,b = LS()
c = int(a+b)
for i in range(1,1000):
    if i * i == c:
        print("Yes")
        quit()
print("No")
"""


"""
a,b = LI()
if a*b <= 0:
    print("Zero")
else:
    if b < 0:
        if (a-b) %2 == 1:
            print("Positive")
        else:
            print("Negative")
    else:
        print("Positive")
"""


"""
n = II()
s = SR(n)
march = [[] for i in range(5)]
ch = list("MARCH")
for i in s:
    for j in range(5):
        if i[0] == ch[j]:
            march[j].append(i)
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
            if len(march[i])*len(march[j])*len(march[k]) == 0:
                break
            ans += len(march[i])*len(march[j])*len(march[k])
print(ans)
"""


"""
n = II()
d = LIR(n)
q = II()
p = IIR(q)
d.insert(0,[0 for i in range(n+1)])
for i in range(n):
    d[i+1].insert(0,0)
for i in range(n):
    for j in range(n):
        d[i+1][j+1] += d[i+1][j]+d[i][j+1]-d[i][j]
ans = [0 for i in range(n**2+1)]

for a in range(n+1):
    for b in range(n+1):
        for c in range(a):
            for e in range(b):
                ans[(a-c)*(b-e)] = max(ans[(a-c)*(b-e)],d[a][b]-d[c][b]-d[a][e]+d[c][e])

for i in p:
    an = 0
    for a in range(i+1):
        an = max(an, ans[a])
    print(an)
"""


"""
s = list(S())
ans = -1
s.insert(0,0)
d = 0
for i in range(1,len(s)):
    if s[i] != d:
        d = s[i]
        ans += 1
print(ans)
"""


"""
n = II()
x,y = LI()
for _ in range(n-1):
    a,b = LI()
    if a == b:
        x = max(x,y)
        y = x
    else:
        i = max(x//a,y//b)
        while 1:
            if a*i >= x and b*i >= y:break
            i += 1
        x = a*i
        y = b*i
print(x+y)
"""


s = list(S())
p = 0
g = 0
for i in s:
    if i == "g":
        g += 1
    else:
        p += 1
ans = (g-p)//2
print(ans)

Solution (Python):
s = list(input())
a = ["g"] * (-(-len(s) // 2)) + ["p"] * (len(s) // 2)
ans = 0
for i in range(len(s)):
    if s[i] == "g" and a[i] == "p":
        ans += 1
    elif s[i] == "p" and a[i] == "g":
        ans -= 1
print(ans)

Solution (Python):
import collections

S = input()
N = len(S)
num_p = N // 2
c = collections.Counter(S)
ans = num_p - c['p']
print(ans)

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

Solution (Python):
s=input()
print(len(s)//2-s.count("p"))

Solution (Python):
s = input()

c = 0

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

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

Solution (Python):
ar = list(input())
g = 0
p = 0
count = 0
for a in ar:
    if a == "g":
        if g == p:
            g += 1
        else:
            p += 1
            count += 1
    else:
        if g == p:
            g += 1
            count -= 1
        else:
            p += 1
print(count)

Solution (Python):
s = input()
hmp = 0
ans = 0
for i in s:
    if i == 'g' and hmp > 0:
        hmp -= 1
        ans += 1
    elif i == 'g':
        hmp += 1
    elif hmp > 0:
        hmp -= 1
    else:
        hmp += 1
        ans -= 1
print(ans)

Solution (Python):
S = input()

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

Solution (Python):
S = input()

max_p = len(S)//2

g,p = 0,0
for s in S:
    if s == 'g':
        g += 1
    else:
        p += 1




print(max_p - p)

Solution (Python):
s=input().strip()
N=len(s)
po=0
for i in range(N):
    if s[i]=='p':
        po+=1

print(N//2 -po)

Solution (Python):
s = list(input())
print(len(s)//2-s.count("p"))

Solution (Python):
s=input()
ans = 0
p_n = 0; g_n = 0
for s_i in s:
    if s_i == "g":
        if p_n < g_n:
            ans += 1
            p_n += 1
        else:
            g_n += 1
    else:
        if p_n < g_n:
            p_n += 1
        else:
            g_n += 1
            ans -= 1
print(ans)

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

Solution (Python):
S = list(input())
g = S.count("g")
p = S.count("p")

s = len(S)

if s % 2 == 0:
	print(int(s // 2) - p)
else:
	print(int((s - 1) // 2) - p)

Solution (Python):
ss = input()

ans = 0
for i, s in enumerate(ss, 1):
    if i % 2: 
        if s == 'p':
            ans -= 1
    else: 
        if s == 'g':
            ans += 1

print(ans)

Solution (Python):
s = input()
gmp = 0

ans = 0
k = ''
for si in s:
    if si == 'g':
        if gmp > 0:
            ans += 1
            gmp -= 1
            k+='p'
        else:
            gmp += 1
            k+='g'
    else:
        if gmp > 0:
            gmp -= 1
            k+='p'
        else:
            gmp += 1
            ans -= 1
            k+='g'

print(ans)

Solution (Python):
s = str(input())
g = s.count("g")
p = s.count("p")
print((g-p)//2)

Solution (Python):
g,p,w,l=0,0,0,0
for s in input():
  if s=="g":
    if g>p:
      p+=1
      w+=1
    else:
      g+=1
  else:
    if g>p:
      p+=1
    else:
      g+=1
      l+=1

print(w-l)

Solution (Python):
s = input()
at = 0
to = 0
res = 0

for i in s:
    if i == "g":
        to += 1
        if at > 0:
            at -= 1
            res += 1
        else:
            at += 1
    elif i == "p":
        to -= 1
        if at > 0:
            at -= 1
        else:
            at += 1
            res -= 1
else:
    print(res)

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

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

Solution (Python):

s = input()

cp = 0
cg = 0

for ss in list(s):
    if ss == "p":
        cp += 1
    else:
        cg += 1

if cg==cp:
    print(0)
else:
    print((cg+cp)//2 - cp)

Solution (Python):
s = raw_input()

res = 0
pre_sum = 0

for i in s:
	if i == 'p':
		res -= 1

res += len(s) / 2

print res

Solution (Python):
s = list(input())

all = len(s)
g = s.count('g')
p = s.count('p')

top = g-p

if all%2 == 1:
	deer = 1
	top += 1
	top //= 2
elif all%2 == 0:
	deer = 0
	top //= 2 
print(top - deer)

Solution (Python):
s = input()
print((s.count("g")-s.count("p"))//2)

Solution (Python):
s=input()


print(len(s)//2-s.count("p"))

Solution (Python):
s = raw_input()
print len(s) / 2 - s.count('p')

Solution (Python):
from collections import Counter
S = input()
C = Counter(S)
print((len(S)//2)+(C["p"]*(-1)))

Solution (Python):
def main():
    s = input()
    
    p = 0
    for i in range(len(s)):
        if s[i] == "p":
            p += 1
            
    print(len(s)//2-p)
    
    
if __name__ == "__main__":
    main()

Solution (Python):
s=list(input())
n=len(s)
score=0
g_cnt,p_cnt=1,0
if s[0]=="p":
    score-=1
for i in range(1,n):
    if g_cnt==p_cnt:
        if s[i]=="p":
            g_cnt+=1
            score-=1
        elif s[i]=="g":
            g_cnt+=1
    elif p_cnt<g_cnt:
        if s[i]=="p":
            p_cnt+=1
        elif s[i]=="g":
            p_cnt+=1
            score+=1
print(score)

Solution (Python):
s=input().rstrip()
win,lose=0,0
if s[0] == 'p':
  lose += 1
countg,countp=1,0
for i in range(1,len(s)):
  if s[i] =='g' and (countp +1 <= countg):
    win += 1
    countp += 1
  elif s[i] =='g':
    countg += 1
  elif s[i] =='p' and (countp +1 <= countg):
    countp += 1
  else:
    countg += 1
    lose += 1
print(win-lose)

Solution (Python):
s=input()
print(len(s)//2-s.count("p"))

Solution (Python):
n = input();print(len(n)//2-n.count('p'))

Solution (Python):
s = input()
n = len(s)
r = n // 2
p = s.count("p")
print(r-p)

Solution (Python):
s=input()
g=0
p=0
point=0
for i in s:
  if(i=="g"):
    if(p<g):
      point+=1
      p+=1
    else:
      g+=1
  else:
    if(p<g):p+=1
    else:
      g+=1
      point-=1
print(point)

Solution (Python):
print((lambda s:len(s)//2-s.count('p'))(input()))

Solution (Python):
s=input()
ret=0
for i in range(len(s)):
    ret+=(i%2)-[0,1][int(s[i]=="p")]
print(ret)

Solution (Python):
s = list(str(input()))

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

print(res)

Solution (Python):
s=input()
par=s.count("p")
print(len(s)//2-par)

Solution (Python):


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

Solution (Python):
S=input()
g=S.count('g')
p=S.count('p')
print((g+p)//2-p)

Solution (Python):
s = raw_input()

print len(s) / 2 - s.count("p")

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

Solution (Python):
s=input()
g,p=0,0
w,l=0,0
t=""
for c in s:
    if c == 'g' and p < g:
        w += 1
        p += 1
        t += 'p'
    else:
        g += 1
        t += 'g'
        if c == 'p':
            l += 1
for i in range(len(s)-1, -1, -1):
    if t[i] == 'g' and s[i] == 'p':
        if p+1 <= g-1:
            l -= 1
            p += 1
            g -= 1
print(w-l)

Solution (Python):
import sys

s = raw_input()
ps = len(s) / 2
gs = len(s) - ps
at = list('g'*gs + 'p'*ps)
top = list(s)

w, l = 0, 0
for x in range(len(top)):
	if (at[x] == 'p' and top[x] == 'g'):
		w += 1
	elif (at[x] == 'g' and top[x] == 'p'):
		l += 1
	else:
		pass

print str(w-l)

Solution (Python):
def main():
    rival = list(input())
    possiblePaCount = 0
    intOut = 0
    result = ""

    for i in range(len(rival)):
        if rival[i] == "g":
            if possiblePaCount > 0:
                intOut += 1
                possiblePaCount -= 1
                result += "p"
            else:
                possiblePaCount = 1
                result += "g"

        if rival[i] == "p":
            if possiblePaCount > 0:
                possiblePaCount -= 1
                result += "p"
            else:
                result += "g"
                possiblePaCount = 1
                intOut -= 1

    print(intOut)
    
if __name__ == '__main__':
  main()

Solution (Python):

import math

list_gp = list(raw_input())

num_g = 0
num_p = 0
points = 0

for i in xrange(len(list_gp)):

	
	if ( num_g - num_p ) <= 0 :
		num_g += 1

		if list_gp[i] == "p":
			points -= 1

		continue

	
	if list_gp[i] == "p":
		
		num_p += 1
	elif list_gp[i] == "g":
		
		num_p += 1
		points += 1


print points

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

Solution (Python):
s = input()
N = len(s)
ans = 0
for i in range(N):
    c = s[i]
    if c =='p':
        ans -= 1

ans += N//2
print(ans)

Solution (Python):
from sys import stdin
a = stdin.readline().strip()
ans = 0
cur = 0
res = ''
for i in a:
 if i=='p':
  if cur:
   res += "p"
   cur-=1
  else:
   res += "g"
   cur += 1
   ans -=1
 else:
  if cur:
   res += 'p'
   ans += 1
   cur -= 1
  else:
   res += 'g'
   cur += 1
 
print ans

Solution (Python):
s= input()
N=len(s)
g_count=s.count('g')
p_count=s.count('p')

score= N//2 -p_count
print(score)

Solution (Python):
from collections import Counter

gp = Counter(input())
n = sum(gp.values())

print(n // 2 - gp["p"])

Solution (Python):
from collections import Counter
gps = Counter(input())
print(sum(gps.values())//2 - gps["p"])

Solution (Python):



from itertools import *
import random

S = input()
T = "gp" * len(S)
ans = 0
for s,t in zip(S,T):
    if t == 'g' and s == 'p':
        ans -= 1
    elif t == 'p' and s == 'g':
        ans += 1
print(ans)

Solution (Python):



from itertools import *
import random

S_input = input()
def greedy(S):
    stack = 0
    score = 0
    debug = []
    for ch in S:
        my = ''
        if stack == 0:
            my = 'g'
            stack += 1
        else:
            my = 'p'
            stack -= 1

        debug.append(my)
        if my == 'g' and ch == 'p':
            score -= 1
        elif my == 'p' and ch == 'g':
            score += 1
    
    return max(score,0)


























































        


print(greedy(S_input))

Solution (Python):
s = raw_input()
print len(s) / 2 - s.count("p")

Solution (Python):
s=raw_input()
cntg=0
cntp=0
ans=0
for i in xrange(len(s)):
    if cntg>cntp:
        if s[i]=="g":
            cntp+=1
            ans+=1
        else:
            cntp+=1
    else:
        if s[i]=="g":
            cntg+=1
        else:
            cntg+=1
            ans-=1
print(ans)

Solution (Python):


c = w = l = 0
for i in input():
    if c == 0:
        c += 1
        if i == 'p':l += 1
    else:
        c -= 1
        if i == 'g' : w += 1
print(w-l)

Solution (Python):
s = raw_input()
n = len(s)

n_atcoder = n / 2
n_topcoder = 0
for c in s:
  if c == 'p':
    n_topcoder += 1

print n_atcoder - n_topcoder

Solution (Python):
s = input()
point = 0
p = 0
for l in s:
	if l == "g":
		if p > 0:
			p -= 1
			point += 1
		else:
			p += 1
	else:
		if p > 0:
			p -= 1
		else:
			point -= 1
			p += 1
print(point)

Solution (Python):
S = input()
n_p = S.count("p")
N = len(S)
ans = N // 2 - n_p
print(ans)

Solution (Python):
import math

S = raw_input()


rock = 0
paper = 0
score = 0
for n in S:
    if n == 'g': 
        if paper < rock:
            paper += 1
            score += 1
        else:
            rock += 1
    else:
        if paper < rock:
            paper += 1
        else:
            rock += 1
            score -= 1

print score

Solution (Python):
s = input()
g, p = 0, 0
score = 0
mp = {'p' : {'p' : 0, 'g' : 1}, 'g' : {'p' : -1, 'g' : 0}}
for c in s:    
    if p < g:
        p += 1
        a = 'p'
    else:
        g += 1
        a = 'g'
    score += mp[a][c]
print(score)

Solution (Python):
s = raw_input().strip()
l = len(s)
t = 'gp' * (l / 2 * 2)
w = 0
for i in xrange(l):
    if s[i] == 'g' and t[i] == 'p':
        w += 1
    if s[i] == 'p' and t[i] == 'g':
        w -= 1
print w

Solution (Python):

import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

EPS = 1e-9


def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def distance(a, b, c):
    if dot(b-a, c-a) <= EPS:
        return abs(c-a)
    if dot(a-b, c-b) <= EPS:
        return abs(c-b)
    return abs(cross(b-a, c-a)/(b-a))

S = s()

score = 0

if S[0] == 'p':
    score -= 1
g = 1
p = 0
for c in S[1:]:
    if p < g:
        p += 1
        if c == 'g':
            score += 1
    else:
        g += 1
        if c == 'p':
            score -= 1

print score

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7

def f():
    s = input()
    r = 0
    tt = ['g','p']
    t = 'g'
    i = 0
    for c in s:
        if c != t:
            if t == 'p':
                r += 1
            else:
                r -=1
        i += 1
        t = tt[i%2]
    return r

print(f())

Solution (Python):
S = raw_input()
print len(S)/2-S.count('p')

Solution (Python):
s = raw_input()
res = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == 'p':
            res -= 1
    else:
        if s[i] == 'g':
            res += 1
print res