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):
s = list(input())
N = len(s)


win = 0
lose = 0
for i in range(N):
  if(i%2 == 0): 
    my_hand = 'g'
    if(my_hand != s[i]): lose += 1 
  else: 
    my_hand = 'p'
    if(my_hand != s[i]): win += 1 
  
ans = win-lose
print(ans)

Solution (Python):
S = input()

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

Solution (Python):
from sys import stdin
S = stdin.readline().rstrip()
len_S = len(S)
if len_S % 2 == 0:
    atcodeer = "gp"*(len_S//2)
else:
    atcodeer = "gp"*(len_S//2)+"g"

ans = 0
for s1, s2 in zip(S, atcodeer):
    if s1 == 'g' and s2 == 'p':
        ans += 1
    elif s2 == 'g' and s1 == 'p':
        ans -= 1
print(ans)

Solution (Python):
s = input()
N = len(s)
ans = 0
count = 0
for i in range(N):
    if s[i] == "g":
        if count > 0:
            count -= 1
            ans += 1
        else:
            count += 1
    else:
        if count > 0:
            count -= 1
        else:
            count += 1
            ans -= 1

print(ans)

Solution (Python):
S=input()

ans=0
for i in range(len(S)):
  if i%2==0:
    ans -= 0 if S[i]=="g" else 1
  else:
    ans += 1 if S[i]=="g" else 0
print(ans)

Solution (Python):
import numpy as np

s = input()
s_list = np.array([1 if s[i] == "p" else 0 for i in range(len(s))])
myhand = np.array([0 if i % 2 == 0 else 1 for i in range(len(s))])
print(np.sum(myhand - s_list))

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

Solution (Python):
def resolve():
    s = input()
    win, lose = 0, 0
    hands = {0: "g", 1: "p"}
    for i in range(len(s)):
        h = hands[i % 2]
        if s[i] == "g" and h == "p":
            win += 1
        elif s[i] == "p" and h == "g":
            lose += 1
    print(win - lose)


if __name__ == "__main__":
    resolve()

Solution (Python):
S = input()

e,o = [],[]
for i in range(len(S)):
    if i%2 == 0: e.append(S[i])
    else: o.append(S[i])

win,lose = 0,0
for s in e:
    if s == 'p': lose+=1
for s in o:
    if s == 'g': win+=1

print(win-lose)

Solution (Python):


s=list(input())
count=0

for i in range(len(s)):
    if s[i]=='g':
        s[i]=0
    else:
        s[i]=1
    if i&1^s[i]==1 and i&1==1:
        count+=1
    elif i&1^s[i]==1 and s[i]&1==1:
        count-=1
    else:
        pass

print(count)

Solution (Python):
S = str(input())
print(S.count("g")-(len(S)//2+len(S) % 2))

Solution (Python):
import sys
input = sys.stdin.readline

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

if __name__ == "__main__":
    main()

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

Solution (Python):
S = input()

ans = 0
save = 0

for i in range(len(S)):
    if S[i] == 'g':  
        if save > 0:  
            save -= 1
            ans += 1
        else:  
            save += 1
    elif S[i] == 'p':  
        if save > 0:  
            save -= 1
        else:  
            save += 1
            ans -= 1

print(ans)

Solution (Python):
S = input()
p_count = 0
g_count = 0
win, lose = 0, 0
for s in S:
    if s == "g":
        if p_count < g_count:
            p_count += 1
            win += 1
        else:
            g_count += 1
    else:
        if p_count < g_count:
            p_count += 1
        else:
            g_count += 1
            lose += 1
print(win - lose)

Solution (Python):
from math import ceil

s = sorted(input())
l = ceil(len(s)/2)

hands = (['g'] * l) + (['p'] * l)

c = 0

for x, y in zip(s, hands):
    if x != y:
        c += 1

print(c)

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

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

Solution (Python):
s=input()
g=s.count("g")
p=s.count("p")
length=len(s)
if g-p<2:
    print(0)
else:
    print(abs(p - length//2 ))

Solution (Python):
s = input()

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

Solution (Python):
s = str(input())
N = len(s)

max_won = N // 2
Top_won = 0
for i in range(N):
  if s[i] == "p":
    Top_won += 1
    
print(max_won - Top_won)

Solution (Python):
import collections
s = list(input())
c = collections.Counter(s)
Ng = c["g"]
Np = c["p"]
n = Ng-Np
print(n//2)

Solution (Python):
s = input()
cnt = 0
for i, c in enumerate(s):
    if i % 2 == 0:
        if c == 'p':
            cnt -= 1
    else:
        if c == 'g':
            cnt += 1
print(cnt)

Solution (Python):
s=input()

N=len(s)
g=0
p=0
w=0
l=0

for i in range(N):
    if g==p:
        g+=1
        if s[i]=="p":
            l+=1
    else:
        p+=1
        if s[i]=="g":
            w+=1
print(w-l)

Solution (Python):
s = input()

d = 0
ans = 0

for m in s:
  if m == "g":
    if d == 0:
      d += 1
    elif d != 0:
      ans += 1
      d -= 1

  elif m == "p":
    if d == 0:
      ans -= 1
      d += 1
    elif d != 0:
      d -= 1

print(ans)

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

Solution (Python):
c=w=0
for i in input():
	if i=="g":
		if c:
			w+=1
			c-=1
		else:
			c+=1
	else:
		if c:
			c-=1
		else:
			c+=1
			w-=1
print(w)

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

Solution (Python):





from sys import stdin,setrecursionlimit


setrecursionlimit(10**6)
input=stdin.readline

s=input().rstrip()
gu,pa=0,0
win,lose=0,0
for i in s:
    if i=="g":
        if pa+1<=gu:
            pa+=1
            win+=1
        else:
            gu+=1
    else:
        if pa+1<=gu:
            pa+=1
        else:
            gu+=1
            lose+=1
print(win-lose)

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

Solution (Python):
s = input().rstrip()

gc = 0
pc = 0
ts = 0
ds = 0
for si in s:
    if si == 'g':
        if pc < gc:
            ds += 1
            pc += 1
        else:
            gc += 1
    else:
        if pc < gc:
            pc += 1
        else:
            gc += 1
            ts += 1

print(ds - ts)

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

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

print(count)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    s = input().rstrip('\n')
    t = len(s)
    mp = t // 2
    mg = t - mp
    import collections
    s = collections.Counter(s)
    print(mp - s["p"])


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

S = list(input().strip())

m = {
    "g": 0,
    "p": 0,
}

for v in S:
    m[v] += 1

ans = -10 ** 18
p = len(S)
for g in range(p + 1):
    if g >= p - g:
        ans = max(ans, m["g"] - g)

print(ans)

Solution (Python):
s = input()
g_cnt, p_cnt = 0, 0
ans = 0
for si in s:
    if si == "g":
        if p_cnt < g_cnt:
            p_cnt += 1
            ans += 1
        else:
            g_cnt += 1
    else:
        if p_cnt < g_cnt:
            p_cnt += 1
        else:
            g_cnt += 1
            ans -= 1
print(ans)

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

Solution (Python):

import sys, math, fractions, itertools, collections, copy, heapq


def solve(s: str):
    G = 0
    P = 0
    res = 0
    for i, ss in enumerate(s):
        if ss == 'p':
            if P < G:
                P += 1
            else:
                res -= 1
                G += 1
        else:
            if P < G:
                res += 1
                P += 1
            else:
                G += 1
    print(res)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  
    solve(s)

if __name__ == '__main__':
    main()

Solution (Python):


s=input()
n=len(s)
p=s.count('p')

print(n//2-p)

Solution (Python):
S=input()
acc,ans=0,0
for c in S:
    if c=='g':
        if acc > 0:
            ans += 1
            acc -=1
        else:
            acc += 1
    else:
        if acc > 0:
            acc -= 1
        else:
            ans -= 1
            acc +=1
print(ans)

Solution (Python):
S = input()

count = 0
for s in S :
    if s == 'p' :
        count += 1

ans = -count + len(S) // 2
print(ans)

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

Solution (Python):
s = input()

ans = 0
gt = 0
pt = 0

for i in s:
    if i == "g" and gt > pt:
        ans += 1
        pt += 1
    elif i == "g":
        gt += 1
    elif i == "p" and gt > pt:
        pt += 1
    else:
        ans -= 1
        gt += 1
print(ans)

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

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

Solution (Python):
S = input()
N = len(S)

cnt = 0
ans = 0
for i in range(N):
    if cnt >= 1:
        if S[i] == 'g':
            ans += 1
        cnt -= 1
    else:
        if S[i] == 'p':
            ans -= 1
        cnt += 1
    
print(ans)

Solution (Python):
S = input()

g = 0
p = 0
w = 0
l = 0
for s in S:
    if g <= p:
        t = "g"
    else:
        t = "p"

    if t == "p" and s == "g":
        w += 1
    elif t == "g" and s == "p":
        l += 1
    if t == "g":
        g += 1
    else:
        p += 1

print(w-l)

Solution (Python):
s = input()
ans = 0
gcount = 0

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

Solution (Python):
a = input()
g = 0
p = 0
s = 0
for i in range(len(a)):
    if a[i] == "g":
        g += 1
    else:
        p += 1
c = abs((g-p)//2)
if g < p:
    g += c
    p -= c
elif g > p:
    p += c
    g -= c
d = "p" * p + "g" * g
for i in range(len(a)):
    if a[i] != d[i]:
        if a[i] == "p" and d[i] == "g":
            s -= 1
        elif a[i] == "g" and d[i] == "p":
            s += 1
print(s)

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())


S = input()

prevg = 0
prevp = 0

ans = 0
for enec in S:
  if prevg > prevp:
    
    if enec=='p':
      prevp += 1
    else:
      prevp += 1
      ans += 1
  else:
    
    prevg += 1
    if enec=='p':
      ans -= 1

print(ans)

Solution (Python):
s = input()
lens = len(s)




numpar = lens // 2
toppar = 0
for i in range(lens):
    if s[i] == "p":
        toppar += 1
print(str(numpar - toppar))

Solution (Python):
s=input()
from collections import Counter
lens=len(s)%2
s=Counter(s)
print(((s["g"]-s["p"])-lens)//2)

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

Solution (Python):
N=input()
X=len(N)
A=[]
for i in range(X):
  A.append(N[i])



rock=0
paper=0
win=0
lose=0
for i in range (X):
  if A[i]=="g":
    if rock>=paper+1:
      win+=1
      paper+=1
    else:
      rock+=1
  else:
    if rock>=paper+1:
      paper+=1
    else:
      rock+=1
      lose+=1


print(win-lose)

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

Solution (Python):

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


if __name__ == "__main__":
    main()

Solution (Python):
S = input()
ans = 0
g_count = 0
for c in S:
    if c == "g":
        if g_count > 0:
            g_count-=1
            ans += 1
        else:
            g_count += 1
    else:
        if g_count > 0:
            g_count-=1

        else:
            g_count += 1
            ans -=1
print(ans)

Solution (Python):







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

print(score)

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

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

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

Solution (Python):
s = input()
N = len(s)
M = s.count("p")

print(N//2-M)

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

Solution (Python):
s = input()
ans = len(s) // 2
for i in s:
  if i == 'p':
    ans -= 1
print(ans)

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

Solution (Python):

"""
D - AtCoDeerくんと変なじゃんけん / AtCoDeer and Rock-Paper
https://atcoder.jp/contests/arc062/tasks/arc062_b

"""
import sys


def solve(s):
    rock, paper = 0, 0
    ans = 0
    for h in s:
        if rock > paper:
            paper += 1
            if h == 'g':
                ans += 1
        else:
            rock += 1
            if h == 'p':
                ans -=1
    return ans


def main(args):
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
a = input()
n = len(a)
r = 0
g ,p =0, 0
for i in a:
    if i =="g":
        if g>p:
            r+=1
            p+=1
        else:
            g+=1
    else:
        if g>p:
            p+=1
        else:
            g+=1
            r-=1
print(r)

Solution (Python):
a = input()
n = len(a)
r = 0
g ,p =0, 0
for i in a:
    if i =="g":
        if g>p:
            r+=1
            p+=1
        else:
            g+=1
    else:
        if g>p:
            p+=1
        else:
            g+=1
            r-=1
print(r)

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

Solution (Python):
s = input()

sg = 0
sp = 0
ans = 0

for i in range(len(s)):
    if sp+1 <= sg and s[i] == 'g':
        sp += 1
        ans += 1
    elif sp+1 > sg and s[i] == 'p':
        sg += 1
        ans -= 1
    elif sp+1 <= sg and s[i] == 'p':
        sp += 1
    else:
        sg += 1
print(ans)

Solution (Python):
s = input()

sg = 0
sp = 0
ans = 0

for i in range(len(s)):
    if sp+1 <= sg and s[i] == 'g':
        sp += 1
        ans += 1
    elif sp+1 > sg and s[i] == 'p':
        sg += 1
        ans -= 1
    elif sp+1 <= sg and s[i] == 'p':
        sp += 1
    else:
        sg += 1
print(ans)

Solution (Python):
s = input()

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

Solution (Python):
s=input()
g,p,ans=0,0,0
for i in range(len(s)):
  if s[i]=="p":
    if g==p:
      g+=1
      ans-=1
    else:
      p+=1
  elif g==p:
    g+=1
  else:
    p+=1
    ans+=1
print(ans)

Solution (Python):
s = input()

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

print(score)

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

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

Solution (Python):


def read_input():
    s = input()
    return s

def submit():
    s = read_input()

    p_card = 0
    hands = []
    for c in s:
        if p_card == 0:
            hands.append('g')
            p_card += 1
            continue

        if c == 'p':
            if p_card > 0:
                hands.append('p')
                p_card -= 1
                continue
            else:
                hands.append('g')
                p_card += 1
                continue
        else:
            if p_card > 0:
                hands.append('p')
                p_card -= 1
                continue
            else:
                hands.append('g')
                p_card += 1
                continue

    win = 0
    loose = 0
    for a,t in zip(hands, s):
        if a == t:
            continue

        if a == 'g':
            loose += 1
        else:
            win += 1

    print(win - loose)



if __name__ == '__main__':
    submit()

Solution (Python):


s = list(input())

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

ans = int((g-p) / 2)

print(ans)

Solution (Python):
s = input()
n = len(s)
go = 0
pa = 0
score = 0
for i in range(n):
    if s[i] == "g":
        go += 1
    else:
        if go > pa:
            pa +=1
        else:
            go += 1
            score -=1
print(score+(go-pa)//2)

Solution (Python):
N = input()
ans = 0
for i in range(len(N)):
    if i%2 == 0:
        if N[i] =="p":
            ans += -1
    else:
        if N[i] =="g":
            ans += 1
print(ans)

Solution (Python):
s = input()

cntg = 0
cntp = 0
score = 0
for c in s:
    if c == 'g' and cntg>cntp:
        cntp += 1
        score += 1
    elif c == 'g' and cntg<=cntp:
        cntg += 1
    elif c == 'p' and cntg>cntp:
        cntp += 1
    elif c == 'p' and cntg<=cntp:
        cntg += 1
        score -= 1
print(score)

Solution (Python):
s=input()

ng = s.count('g')
np = s.count('p')

print((ng+np)//2 - np)

Solution (Python):
s = input()
n = s.count('p')
l = len(s)

ans = l//2 - n
print(ans)

Solution (Python):
S = input()
N = len(S)

P = N // 2

print(P - S.count('p'))

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

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

Solution (Python):
s=input()
a=s[0::2]
b=s[1::2]
print(b.count('g')-a.count('p'))

Solution (Python):
s=input()

gu=0
pa=0
win=0

for t in s:
  if t=='g':
    if gu>pa:
      pa+=1
      win+=1
    else:
      gu+=1
  else:
    if gu>pa:
      pa+=1
    else:
      win-=1
      gu+=1
print(win)

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

Solution (Python):
S = input()
ans = 0
for i in range(len(S)):
  if i%2 == 0 and S[i] == "p":
    ans -= 1
  elif i%2 == 1 and S[i] == "g":
    ans += 1
print(ans)

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

Solution (Python):
s = input()
m = "gp"*(len(s)//2+1)
g = 0
for i in range(len(s)):
  if s[i] == m[i]:
    continue
  elif s[i] == "p":
    g -= 1
  else:
    g += 1
print(g)

Solution (Python):
s = input().strip()

gc, pc = 0, 0
wc, lc = 0, 0
for _s in s:
  if _s == 'g':
    if pc + 1 <= gc:
      pc += 1
      wc += 1
    else:
      gc += 1
  else:
    if pc + 1 <= gc:
      pc += 1
    else:
      gc += 1
      lc += 1
print(wc - lc)

Solution (Python):
s = input()
n = len(s)
a = 0

for t in s:
    if t == 'p':
        a += 1


print(n//2 - a)

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

Solution (Python):
S = input()
g = 0
p = 0
win = 0
lose = 0
for s in S:
  if(s == "g"):
    if(p < g):
      p += 1
      win += 1
    elif(p == g):
      g += 1
  else:
    if(p < g):
      p += 1
    elif(p == g):
      g += 1
      lose += 1
print(win-lose)

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

Solution (Python):
S = input()

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

Solution (Python):
s = [x == "g" for x in input()]

p = 0
g = 0

def is_g(x):
    return x


cnt = 0
for v in s:
    if is_g(v):
        if p < g:
            p += 1
            cnt += 1
        else:
            g += 1
    else:
        if p >= g:
            g += 1
            cnt -= 1
        else:
            p += 1
print(cnt)

Solution (Python):
s = input()
print((len(s) >> 1) - s.count('p'))

Solution (Python):
s = input()

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

print(ans)

Solution (Python):
s = input()

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

print(ans)

Solution (Python):
def inpl():
    return list(map(int, input().split()))


S = input()

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

Solution (Python):

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


S = input()

ans = 0
g = 0
p = 0
for s in S:
    if g == p:
        g += 1
        if s == "g":
            pass
        elif s == "p":
            ans -= 1
    else:
        p += 1
        if s == "g":
            ans += 1
        elif s == "p":
            pass
print(ans)

Solution (Python):


"""
Created on 2019/2/
Solved on 2019/2/
@author: shinjisu
"""



def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def probC():
    S = input()
    dmp(S)
    GU = 'g'
    PA = 'p'
    guCount = 0
    paCount = 0
    point = 0
    allTe = ''
    for i in range(len(S)):
        if paCount < guCount:
            te = PA
            paCount += 1
        else:
            te = GU
            guCount += 1

        if te == GU and S[i] == PA:
            point -= 1
        elif te == PA and S[i] == GU:
            point += 1
        allTe += te
    dmp(allTe,'allTe')
    dmp(point)
    return point


debug = False  
ans = probC()
print(ans)



"""
        if S[i] == GU:
            if paCount < guCount:
                te = PA
                paCount += 1
            else:
                te = GU
                guCount += 1
        else:
            if paCount < guCount:
                te = PA
                paCount += 1
            else:
                te = GU
                guCount += 1
"""

Solution (Python):


"""
Created on 2019/2/
Solved on 2019/2/
@author: shinjisu
"""



def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def probC():
    S = input()
    dmp(S)
    GU = 'g'
    PA = 'p'
    guCount = 0
    paCount = 0
    point = 0
    allTe = ''
    for i in range(len(S)):
        if S[i] == GU:
            if paCount < guCount:
                te = PA
                paCount += 1
            else:
                te = GU
                guCount += 1
        else:
            if paCount < guCount:
                te = PA
                paCount += 1
            else:
                te = GU
                guCount += 1
        if te == GU and S[i]== PA:
            point -= 1
        elif te == PA and S[i]== GU:
            point += 1
        allTe += te
    dmp(allTe,'allTe')
    dmp(point)
    return point


debug = False  
ans = probC()
print(ans)

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

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

Solution (Python):
S = input()

ans = 0
cnt = 0

for topcodeer in S :
    if topcodeer == "g" :
        if cnt > 0 :
            cnt -= 1
            ans += 1
        else :
            cnt += 1
    else :
        if cnt > 0 :
            cnt -= 1
        else :
            cnt += 1
            ans -= 1

print(ans)

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

Solution (Python):
s = input()
print(len(list(filter(lambda x: x == 'g',
                      s[1::2]))) - len(list(filter(lambda x: x == 'p', s[0::2]))))

Solution (Python):
s = input()

l = len(s)

point = 0
for a, b in zip(s[0::2], s[1::2]):
    if a == 'p':
        point -= 1
    if b == 'g':
        point += 1
print(point)

Solution (Python):
s = input()

l = len(s)

point = 0
cnt = 0
for i in s:
    if cnt > 0:
        cnt -= 1
        if i == 'g':
            point += 1
    else:
        cnt += 1
        if i == 'p':
            point -= 1
print(point)

Solution (Python):
S = input()

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

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

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

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

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

Solution (Python):

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


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


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


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

"""

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


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


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)