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()
n = len(s)
pt = s.count("p")
print(n //2 -pt)

Submission status: Accepted

Solution code:
s = list(input())
N = len(s)

#(方針)パーが使えるようになった瞬間パー使用 → gpgpgpgp...
win = 0
lose = 0
for i in range(N):
  if(i%2 == 0): #奇数回目 g
    my_hand = 'g'
    if(my_hand != s[i]): lose += 1 #負け
  else: #偶数回目 p
    my_hand = 'p'
    if(my_hand != s[i]): win += 1 #負け
  
ans = win-lose
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 2019/08/15

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

print(n//2-p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
#l = s.__len__()
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
###template###
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)
# 4近傍（右, 下, 左, 上）
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())
###template###

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:
    #gを出すしかない
    prevg += 1
    if enec=='p':
      ans -= 1

print(ans)

Submission status: Accepted

Solution code:
s = input()
lens = len(s)
# パーとグーを置換すると、その前後でスコアは変わらない
# ggの時,pgとgpの点数はともに1
# gpの時,pgとgpの点数はともに0 って感じ
#ので、パーをばらけさせても後ろに固めても回数が同じなら結果は同じ -> AtcoDeerくんがパーを出せる回数 - TopcoDeerくんがパーを出した回数が答え
numpar = lens // 2
toppar = 0
for i in range(lens):
    if s[i] == "p":
        toppar += 1
print(str(numpar - toppar))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC046D - AtCoDeerくんと変なじゃんけん / AtCoDeer and Rock-Paper (ARC062D)
def main():
    s = input()
    print(len(s) // 2 - s.count("p"))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

# 全てグーを出すのは明らかに合法手。
# そこから任意の位置をパーに変えると
# 引き分け→勝ち：スコアが1増える。
# 負け→引き分け：スコアが1増える。
# これは位置に依存しない。したがって、パーの回数を最大にするのが最高スコアになる。
# パーの回数を最大にするように適当に決めつけ・決め打ちして答えにする
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)

Submission status: Accepted

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

Submission status: Accepted

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

print(N//2-M)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

P = N // 2

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


print(n//2 - a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = [x == "g" for x in input()]
# p <= g
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


S = input()

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

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/2/
Solved on 2019/2/
@author: shinjisu
"""


# ARC 062 C AtCoDeer and Rock-Paper
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  # True False
ans = probC()
print(ans)
#for row in ans:
#    print(row)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/2/
Solved on 2019/2/
@author: shinjisu
"""


# ARC 062 C AtCoDeer and Rock-Paper
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  # True False
ans = probC()
print(ans)
#for row in ans:
#    print(row)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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