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.



Sample input:
gpg


Sample output:
0

Submission status: Accepted

Solution code:
S = input()

point = 0
can_p_cnt = 0
for i in range(len(S)):
  if S[i] == 'g':
    if can_p_cnt > 0:
      #p
      point += 1
      can_p_cnt -= 1
    else:
      #g
      can_p_cnt += 1
  else:
    if can_p_cnt > 0:
      can_p_cnt -= 1
    else:
      point -= 1
      can_p_cnt += 1
      
print(point)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
n = len(s)
count = Counter()
for c in s:
    if c == 'p':
        count[0] += 1
    elif c == 'g':
        count[1] += 1
print(n//2-count[0])

Submission status: Accepted

Solution code:
S = input()
res = len(S) // 2
for st in S:
    res -= int(st == "p")
print(res)

Submission status: Accepted

Solution code:
import collections
s =input()
s2=collections.Counter(s)
gu = s2['g']
pa = s2['p']
point = len(s)//2-pa
print(point)

Submission status: Accepted

Solution code:
#a
"""
import math
a, b = map(str, input().split())
j = int(a + b)
if math.sqrt(j).is_integer():
    print("Yes")
else:
    print("No")
"""

#b
"""
ans = ["Positive","Negative"]
a, b = map(int, input().split())
if 0 < a:
    print("Positive")
elif b >= 0:
    print("Zero")
else:
    print(ans[(b-a)%2-1])
"""

#C
"""
import itertools
n = int(input())
MARCH = ["M", "A", "R", "C", "H"]
march = [0 for _ in range(5)]
for i in range(n):
    s = input()
    if s[0] in MARCH:
        march[MARCH.index(s[0])] += 1
num = list(range(5))
a = list(itertools.combinations(num, 3))
ans = 0
for i in a:
    bf = 1
    for k in i:
        bf *= march[k]
    ans += bf
print(ans)
"""

#D
"""
n = int(input())
D = [list(map(int, input().split())) for _ in range(n)]
q = int(input())
p = [int(input()) for _ in range(q)]
ans = [[0 for i in range(n)] for _ in range(n)]
tate = [[[]]]
for i in range(n):
    for j in range(n):

for _ in p:
    print(ans[p])

"""
#E
"""
s = input()
bf = s[0]
ans = 0
for i in range(1,len(s)):
    if bf != s[i]:
        ans += 1
        bf = s[i]
print(ans)
"""

#F
"""
n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]
ans = ta[0]
for i in ta:
    if ans[0] <= i[0] and ans[1] <= i[1]:
        ans = i
    else:
        a = ((ans[0] - 1) // i[0]) + 1
        b = ((ans[1] - 1) // i[1]) + 1
        ab = max(a,b)
        ans = [i[0] * ab, i[1] * ab]
print(ans[0]+ans[1])
"""

#G
s = input()
ans = 0
for i in range(1,len(s)):
    if i % 2 == 1:
        if s[i] != "p":
            ans += 1
    else:
        if s[i] != "g":
            ans -= 1
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
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
"""
a,b = LS()
c = int(a+b)
for i in range(1,1000):
    if i * i == c:
        print("Yes")
        quit()
print("No")
"""

#B
"""
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")
"""

#C
"""
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)
"""

#D
"""
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)
"""
#E

"""
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)
"""

#F
"""
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)
"""
#G

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)


#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import collections

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
s = input()

c = 0

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

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
S = input()

max_p = len(S)//2

g,p = 0,0
for s in S:
    if s == 'g':
        g += 1
    else:
        p += 1
# print(g)
# print(p)
#print(max_p)

print(max_p - p)

Submission status: Accepted

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

print(N//2 -po)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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(k)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
s = raw_input()

res = 0
pre_sum = 0

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

res += len(s) / 2

print res

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 s[i] == 'g':
		if p + 1 <= g:
			p += 1
			res += 1
		else:
			g+=1

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = raw_input()

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys

s = raw_input()
ps = len(s) / 2
gs = len(s) - ps
at = list('g'*gs + 'p'*ps)
top = list(s)
#print 'at : ' + at
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)

Submission status: Accepted

Solution code:
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)
    #print(result)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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
    # print("myans:",debug)
    return max(score,0)

# def bf(S):
#     leng = len(S)
#     ret = 0
#     best = ""
#     for comb in product("gp", repeat=leng):
#         g_num = 0
#         valid = True
#         for ch in comb:
#             if ch == 'g':
#                 g_num += 1
#             else:
#                 g_num -= 1
#             if g_num < 0:
#                 valid = False
#                 break
#         if not valid:
#             continue


