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:
w=input()
num=len(w)
countp=0
countg=0
for i in range(num):
  if w[i]=="g":
    countg+=1
  else:
    countp+=1
if num%2==0:
  print(num//2-countp)
else:
  print(num//2-countp)

Submission status: Accepted

Solution code:
#D-atcoderくんと変なジャンケン
s=input()+"g"+"p"
import collections
S=dict(collections.Counter(s))
a=S["p"]-1
b=S["g"]-1
x=((a+b)//2)
print(x-a)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

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()
stack = []
for s in S:
    if s == 'p':
        stack.pop(0)
    else:
        stack.append('g')
        
print(len(stack)//2)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
e = n//2
o = n - e
w = 0
l = 0
for i in range(o):
    p = 2*i
    if s[p] == 'p':
        l += 1
for j in range(e):
    q = 2*j + 1
    if s[q] == 'g':
        w += 1
ans = w - l
print(ans)

Submission status: Accepted

Solution code:
s = input()
num_g = s.count("g")
num_p = s.count("p")

print((num_g - num_p) // 2)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
S = input().rstrip()

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:
def examD():
    St = S()
    cur = St.count("g")
    ans = cur - (len(St)+1)//2
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Submission status: Accepted

Solution code:
def solve():
    S = input()
    N = len(S)
    # print(S, N)

    # 最大回数のパーを数える
    n = (N - 1)
    p = (n + 2 - 1) // 2

    return p - S.count("p")


if __name__ == '__main__':
    res = solve()
    print(res)

Submission status: Accepted

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

ans = 0
dif = 0

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

Submission status: Accepted

Solution code:
s = input().strip()
cnt = 0
for i in range(len(s)):
    a = s[i]
    if i%2==0:
        if a=="g":
            pass
        else:
            cnt -= 1
    else:
        if a=="g":
            cnt += 1
        else:
            pass
print(cnt)

Submission status: Accepted

Solution code:
s = input()
print(s[(len(s)+1)//2:].count('g') - s[:(len(s)+1)//2].count('p'))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(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() 
#maximize ans.count(p)-ans.count(g)
#at each point g>=p   
g=0 
p=0 
ans=''
for i in s: 
    if i=='g':
        if g==p: 
            ans+='g'
            g+=1 
        else: 
            ans+='p'
            p+=1  
    if i=='p':
        if g==p: 
            ans+='g'
            g+=1 
        else: 
            ans+='p'
            p+=1 
cnt=0 
#print(ans)
for i in range(len(s)):
    if s[i]=='g' and ans[i]=='p':
        cnt+=1 
    if s[i]=='p' and ans[i]=='g': 
        cnt-=1  
print(cnt)

Submission status: Accepted

Solution code:
s=str(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()
n = s.count('p')
l = len(s)

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

Submission status: Accepted

Solution code:
#gpgpgpで出し続ける。

s = str(input())
s_cnt = s.count("p")
ans = 0
#偶数
if len(s)%2 == 0:
    ans = len(s)//2 - s_cnt
#奇数
else:
    ans = len(s)//2 - s_cnt
    if ans < 0:
        ans = 0
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(n//2 -p)

Submission status: Accepted

Solution code:
s=input()
gu_time=0
pa_time=0
n=len(s)
score=0
for i in range(n):
    if pa_time==gu_time:
        gu_time+=1
        if s[i]=="p":
            score-=1
    elif pa_time<gu_time:
        pa_time+=1
        if s[i]=="g":
            score+=1
print(score)

Submission status: Accepted

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


def solve(s: str):
    print(max(0, (len(s)-2*s.count('p'))//2))
    return


# Generated by 1.1.6 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:
s = input()

count_p = len([_ for _ in s if _ == 'p'])
count_g = len(s) - count_p

if count_g - count_p <= 1:
    print(0)
elif len(s) % 2 == 0:
    print(count_g - len(s)//2)
else:
    print(len(s) // 2 - count_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

    else:

        if p < g:
            p += 1

        else:
            g += 1
            ans -= 1

print (ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    S = str(input())
    num = S.count("g")-S.count("p")

    print(num//2)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
point = 0
count_g = 0
count_p = 0
for enemy_move in s:
  if enemy_move == "g":
    if count_g > count_p:
      point += 1
      count_p += 1
    else:
      count_g += 1
  else:
    if count_g > count_p:
      count_p += 1
    else:
      count_g += 1
      point -= 1
print(point)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
cnt = 0
g_cnt = 0
p_cnt = 0
for i in range(n):
    if g_cnt > p_cnt:
        if s[i] == 'g':
            cnt += 1
            p_cnt += 1
        else:
            p_cnt += 1
    else:
        if s[i] == 'g':
            g_cnt += 1
        else:
            cnt -= 1
            g_cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
s = list(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:
    if S[i] == 'p':
      ans -= 1
  else:
    if S[i] == 'g':
      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:
        t = "g"
        if s[i] == "p":
            ans -= 1
    else:
        t = "p"
        if s[i] == "g":
            ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter
S = input()
N = len(S)
counter = Counter(S)

p_len = N // 2

print(p_len - counter['p'])

Submission status: Accepted

Solution code:
S = input()

res = 0
for i in range(len(S)):
    h = 'gp'[i % 2]
    if S[i] == 'g' and h == 'p':
        res += 1
    elif S[i] == 'p' and h == 'g':
        res -= 1
    else:
        pass

print(res)

Submission status: Accepted

Solution code:
s = input()

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

ans = len(s) // 2 - np
print(ans)

Submission status: Accepted

Solution code:
s = input()

x = 0
np = []
for i in reversed(range(len(s))):
    if s[i] == 'p':
        x += 1
    np.append(x)
np = list(reversed(np))

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

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(len(S)//2-p)

Submission status: Accepted

Solution code:
S = input().strip()
p, g = "pg"

score = sum(1 if c==g else 0 for c in S)
G, P = 0, 0

hands = []
lastp = None
for c in S:
    if P == G:
        if c == g:
            hand = g
            score -= 1
        else:
            hand = p
            hands[lastp] = g
            # c == p
            # 過去のP vs G を G vs G : +1 -> 0 = -1
            # 過去のP vs P を G vs P :  0 -> -1 = -1
            score -= 1
            P-=1
            G+=1
    else:
        hand = p
    if hand == g:
        G += 1
    else:
        P += 1
        lastp = len(hands)
    hands.append(hand)
    #print(score, hand, "vs", c, P, G)
#print(S)
#print("".join(hands))
print(score)

Submission status: Accepted

Solution code:
S = input()
v = ['g', 'p']
ans = 0
for i, s in enumerate(S):
    if s != v[i % 2]:
        if s == 'g':
            ans += 1
        else:
            ans -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())

a = 0
for i, s in enumerate(S):
    if i%2==0:
        if s == "p":
            a -= 1
    if i%2==1:
        if s == "g":
            a += 1
print(a)

Submission status: Accepted

Solution code:
S = list(input())

count_P = S.count('p')

#print(count_P)
print(len(S) // 2 - count_P)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():

    s = input()
    ng, np = 0, 0
    count = 0
    for c in s:
        if c == "g":
            if np + 1 <= ng:
                 count += 1
                 np += 1
            else:
                ng += 1
        else:
            if np + 1 <= ng:
                np += 1
            else:
                ng += 1
                count -= 1
    return count

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
#グー、パーを出した回数
count_g, count_p = 0, 0

#勝った回数
vict = 0

for i in range(len(s)):
  if s[i] == "g" and count_p >= count_g:
    #グーを出してあいこ
    count_g += 1
  elif s[i] == "g" and count_p < count_g:
    #パーを出して勝つ
    vict += 1
    count_p += 1
    
  elif s[i] == "p" and count_p >= count_g:
    #グーを出して負ける
    vict -= 1
    count_g += 1
  elif s[i] == "p" and count_p < count_g:
    #パーを出してあいこ
    count_p += 1

print(vict)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    ls = list(input())
    cnt = 0
    ans = 0
    for i in range(len(ls)):
        if ls[i]=="g":
            if cnt>=1:
                ans +=1
                cnt -=1
            else:
                cnt +=1
        else:
            if cnt>=1:
                cnt -=1
            else:
                cnt +=1
                ans -=1
    print(ans)
                
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from heapq import heappush, heappop
import math
import bisect
import random

def LI(): return list(map(int, input().split()))
def I(): return int(input())
def LIM(): return list(map(lambda x:int(x) - 1, input().split()))
def LS(): return input().split()
def S(): return input()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007



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



print(main())

Submission status: Accepted

Solution code:
s=input()

pn=s.count('p')

print(int(len(s)/2)-pn)

Submission status: Accepted

Solution code:
def main():
    s = input()
    s_list = list(s)
    stock = 0
    point = 0
    for i in s_list:
        if i == "g" and stock == 0:
            stock += 1
        elif i == "g" and stock > 0:
            stock -= 1
            point += 1
        elif i == "p" and stock == 0:
            stock += 1
            point -= 1
        elif i == "p" and stock > 0:
            stock -= 1
    print(point)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
#n = int(input())
#n,t = [int(i) for i in readline().split()]
#a = [int(i) for i in readline().split()]
s = input()

g = p = 0
ans = 0
for i in s:
    if 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 = 0
p = 0
ans = 0
for i in s:
    if i == "g":
        if p < g:
            ans += 1
            p += 1
        else:
            g += 1
    else:
        if p < g:
            p += 1
        else:
            ans -= 1
            g += 1
print(ans)

Submission status: Accepted

Solution code:
s = input()

deposit = 0
score = 0
for i in s:
    if deposit > 0 and i == "g":
        deposit -= 1
        score += 1
    elif deposit == 0 and i == "g":
        deposit += 1
    elif deposit > 0 and i == "p":
        deposit -= 1
    elif deposit == 0 and i == "p":
        deposit += 1
        score -= 1
print(score)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
tcd = input()

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

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

Submission status: Accepted

Solution code:
s = list(input())
lose = 0
win = 0
g = 0
for i in s:
    if g == 0: #pを出せない時
        # print ('A')
        g += 1
        if i == 'g': #あいこ
            pass
        else:
            lose += 1
    elif g > 0: #pを出せる時
        # print ('B')
        g -= 1
        if i == 'g': #勝ち
            win += 1
        else: #pを出してあいこ
            pass

print (win - lose)

Submission status: Accepted

Solution code:

def main():
    data = list(input())
    num_g = data.count('g')
    num_p = data.count('p')
    half = len(data) // 2
    print(half - num_p)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(s: str):
    ret = 0
    for i, c in enumerate(s):
        if i % 2:
            if c == 'g':
                ret += 1
        else:
            if c == 'p':
                ret -= 1
    print(ret)
    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()

ans = 0
cnt = 0  # グーを出した回数-パーを出した回数; cntが負になったらダメ

for i in range(len(s)):
    if cnt == 0:
        AtCoDeer = 'g'
        cnt += 1
    else:
        AtCoDeer = 'p'
        cnt -= 1

    if AtCoDeer == 'p' and s[i] == 'g':
        ans += 1
    elif AtCoDeer == 'g' and s[i] == 'p':
        ans -= 1

print(ans)

Submission status: Accepted

Solution code:
S = input()
cnt = 0
for i in range(0, len(S)):
	if S[i] == 'g':
		cnt += 1
gandp = [0, 0]
for i in range(0, len(S)):
	if gandp[0] <= gandp[1]:
		gandp[0] += 1
		cnt -= 1
	else:
		gandp[1] += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

s = input()

g_count, p_count = 0, 0
ans = 0
for si in s:
    if si == "g":
        if p_count < g_count:
            p_count += 1
            ans += 1
        else:
            g_count += 1
    elif si == "p":
        if p_count < g_count:
            p_count += 1
        else:
            g_count += 1
            ans -= 1
print(ans)

Submission status: Accepted

Solution code:
import math

s = input()
n = len(s)
p = sum(1 for c in s if c == 'p')
print(math.floor(n / 2) - p)

Submission status: Accepted

Solution code:
s = input()
score = 0
toUse = 0
for it in s:
  if it == 'g' and toUse > 0:
    toUse -= 1
    score += 1
    continue
  if it == 'g':
    toUse += 1
    continue
  if toUse > 0:
    toUse -= 1
  else:
    toUse += 1
    score -=1
    
print(score)

Submission status: Accepted

Solution code:
s = input()

ret = 0
g, p = 0, 0
for s_ in s :
    if s_ == 'g' :
        if p < g :
            p += 1
            ret += 1
        else :
            g += 1
    else :
        if p < g :
            p += 1
        else :
            g += 1
            ret -= 1
            
print(ret)

Submission status: Accepted

Solution code:
# ABC046D - AtCoDeerくんと変なじゃんけん / AtCoDeer and Rock-Paper (ARC062D)
def main():
    s = input()
    G, P, ans = 0, 0, 0
    for i in s:
        if P < G:
            P += 1
            ans += 1 if i == "g" else 0
        else:
            G += 1
            ans += 0 if i == "g" else -1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

S = list(sys.stdin.readline().rstrip())

ans = 0
for i, c in enumerate(S):
    a = i % 2
    b = 'gp'.index(c)
    if a > b:
        ans += 1
    if a < b:
        ans -= 1
print(ans)

Submission status: Accepted

Solution code:
s = input()

g_num = 1
p_num = 0

win = 0
lose = 0

if s[0] == 'p':
    lose += 1


for i in range(1, len(s)):
    if s[i] == 'p':
        if p_num < g_num:
            p_num += 1
        else:
            g_num += 1
            lose += 1
    else:
        if p_num < g_num:
            p_num += 1
            win += 1
        else:
            g_num += 1

print(win - lose)

Submission status: Accepted

Solution code:
s = input()

g_num = 0
p_num = 0

win = 0
lose = 0

for i in range(0, len(s)):
    if i == 0:
        g_num += 1
        if s[0] == 'p':
            lose += 1
    else:
        if s[i] == 'p':
            if p_num < g_num:
                p_num += 1
            else:
                g_num += 1
                lose += 1
        else:
            if p_num < g_num:
                p_num += 1
                win += 1
            else:
                g_num += 1

print(win - lose)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input().rstrip()
x=list(s)
R=0;
P=0;
ans = 0;
for i in range(0,len(x)):
    if i==0:
        R+=1;
        if x[i]=='p':
            ans-=1;
    else:
        if x[i]=='g':
            if (P+1) <= R:
                P+=1;
                ans+=1;
            else:
                R+=1;
        else:
            if (P+1) <= R:
                P+=1;
#                ans+=1;
            else:
                R+=1;
                ans-=1;
print(ans)

Submission status: Accepted

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

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

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

# 方針
# なるべくパーを出した方がいい
# len(s)の半分をパーにすれば条件は満たされる
# あとはポイントを計算する
# （自分のパーの数） - （相手のパーの数）

def main():
  s=S()

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

  myp=len(s)//2
  myg=len(s)-myp

  return myp-p

print(main())

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

s = str(input())
g,p = 0,0
ans = 0
for i in range(len(s)):
    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:
#coding:utf-8
s=raw_input()

win=lose=0
b=0
for c in s:
    t=""
    if b==0:
        t="g"
        b+=1
    else:
        t="p"
        b-=1
    if c=="g" and t=="p":win+=1
    if c=="p" and t=="g":lose+=1
print(win-lose)

Submission status: Accepted

Solution code:
# 解説読んだ
s = input()
p = s.count('p')
print(len(s)//2 - p)

Submission status: Accepted

Solution code:
# 解説読んだ
s = input()
p = 0
for sv in s:
    if sv == "p":
        p += 1
print(len(s)//2 - p)

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

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

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

def main():
  s=S()

  gc=0
  pc=0
  p=0

  for x in s:
    if gc<pc+1:
      gc+=1

      if x=='p':
        p-=1
      
    else:
      pc+=1
      if x=='g':
        p+=1

  return p

print(main())

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    slen = len(s)

    ans = 0
    diff = 1
    for i in s[1:slen]:
        if i == 'p':
            if diff > 0:
                diff -= 1
            else:
                ans -= 1
                diff += 1
        else:
            if diff>0:
                diff -= 1
                ans += 1
            else:
                diff += 1

    
    print(ans)
        



solve()

Submission status: Accepted

Solution code:
s = input()
g = 0
p = 0
ans = 0
for si in s:
    if p + 1 <= g: # パーを出せる
        p += 1
        if si == 'g': # 相手がグーの時は勝ち
            ans += 1
    else: # パーを出せない
        g += 1
        if si == 'p': # 相手がパーの時は負け
            ans -= 1
print(ans)

Submission status: Accepted

Solution code:
S=input()
li =[0]*(len(S))
g = 0
p = 0
for v in S:
  if ( v == "g" ):
    g += 1
  else:
    p += 1
print ( (g-p)//2 )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = list(input())


if len(s) % 2 == 1:
  ans = (s.count("g") - (s.count("p")+1)) // 2
else:
  ans = (s.count("g") - s.count("p")) // 2
print(ans)

Submission status: Accepted

Solution code:
S = input()
N = len(S)
P = S.count('p')

print(N // 2 - P)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
	s = input()
	g = 0
	p = 0
	ans = 0
	for c in s:
		if c == "g":
			g += 1
		else:
			p += 1
	if len(s) % 2 == 0:
		ans = (g-p)//2
	else:
		ans = (g-p-1)//2

	print(ans)


if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = [1 if c == 'p' else 0 for c in input().strip()]
    return len(S)//2 - sum(S)

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