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:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    s = list(input())

    g = 0
    p = 0
    ans = 0

    for i in range(len(s)):
        if p + 1 <= g:
            a = "p"
            p += 1
        else:
            a = "g"
            g += 1

        if a == s[i]:
            continue
        elif a == "p":
            ans += 1
        else:
            ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    s = SS()

    N = len(s)

    # 出す順番関係なし パーを出せるだけ出せば良い
    ans = N // 2 - s.count('p')
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s= input()
g = 'gp'*(len(s)//2)+'g'*(len(s)%2)
cnt = 0
for si,gi in zip(s,g):
    if si == gi:
        continue
    elif si =='g' and gi == 'p':
        cnt += 1
    else:
        cnt -= 1
print(cnt)

Submission status: Accepted

Solution code:
s = input().strip()
N = len(s)
C = {0:0,1:0}
for i in range(N):
    if s[i]=="g":
        C[0] += 1
    else:
        C[1] += 1
n = N//2
print(n-C[1])

Submission status: Accepted

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

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:
import sys
input = sys.stdin.readline

s = input()[:-1]
p, g = 0, 0
ans = 0

for si in s:
    if si=='g':
        if p<g:
            p += 1
            ans += 1
        else:
            g += 1
    else:
        if p<g:
            p += 1
        else:
            g += 1
            ans -= 1

print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

hand = {'g': 0, 'p': 0}
ans = 0
for i in range(N):
    if S[i] == 'g':
        if hand['g'] > hand['p']:
            hand['p'] += 1
            ans += 1
        else:
            hand['g'] += 1
    else:
        if hand['g'] > hand['p']:
            hand['p'] += 1
        else:
            hand['g'] += 1
            ans -= 1

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    ans = (S.count("g") - S.count("p")) // 2

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = list(input())

num_g, num_p = 0, 0
score = 0
for x in s:
    if x == 'g':
        if num_g - num_p > 0:
            score += 1
            num_p += 1
        else:
            score = score
            num_g += 1
    elif x == 'p':
        if num_g - num_p > 0:
            score = score
            num_p += 1
        else:
            score -= 1
            num_g += 1

print(score)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    import numpy as np
    sys.setrecursionlimit(10**6)
    s = input().strip()
    N = len(s)
    p = sum([1 if si == 'p' else 0 for si in s])
    print(N//2-p)

if __name__ == '__main__':
    main()

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

def solve(s: str):
    from collections import Counter
    from math import floor
    N = len(s)
    c = Counter(s)
    return floor(N / 2) - c["p"]

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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
    print(solve(s))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

Solution code:
s=(input())
pap,rk=0,0
sm=0
for el in s:
    if(el=='g'):#rock
        if(pap+1<=rk):
            sm+=1
            pap+=1
        else:
            sm+=0
            rk+=1
    else:
        if(pap+1<=rk):
            sm+=0
            pap+=1
        else:
            sm-=1
            rk+=1
print(sm)

Submission status: Accepted

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


def point(c0, c1):
    if c0 == "p" and c1 == "p":
        return 0
    if c0 == "p" and c1 == "g":
        return 1
    if c0 == "g" and c1 == "p":
        return -1
    if c0 == "g" and c1 == "g":
        return 0


answer = 0
for i in range(n):
    c0 = "g" if i % 2 == 0 else "p"
    answer += point(c0, s[i])

print(answer)

Submission status: Accepted

Solution code:
s = input()
ans = 0
for t, u in zip(s[::2], s[1::2]):
    if t == 'p':
        ans -= 1
    if u == 'g':
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import  sys
s=input()

a=s.count('g')
if len(s)/2==a:
    print('0')
    sys.exit()

if len(s)%2==0:
    p=a-len(s)/2
else:
    p=a-(len(s)+1)/2
print(int(p))

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
ans = 0
count = 0
for c in s:
    if c=="g":
        if count>0:
            ans += 1
            count -= 1
        else:
            count += 1
    else:
        if count>0:
            count -= 1
        else:
            ans -= 1
            count += 1
print(ans)

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

ans = 0
s = sr()
for i,c in enumerate(s):
    if i%2 == 0:
        if c == 'p':
            ans-=1
    else:
        if c == 'g':
            ans+=1
print(ans)

Submission status: Accepted

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

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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

s = input()

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    s = in_s()
    N = len(s)

    cnt_g = 0
    cnt_p = 0
    score = 0

    for i in range(N):

        if s[i] == 'g':
            if cnt_p < cnt_g:
                cnt_p += 1
                score += 1
            else:
                cnt_g += 1
        else:
            if cnt_p < cnt_g:
                cnt_p += 1
            else:
                cnt_g += 1
                score -= 1

    print(score)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate
S = input()
dic =  {"g":0, "p":1}
# 最適なのはgpgpgpgpと出し続ける
# me g-g 0
# me g-p -1
# me p-g 1
# me p-p 0
# 相手がpのとき、pを出すほうが良い、相手がgのとき、pを出すほうが良い
# 従って、pが余っている状態のときは常に出し続けるのが良い
As = [dic[s] for s in S]
cnt = 0
for i,s in enumerate(S):
    a = i % 2
    b = dic[s]
    cnt += (a-b)
print(cnt)

Submission status: Accepted

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

def main():
    S = list(input())
    ret = 0
    for i, a in enumerate(S):
        if i%2==0:
            #jibunnha g
            if a=='p':
                ret -= 1
        else:
            if a=='g':
                ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S=input()
P=0
for i in range(len(S)):
  P+=(i&1)-(S[i]=='p')
print(P)

Submission status: Accepted

Solution code:
S = input()

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

Submission status: Accepted

Solution code:
S = input()

cnt = 0
for s in S:
  if s == 'g':
    cnt += 1

if len(S) % 2 == 1:
  print(cnt-len(S)//2-1)
else:
  print(cnt-len(S)//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


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

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



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n,*ta = map(int, read().split())
s = input()
n = len(s)
t = "gp"*((n+2)//2)

ans = 0
for i,j in zip(s,t):
    if i != j:
        if i=="g": ans += 1
        else: 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
    if i%2 == 1:
        if s[i] == "g":
            ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
from collections import defaultdict
d=defaultdict(int)
t=['g' if i%2==0 else 'p' for i in range(n)]
pnt=0
for i in range(n):
    if s[i]==t[i]:
        continue
    elif s[i]=='g':
        pnt+=1
    else:
        pnt-=1
print(pnt)

Submission status: Accepted

Solution code:
s=input()
n=len(s)
g=0
p=0
ans=0
for i in range(n):
    if s[i]=="g":
        if p+1<=g:
            ans+=1
            p+=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()
gcnt = 0
pcnt = 0
res = 0

for c in s:
    if pcnt<gcnt:
        pcnt += 1
        if c=="g":
            res += 1
    else:
        gcnt += 1
        if c=="p":
            res -= 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
cnt = Counter(s)
n_p = cnt['p']
print(len(s) // 2 - n_p)

Submission status: Accepted

Solution code:
def main():
    S = input()
    gu = 0
    par = 0
    ans = 0
    for s in S:
        if s == 'g':
            if par < gu:
                ans += 1
                par += 1
            else:
                gu += 1
        else:
            if par < gu:
                par += 1
            else:
                ans -= 1
                gu += 1

    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc062/tasks/arc062_b

S = input()
N = len(S)

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

# print(S, num, ans)
print(ans)

Submission status: Accepted

Solution code:
s=input()
ans=0
for index,i in enumerate(s):
  if index%2==0:
    if i=="p":
      ans-=1
  else:
    if i=="g":
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

s = input()
n = len(s)
c = Counter(s)
can_p = n // 2
print(can_p-c['p'])

Submission status: Accepted

Solution code:
from collections import defaultdict
s = input()
n = len(s)

cnt = defaultdict(int)
for x in s:
    cnt[x] += 1

can_p = n//2
print(can_p-cnt['p'])

Submission status: Accepted

Solution code:
s = input()

ans = 0
np = 0
ng = 0

for ss in s:
    if ng > np:
        if ss == 'g':
            ans += 1
        np += 1
    else:
        if ss == 'p':
            ans -= 1
        ng += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
cnt_g = 0
cnt_p = 0
for i in range(n):
    if cnt_p + 1 <= cnt_g:
        cnt_p += 1
        if s[i] == 'g':
            ans += 1
    else:
        cnt_g += 1
        if s[i] == 'p':
            ans -= 1

print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s)
nowp = 0
nowg = 0
ans = 0

for i in range(n):
    if s[i] == "g":
        if nowp < nowg:
            nowp += 1
            ans += 1
        elif nowp == nowg:
            nowg += 1
    elif s[i] == "p":
        if nowp < nowg:
            nowp += 1
        elif nowp == nowg:
            nowg += 1
            ans -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    s = input()
    N = len(s)
    gnum = 0
    pnum = 0
    for i in range(N):
        if s[i] == 'g':
            gnum += 1
        else:
            pnum += 1
    print((gnum-pnum)//2)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    S = SI()
    N = len(S)
    A = "gp" * (N//2 + 1)
    ans = 0
    for i in range(N):
        if S[i] == A[i]:
            continue
        if S[i] == "g":
            ans += 1
            continue
        ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()

res = 0
g_stock = 0
for i in s:
    if i == 'g':
        g_stock += 1
    else:
        if g_stock > 0:
            g_stock -= 1
        else:
            res -= 1
res += g_stock//2
print(res)

Submission status: Accepted

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

S = readline().rstrip()

# パーを出せるときは必ずパーを出すのが最善
# g p g pの順で出せばよい
# 相手の手が、
# i % 2 == 0のとき
# gであれば0、pであれば-1
# i % 2 == 1のとき
# gであれば+1、pであれば0

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

Submission status: Accepted

Solution code:
S = list(input())
N = len(S)
p = sum([1 if s == "p" else 0 for s in S])
print(N//2-p)

Submission status: Accepted

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

print(n // 2 - p)

Submission status: Accepted

Solution code:
s = str(input())
n, g, p = len(s), s.count('g'), s.count('p')

print(n // 2 - p)

Submission status: Accepted

Solution code:
s = str(input())
n, g, p = len(s), s.count('g'), s.count('p')

print(g - (n - n // 2))

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
#from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
s=input()
n=len(s)
count=[0,0]
for i in s:
    if i=="g":
        count[0]+=1
    else:
        count[1]+=1
print((count[0]-count[1])//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = list(input())
    c = Counter(S)
    ans = (c["g"] - c["p"]) // 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
tcd_g = s.count("g")
tcd_p = len(s) - tcd_g

acd_p = len(s)//2
acd_g = len(s) - acd_p

if tcd_g >= acd_p:
    print(acd_p - tcd_p)
else:
    print(tcd_g - acd_g)

Submission status: Accepted

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

print(cnt//2)

Submission status: Accepted

Solution code:
import math
s = input()
li = list(s)
a = li.count('p')
b = li.count('g')
#print(a,b)
#1 2
risou = math.ceil((a+b)/2)
#print(risou) 2
print(((a+b)-risou)-a)

Submission status: Accepted

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

Submission status: Accepted

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

print((g-p)//2)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()

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

Submission status: Accepted

Solution code:
def solve():
    S = input()
    even = S[0::2]
    odd = S[1::2]
    ans = odd.count('g')-even.count('p')
    return ans
print(solve())

Submission status: Accepted

Solution code:
s = input()
ans = 0
for i,t in enumerate(s):
  if i&1 == 0 and t == 'p':
    ans -= 1
  elif i&1 == 1 and t == 'g':
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**5
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    s = sys.stdin.readline().rstrip()
    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:
import sys

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

n = len(s)
p_n = s.count("p")
ans = n // 2 - p_n
print(ans)

Submission status: Accepted

Solution code:
s = input()
N = len(s)
pc = 0
gc = 0
wp = 0
lp = 0
for i in range(N):
  if s[i] == "g":
    if pc+1 <= gc:
      pc += 1
      wp += 1
    else:
      gc += 1  
  if s[i] == "p":  
    if pc+1 <= gc:
      pc += 1
    else:
      gc += 1  
      lp += 1
print(wp-lp)

Submission status: Accepted

Solution code:
s_str = input()
s_list = list(s_str)
g_count = 0
p_count = 0
score = 0
for s in s_list:
  if p_count >= g_count:
    if s == "p":
      score -= 1
    g_count += 1
  else:
    if s == "g":
      score += 1
    p_count += 1
print(score)

Submission status: Accepted

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

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode("utf-8").rstrip()
sp = [int(h == "p") for h in S]


def solve():
    g = p = 0
    score = 0
    for is_p in sp:
        if g == p:
            hand = 0
            g += 1
        else:
            hand = 1
            p += 1
        if hand > is_p:
            score += 1
        elif hand < is_p:
            score -= 1
    return score


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

from collections import Counter
def resolve():
    S=input()
    c=Counter(S)
    #print(c)
    print((c["g"]-c["p"])//2)
#%%submit!
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A= list(input())
p_c = 0
total = 0 
g_c = 0
for i in A:
    if i == "g" and p_c+1 <= g_c:
        total += 1
        p_c += 1
    elif i == "p" and p_c+1 <= g_c:
        p_c += 1
    elif i == "g":
        g_c += 1
    else:
        g_c += 1
        total -= 1
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
g=0
p=0
for i in range(N):
    if s[i]=="p":
        p+=1
        if p>g:
            ans-=1
            p-=1
            g+=1 
    else:
        g+=1
        val=g-p
        if val==2:
            ans+=1
            g-=1
            p+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
cnt = 0
ans = 0
size = len(s)
flag = False
for i in range(size):
    if cnt >= size - i:
        flag = True
    if s[i] == 'p':
        cnt -= 1
    if s[i] == 'g':
        if flag:
            ans += 1
        else:
            cnt += 1
if flag:
    print(ans)
else:
    print(min(cnt, 0))

Submission status: Accepted

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