#         score = 0
#         for ch,my in zip(S,comb):
#             if my == 'g' and ch == 'p':
#                 score -= 1
#             elif my == 'p' and ch == 'g':
#                 score += 1
#         if score > ret:
#             ret = score
#             best = comb

#     # print("bf:",best)
#     return ret

# def main():

#     while True:
#         # q = "gggggp"

#         q = []
#         g_num = 0
#         for i in range(6):
#             if g_num == 0:
#                 q.append('g')
#                 g_num += 1
#             else:
#                 tmp = random.choice("gp")
#                 q.append(tmp)
#                 if tmp == 'g':
#                     g_num += 1
#                 else:
#                     g_num -= 1

#         ans1 = greedy(q)
#         ans2 = bf(q)
#         if ans1 != ans2:
#             print("q:", q)
#             print("ans1:",ans1)
#             print("ans2:",ans2)
        
# main()

print(greedy(S_input))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

S = raw_input()

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

print score

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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

#http://www.deqnotes.net/acmicpc/2d_geometry/lines
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

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()

grid = [0 if i == 'g' else 1 for i in s]


def biggest(grid):
    dist = [float('-inf')] * len(s)
    move = (0, 1)
    st = deque([[0, 0, 0, 0]])
    while st:
        g, p, idx, cur = st.popleft()
        if idx > len(s) - 1:
            continue
        for a in move:
            if a:
                if p + 1 > g:
                    continue
                tmpg, tmpp = g, p + 1
            else:
                tmpg, tmpp = g + 1, p
            if a > grid[idx]:
                tmp = cur + 1
            elif a < grid[idx]:
                tmp = cur - 1
            else:
                tmp = cur
            if dist[idx] < tmp:
                dist[idx] = tmp
            st.append([tmpg, tmpp, idx + 1, tmp])
    return dist[-1]


print(biggest(grid))

Submission status: Runtime Error

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys

input = sys.stdin.readline
_NUMINT_ALL = list(range(10))


def main():
    ans = solve()

    if ans is True or ans is False:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():
    s = iip()

    d = count_elements(s)
    #print(d)

    a = d["g"]
    b = d["p"]

    p_saizente = (a+b) // 2
    diff = (a+b) // 2 -p_saizente
    print(diff // 2)


#####################################################ライブラリ集ここから

def kiriage_warizan(a, b):
    return -(-a//b)


def iip(listed=True):  # 数字のinputをlistで受け取る
    d = input().rstrip("\n").split()
    try:
        ret = [int(i) for i in d]
    except:
        ret = [int(i) if i in _NUMINT_ALL else i for i in d]
        if len(ret) == 1:
            return ret[0]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iipt(l, listed=False, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed))
    return ret


def saidai_kouyakusuu(A):  # 最大公約数
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def make_graph_edge_flat(N):  # グラフ作成のための辺をリストで返す
    ret = []
    for i in range(N-1):
        a, b, c = iip()
        a -= 1
        b -= 1
        ret[a].append((b, c))
        ret[b].append((a, c))
    return ret


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


def nibutan_func(func, target, left, right, side="left"): # 関数を二分探索
    l = left
    r = right
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if func(x) == target:
            return x
        elif func(x) > target:
            r = x
        else:
            l = x

    if side == "left" or func(x) == target:
        return l
    else:
        return r


def nibutan_list(list_, target, side="left"):  # リストを二分探索
    if not isinstance(list_, list):
        list_ = list(list_)

    l = 0
    r = len(list_)
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if list_[x] == target:
            return x
        elif list_[x] > target:
            r = x
        else:
            l = x

    if side == "left" or list_[x] == target:
        return l
    else:
        return r


class UfTree():
    def __init__(self, maxnum):
        self.parent = list(range(maxnum))
        self._size = [1] * maxnum
        self.rank = [0] * maxnum

    def size(self, a):
        return self._size[self.root(a)]

    def root(self, a):
        rank = 0
        cur = a
        while True:
            if self.parent[cur] == cur:
                #for i in path: # 経路圧縮
                #    self.parent[i] = cur
                return cur
            else:
                self.parent[cur] = self.parent[self.parent[cur]]
                cur = self.parent[cur]
                rank += 1

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return self

        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        return self

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s = input()
t_s = n.count("p")
a_s = len(s) // 2
print(a_s-t_s)