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:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
slist = list(s)

gs = slist.count("g")
ps = slist.count("p")

if len(slist) % 2==0:
    res = (gs-ps)//2
    
else:
    res= (gs-1-ps)//2

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

g = 0
p = 0
cnt = 0
for s in S:
    if s == 'g':
        if g > p:
            p += 1
            cnt += 1
        else:
            g += 1
    else:
        if g > p:
            p += 1
        else:
            g += 1
            cnt -= 1

print(cnt)

Submission status: Accepted

Solution code:
# solution
import io
data=input()
g=data.count('g')
p=data.count('p')
result=(-p+(g+p)//2)
print(result)

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = input()[:-1]

po = 0

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

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

Submission status: Accepted

Solution code:
#coding: utf-8
import math

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())
T_g = s.count("g")
T_p = s.count("p")

if T_g == T_p or T_g == T_p+1:
  result = 0
  print(result)
  exit()
else:
  P = (T_g + T_p) // 2
  result = P - T_p
  print(result)

Submission status: Accepted

Solution code:
s = str(input().rstrip())

def battle(s1, s2):
    l = {'g': {'g': 0, 'p': -1}, 'p': {'g': 1, 'p': 0}}
    return l[s1][s2]

hist = ['g']

g = 1
p = 0
ans = 0
if s[0] == 'p':
    ans = -1
for i in range(1, len(s)):
    cur = 'g'
    if s[i] == 'g':
        if p < g:
            cur = 'p'
    if s[i] == 'p':
        if p < g:
            cur = 'p'

    if cur == 'p':
        p += 1
    else:
        g += 1
    hist.append(cur)
    ans += battle(cur, s[i])

# print(list(s))
# print(hist)
print(ans)

Submission status: Accepted

Solution code:
s=input()

s= list(s)

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
s=input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
r=0
p=0
ans=0
for i in s:
    if i=='g':#rock
        if r>=p+1:
            ans+=1
            p+=1
        else:
            r+=1
    else:
        #paper
        if r>=p+1:
            p+=1
        else:
            r+=1
            ans-=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
cp, cg = 0, 0
ans = 0
for s in S:
    if s == 'g':
        if cp < cg:
            cp += 1
            ans += 1
        else:
            cg += 1
    elif s == 'p':
        if cp < cg:
            cp += 1
        else:
            cg += 1
            ans -= 1
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")

s = stdin.readline().rstrip()

v = [s[i] for i in range(0, len(s))]

g = v.count('g')
p = v.count('p')

print((g-p)//2)

Submission status: Accepted

Solution code:
import collections
s = input()
t = list(s)

ssgn=lambda x:(x*2+1)//2
gg = round(ssgn(len(t)/2))
pp = len(t) - gg

d = collections.Counter(t)
Top_g = d['g']
Top_p = d['p']
print(pp - Top_p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=str(input())
cnt=0
ans=0
for i in range(len(s)):
  if cnt<=((i+1)//2 if i%2==0 else (i+1)//2-1):
    cnt+=1
    if s[i]=='p':
      ans-=1
  else:
    if s[i]=='g':
      if i+1<=len(s)-1 and s[i+1]=='p' and cnt<=((i+2)//2 if (i+1)%2==0 else (i+2)//2-1):
        cnt+=1
      else:
        ans+=1
    else:
      pass
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
INF = 10**10
MOD = 10**9 + 7
sys.setrecursionlimit(100000000)
from functools import lru_cache
from itertools import permutations
from math import factorial


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

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    s=input()
    ng=s.count("g")
    np=len(s)-ng
    print((ng-np)//2)
    

main()

Submission status: Accepted

Solution code:
s = input()

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

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
wc = 0
lc = 0
gc = 0
pc = 0
for i in range(n):
    if s[i] == 'g':
        if pc+1 <= gc:
            wc += 1
            pc += 1
        else:
            gc += 1
    else:
        if pc+1 <= gc:
            pc += 1
        else:
            lc += 1
            gc += 1
print(wc-lc)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc046/tasks/arc062_b
# 300点なのに水色diff
# AtCodeerくんの最善手はgpgpgpと交互に手を出すことである。任意のタイミングでpをgに変更したとき、負けることはあっても勝つことはない.
# (相手が何を出そうともpは負けることはない(悪化しない))

s = input()
ans = 0
for i, ss in enumerate(s):
    if i & 1:
        # Aはpである
        ans += ss == 'g'  # 相手がgだったら得点
    else:
        # Aはgである
        ans -= ss == 'p'  # 相手がpだったら減点
print(ans)

Submission status: Accepted

Solution code:
s = input()

hand = 0
ans = 0
for x in s:
    o = 0
    if x == 'p':
        o = 1
    if hand < o:
        ans -= 1
    if hand > o:
        ans += 1
    hand = 1 - hand
print(ans)

Submission status: Accepted

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

s = readline().rstrip().decode('utf-8')
n = len(s)
g = s.count("g")
p = s.count("p")

if p == n//2:
    print(0)
else:
    print((n//2-p))

Submission status: Accepted

Solution code:
s = list(input())
countg = 0
countp = 0
for i in s:
    if i == 'g':
        countg += 1
    else:
        countp += 1

print(int((countg-countp)/2))

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

s = list(input().rstrip())

G = 0 # グーの回数
P = 0 # パーの回数
ans = 0 # 勝ち-負け

for i in range(len(s)):
    if i == 0:
        if s[i] == "g":
            G += 1
        else:
            ans -= 1
            G += 1
    else:
        if s[i] == "g":
            if G > P:
                ans += 1
                P += 1
            else:
                G += 1
        else:
            if G > P:
                P += 1
            else:
                ans -= 1
                G += 1

print(ans)

Submission status: Accepted

Solution code:
s = input()

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

t = list(s)
for i in range(len(s) -1, -1, -1):
  if t[i] == 'g' and g > p + 1:
    t[i] = 'p'
    g -= 1
    p += 1
t = ''.join(t)

result = 0
for i in range(len(s)):
  if t[i] == 'p' and s[i] == 'g':
    result += 1
  elif t[i] == 'g' and s[i] == 'p':
    result -= 1
print(result)

Submission status: Accepted

Solution code:
#ABC046

s =list(input())
n = len(s)
h = [0,0]#p,g
point = 0#win,lose

for i in range(n):
    if h[0] < h[1]:
        h[0] += 1
        if s[i] == "g":
            point += 1
    
    else:
        h[1] += 1
        if s[i] == "p":
            point -= 1
        
print(point)

Submission status: Accepted

Solution code:
s = input()

l = len(s)

q, r = divmod(l, 2)
hand = "g" * (q + r) + "p" * q

score = 0
for e1, e2 in zip(s, hand):
	if e1 == "g" and e2 == "p":
		score += 1
	elif e1 == "p" and e2 == "g":
		score -= 1

print(score)

Submission status: Accepted

Solution code:
s = input()

g = len(s.replace('p', ''))
p = len(s) - g

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    S = input().strip()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#1, g stock=0. : g       point 0
#2. g stock>0 :  p          +1
#2 p stock=0 : g         -1
#4 p stck>0 : p           0

s = str(input())

point = 0
stock = 0

for i in range(len(s)):
  if s[i] == 'g':
    if stock == 0:
      stock+=1
    elif stock>0:
      stock-=1
      point+=1
  elif s[i] == 'p':
    if stock == 0:
      stock+=1
      point-=1
    elif stock>0:
      stock-=1
print(int(point))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(s: str):
    N = len(s)
    P = s.count("p")
    print(N//2-P)
    return


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:
s=[0 if i=='g' else 1 for i in input()]
print(s[1::2].count(0)-sum(s[0::2]))

Submission status: Accepted

Solution code:
s = input()

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

g_len -= g_num
print(g_len)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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, p = 0, 0
for val in s:
    if val == 'g':
        g += 1
    else:
        p += 1

ans = 0
while g > p + 1:
    g -= 1
    p += 1
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
#時間がなかった
s=input()
n=len(s)
ans=0
for i in range(n):
    if i%2==0:
        if s[i]=="p":
            ans-=1
    else:
        if s[i]=="g":
            ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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


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:
gp = input()
p = gp.count('p')
g = gp.count('g')

print((g-p)//2)

Submission status: Accepted

Solution code:
s = input()

g = 0;p = 0
total = 0

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

print(total)

Submission status: Accepted

Solution code:
import collections
s = list(str(input()))

c = collections.Counter(s)
appear_g = c["g"]
appear_p = c["p"]

if appear_g - appear_p < 2:
	print(0)
else:
	print((appear_g - appear_p) // 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
N = len(S)
W = ['p']*N
g, p = 0, 0
d = 0

last = None
w = 0
for i in range(N):
    p += 1
    if p <= g:
        if S[i] == 'g':
            w+=1
    else:
        W[i] = 'g'
        p -= 1
        g += 1
        if S[i] == 'p':
            w-=1
print(w)

Submission status: Accepted

Solution code:
s = input()

g = 0
score = 0
for c in s:
    if c == 'g':
        if g:
            score += 1
            g -= 1
        else:
            g += 1
    else:
        if g:
            g -= 1
        else:
            g += 1
            score -= 1
print(score)

Submission status: Accepted

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

Answer = counter

print(Answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
a=s.count('p')
b=s.count('g')

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

win = 0
lose = 0
for i in range(len(s)):
    if i%2 == 0:
        if s[i] == "g":
            pass
        else:
            lose += 1
    else:
        if s[i] == "g":
            win += 1
        else:
            pass

print(win - lose)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# dpぽい気がするのでそうする
# なぜかREなる....
# pythonだとrecursion limitがアレなのを忘れていた...
# なぜかTLEなる....

import sys

sys.setrecursionlimit(10 ** 8)


s = input()
dp = {}


def rec(i, cur_g, cur_p, g, p):
    if i in dp:
        return dp[i]
    if i == len(s):
        ret = p - g
        dp[i] = ret
        return ret
    if cur_g > cur_p:
        # パーを出せる（出さなくてもいい）
        if s[i] == "g":
            ret = max(
                rec(i + 1, cur_g, cur_p + 1, g, p + 1),
                rec(i + 1, cur_g + 1, cur_p, g, p),
            )
            dp[i] = ret
            return ret
        elif s[i] == "p":
            ret = max(
                rec(i + 1, cur_g, cur_p + 1, g, p),
                rec(i + 1, cur_g + 1, cur_p, g + 1, p),
            )
            dp[i] = ret
            return ret
    else:
        # 勝てるかどうかにかかわらずグーを出すしか無い
        if s[i] == "g":
            ret = rec(i + 1, cur_g + 1, cur_p, g, p)
            dp[i] = ret
            return ret
        elif s[i] == "p":
            ret = rec(i + 1, cur_g + 1, cur_p, g + 1, p)
            dp[i] = ret
            return ret


print(rec(0, 0, 0, 0, 0))

Submission status: Accepted

Solution code:
s = input()
g, p = 0, 0
ans = 0
for e in s:
    if e == "g":
        if p+1 <= g:
            p += 1
            ans += 1
        else:
            g += 1
    else:
        if p+1 <= g:
            p += 1
        else:
            g += 1
            ans -= 1

print(ans)

Submission status: Accepted

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

win = lose = 0
g = p = 0

for i in range(N):
    if s[i]=="g":
        if p < g:
            p += 1
            win += 1
        else:
            g += 1
    else: # s[i]=="p"
        if p < g:
            p += 1
        else:
            g += 1
            lose += 1
print(win-lose)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s=input().strip()
g=0
p=0
cnt=0
for i in range(len(s)):
    if s[i]=="g":
        if g>p:
            p+=1
            cnt+=1
        else:
            g+=1
    else:
        if g>p:
            p+=1
        else:
            g+=1
            cnt-=1
    #print(cnt)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()

C = Counter(S)
ans = (C['g'] - C['p']) // 2
print(ans)

Submission status: Accepted

Solution code:
s = str(input())

g_count = 0
p_count = 0
point = 0
for i in range(len(s)):
    # 必ずグーを出す状態
    if g_count == p_count:
        g_count += 1
        if s[i] == 'g':
            pass
        else:
            point -= 1
    # パーも出せる状態
    elif s[i] == 'g':
        p_count += 1
        point += 1
    elif s[i] == 'p':
        p_count += 1

ans = point
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=str(input())
point = 0
N=len(S)
if N%2==0:
  A=[0,1]*(N//2)
else:
  A=[0,1]*(N//2)+[0]

T=[]
for i in range(N):
  if S[i]=='g':
    T +=[0]
  else:
    T +=[1]

count=0
for i in range(N):
  count +=A[i]-T[i]
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import numpy as np
# import math
import sys
input = sys.stdin.readline

s = input()

gtime = 0
ptime = 0

N = len(s) - 1
# print(N)

res = 0

for i in range(N):
    temp = s[i]
    if ptime >= gtime:
        gtime += 1
        if temp == 'p':
            res -= 1
    else:
        if temp == 'p':
            ptime += 1
        elif temp == 'g':
            ptime += 1
            res += 1
    # print(i)
    # print(gtime,ptime)

print(res)

Submission status: Accepted

Solution code:
def main():
    S = input()
    ans = 0
    for i, s in enumerate(S):
        if i & 1:
            if s == "g":  # パー
                ans += 1
        else:
            if s == "p":
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = list(input())

g = s.count("g")

if len(s) % 2 == 0:
   print(g - len(s) // 2)
else:
   print(g - len(s) // 2 - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

print((g-p)//2)

Submission status: Accepted

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

Submission status: Accepted

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

S = list(input())

p = 0
g = 0
w = 0
for s in S:
    # 出せるのならpを出す
    t = 'p' if p < g else 'g'
    p += 1 if t == 'p' else 0
    g += 1 if t == 'g' else 0
    # あいこでない
    if s != t:
        # 負け確
        if s == 'p':
            w -= 1
        # 勝ち確
        elif s == 'g':
            w += 1

print(w)

Submission status: Accepted

Solution code:
s = input()

x = len(s) // 2

a = 'g' * (len(s) - x) + 'p' * x
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 sys

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

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

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

Submission status: Accepted

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


def solve(s: str):
    answer = 0
    for i in range(len(s)):
        ss = s[i]
        if i%2 == 0 and ss=='p':
            answer -= 1
        
        if i%2==1 and ss=='g':
            answer +=1
    
    print(answer)

    return


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:
# 相手の手
s = input()

# 組み合わせ
# 相: 自
# p : g = +1
# g : p = -1
# p : p = g : g = 0

# 最大までpを出す。 = len(s)//2
# 相手のパーの数は、期待値-1点なので減点する = s.count("P")

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    ans = 0
    g_st = 0
    for s in S:
        if g_st == 0:
            g_st += 1
            if s == "p":
                ans -= 1
        else:
            g_st -= 1
            if s == "g":
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    g = S.count("g")
    p = S.count("p")
    print(abs((g+p)//2 - p))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
N = len(s)
result = 0
for i in range(N):
    if i % 2 == 0:
        # AtCoDeer: 'g'
        if s[i] == 'p':
            result -= 1
    else:
        # AtCoDeer: 'p'
        if s[i] == 'g':
            result += 1
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
    S=input()
    C=Counter(S)
    g=C['g']; p=C['p']
    n=g+p
    print(g-(n+1)//2)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()

def ranlength(A):
    num = list(A)
    count = 1
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                table.append(count)
                count = 1
        except:
            table.append(count)
    return(table)

rl=ranlength(s)
w=0
for i in range(len(rl)//2):
    w+=(rl[i*2]-rl[i*2+1])/2

if len(rl)%2==1:
    w+=rl[-1]/2

w=int(w)
print(w)

Submission status: Accepted

Solution code:
s = list(input())
n = len(s)
ans = 0
flag = 0
for i in range(n):
  if s[i] == "g" and flag == 0:
    flag+=1
  elif s[i] == "g" and flag != 0:
    flag -= 1
    ans += 1
  elif s[i] == "p" and flag == 0:
    flag += 1
    ans -= 1
  else:
    flag -= 1
print(ans)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = 0
cnt = 0
for s in input():
  if s == 'g':
    if cnt > 0:
      ans += 1
      cnt -=1
    else:
      cnt += 1
  else:
    if cnt > 0:
      cnt -=1
    else:
      ans -= 1
      cnt += 1
print(ans)