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 fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

s = input()
size = len(s)
p_cnt = s.count("p")

max_p = size // 2

print(max_p - p_cnt)

Submission status: Accepted

Solution code:
s = input()

ans = 0
cnt = 0
for i in s:
    if i == "g":
        if cnt >= 1:
            cnt -= 1
            ans += 1
        else:
            cnt += 1
    else:
        if cnt >= 1:
            cnt -= 1
        else:
            cnt += 1
            ans -= 1

print(ans)

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
import time
from bisect import bisect_left, insort_left, bisect_right
import sys

input = sys.stdin.readline
_NUMINT_ALL = list(range(10))


def main():
    ans = solve()

    if ans is True or ans is False:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():
    s = iip()

    cur = -1
    ans = 0
    for i in s:
        if cur > 0:
            ans += 1
        if i == "p":
            ans -= 1
        cur *= -1
    print(ans)

#####################################################ライブラリ集ここから

def kiriage_warizan(a, b):
    return -(-a//b)


def iip(listed=True):  # 数字のinputをlistで受け取る
    d = input().rstrip("\n").split()
    try:
        ret = [int(i) for i in d]
    except:
        ret = [int(i) if i in _NUMINT_ALL else i for i in d]
        if len(ret) == 1:
            return ret[0]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iipt(l, listed=False, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed))
    return ret


def saidai_kouyakusuu(A):  # 最大公約数
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def make_graph_edge_flat(N):  # グラフ作成のための辺をリストで返す
    ret = []
    for i in range(N-1):
        a, b, c = iip()
        a -= 1
        b -= 1
        ret[a].append((b, c))
        ret[b].append((a, c))
    return ret


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


def nibutan_func(func, target, left, right, side="left"): # 関数を二分探索
    l = left
    r = right
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if func(x) == target:
            return x
        elif func(x) > target:
            r = x
        else:
            l = x

    if side == "left" or func(x) == target:
        return l
    else:
        return r


def nibutan_list(list_, target, side="left"):  # リストを二分探索
    if not isinstance(list_, list):
        list_ = list(list_)

    l = 0
    r = len(list_)
    x = (l + r) // 2
    while r-l > 1:
        x = (l+r)//2
        if list_[x] == target:
            return x
        elif list_[x] > target:
            r = x
        else:
            l = x

    if side == "left" or list_[x] == target:
        return l
    else:
        return r


class UfTree():
    def __init__(self, maxnum):
        self.parent = list(range(maxnum))
        self._size = [1] * maxnum
        self.rank = [0] * maxnum

    def size(self, a):
        return self._size[self.root(a)]

    def root(self, a):
        rank = 0
        cur = a
        while True:
            if self.parent[cur] == cur:
                #for i in path: # 経路圧縮
                #    self.parent[i] = cur
                return cur
            else:
                self.parent[cur] = self.parent[self.parent[cur]]
                cur = self.parent[cur]
                rank += 1

    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return self

        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        return self

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
N = len(s)
g = s.count('g')
p = s.count('p')
ans = g-p
if N%2==1:
  ans -= 1
ans //= 2
print(ans)

Submission status: Accepted

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

g = 0
p = 0
score = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    s=str(input())
    val=len(s)
    cntg=0
    cntp=0
    w=0
    l=0
    for i in range(len(s)):
        if cntg-cntp<=0:
            cntg+=1
            if s[i]=='p':
                l+=1
        else:
            if s[i]=='g':
                cntp+=1
                w+=1
            else:
                cntp+=1
    print(w-l)



resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input()
n=len(s)
ans=0
g_cnt=0
p_cnt=0
for i in range(n):
    # 判定
    if g_cnt>p_cnt:
        # パーを出す
        p_cnt+=1
        if s[i]=='g':
            ans+=1
    else:
        g_cnt+=1
        if s[i]=='p':
            ans-=1
print(ans)

Submission status: Accepted

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

    y[i] = cnt

print(y[-1] // 2)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    readline=stdin.readline
    s=readline().strip()

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

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
S = input()

now = 0
ans = 0
for s in S:
    if now == 0:
        now += 1
        if s == 'p':
            ans -= 1
        continue
    if s == 'g':
        ans += 1
    now -= 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

s = list(input())
g = 0
p = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'g' and p + 1 <= g:
        ans += 1
        p += 1
        #print('a')
    elif s[i] == 'g' and p <= g + 1:
        g += 1
        #print('b')
    elif s[i] == 'p' and p + 1 <= g:
        p += 1
        #print('d')
    elif s[i] == 'p' and p <= g + 1:
        ans -= 1
        g += 1
        #print('c')
print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

s = STR()
n = len(s)
pcnt = 0
gcnt = 0
ans = 0
for i in range(n):
    pcnt += 1
    if pcnt <= gcnt and s[i] == 'g':
        ans += 1
    elif pcnt <= gcnt and s[i] == 'p':
        continue
    elif pcnt > gcnt and s[i] == 'p':
        pcnt -= 1
        gcnt += 1
        ans -= 1
    elif pcnt > gcnt and s[i] == 'g':
        pcnt -= 1
        gcnt += 1
print(ans)

Submission status: Accepted

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

plst=[1 if c=='p' else 0 for c in s]
p=sum(plst)

print(n//2-p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

s = input()
N = len(s)
p = 0
g = 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:
            ans -= 1
            g += 1
print(ans)

Submission status: Accepted

Solution code:
s = list(input())

ans = 0

for i in range(len(s)):
    ans += i & 1

for c in s:
    if c == 'p':
        ans -= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys
#input = sys.stdin.readline

import copy
"""
from collections import *
S=input()

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

Submission status: Accepted

Solution code:
s = input()
p, g = 0, 0
ans = 0
for e in s:
    if e == "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:
A=input()
cntg=0
cntp=0
cnt=0
for i in A:
  if i=='g':
    if cntg==cntp:
      cntg+=1
    else:
      cntp+=1
      cnt+=1
  else:
    if cntg==cntp:
      cntg+=1
      cnt-=1
    else:
      cntp+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()

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


print(ans // 2)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

S = str(input())

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

print(ans)

Submission status: Accepted

Solution code:
s = input()
p_cnt=0
for te in s:
    if te=="p":
        p_cnt+=1
best_p=len(s)//2
diff = best_p - p_cnt
print(diff)

Submission status: Accepted

Solution code:
s = input()

g_cnt=0
for te in s:
    if te=="g":
        g_cnt+=1
p_cnt=len(s)-g_cnt
best_p=len(s)//2
diff = best_p - p_cnt
print(diff)

Submission status: Accepted

Solution code:
s = input()

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

print((g-p)//2)

Submission status: Accepted

Solution code:
s = input()
ans = len(s)//2 - sum(c=='p' for c in s)
print(ans)

Submission status: Accepted

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

cnt_g=0
cnt_p=0

for i in range(N):
    if S[i]=="g":
        cnt_g+=1
    else:
        cnt_p+=1

ans=(cnt_g-cnt_p)//2

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7

def main():
    S = cin.string()
    g,p = 0,0
    ans = 0
    for s in S:
        if p + 1 <= g:
            if s == "g":
                ans += 1
            p +=1
        else:
            if s == "p":
                ans -= 1
            g+=1
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

use_clipboard=True
bbn=1000000007
	
#+++++

		
def main():
	s = input()
	n=len(s)
	m=n//2
	ret = s.count('p') - m
	
	print(-ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
class input_clipboard:
	def __init__(self,s):
		self.input_l=s.splitlines()
		self.ii=0
		
	def input(self):
		ret = self.input_l[self.ii]
		self.ii+=1
		return ret

if __name__ == "__main__":
	if sys.platform =='ios':
		if use_clipboard:
			import clipboard
			input_text=clipboard.get()
			ic=input_clipboard(input_text)
			input = lambda : ic.input()
		else:
			sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations
from itertools import accumulate
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

s=input()
# lst=[0,0]
ans=0
for i in range(len(s)):
    if i%2==0:
        if s[i]=="g":
            continue
        else:
            ans-=1
    else:
        if s[i]=="g":
            ans+=1
        else:
            continue
print(ans)

Submission status: Accepted

Solution code:
S = input()
pd = len(S) // 2
pt = S.count("p")

print(pd- pt)

Submission status: Accepted

Solution code:
S = input()
pd = len(S) // 2
gd = len(S) - pd
pt = S.count("p")
gt = len(S) - pt

score = min(pd,gt) - min(pt,gd)
print(score)

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:
s = input().strip()
dp = [[0]]
print(len(s)//2-s.count('p'))

Submission status: Accepted

Solution code:
s=input()

ans=0
g=0
for h in s:
    if g>0:
        #pを出せるなら出す
        g-=1
        if h=='g':
            ans+=1
    else:
        #pが出せないならg
        g+=1
        if h=='p':
            ans-=1

print(ans)

Submission status: Accepted

Solution code:
import sys
#import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = list(rs())
p_cnt = S.count('p')
g_cnt = len(S) - p_cnt
possible = (g_cnt-p_cnt) // 2
print(possible)
# 44

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = list(input())[: -1]
res = 0
g = s.count("g")
p = s.count("p")
print((g + p) // 2 - p)

Submission status: Accepted

Solution code:
S = input()

ans = 0
for i, s in enumerate(S):
    hand = "p" if i & 1 else "g"
    if s == "g" and hand == "p":
        ans += 1
    elif s == "p" and hand == "g":
        ans -= 1
    else:
        continue

print(ans)

Submission status: Accepted

Solution code:
def main():
    S = input()
    m = len(S) // 2
    print(-S[:len(S) - m].count('p') + S[len(S) - m:].count('g'))

main()

Submission status: Accepted

Solution code:
def main():
    s = input()
    g = s.count('g')
    p = s.count('p')
    if (g + p) % 2 == 0:
        return g - (g + p)//2
    else:
        return g - (g + p + 1)//2
print(main())

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=list(input())
ans=0
g_c,p_c=0,0
for i in range(len(s)):
    if i==0:
        g_c+=1
        if s[i]=='p':
            ans-=1
        continue
    if s[i]=='g':
        if p_c<g_c:
            p_c+=1
            ans+=1
        else:
            g_c+=1
    else:
        if p_c<g_c:
            p_c+=1
        else:
            g_c+=1
            ans-=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])

def main():
    s = input()
    NG = 1
    NP = 0
    did = ["g"]
    point = 0
    for i in range(1,len(s)):
        if s[i] == "g":
            if NP + 1 <= NG:
                did.append("p")
                NP += 1
                point += 1
            else:
                did.append("g")
                NG += 1
        else:
            if NP + 1 <= NG:
                did.append("p")
                NP += 1
            else:
                did.append("g")
                NG += 1
                point -= 1
    print(point)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
S=list(input())
_S=collections.Counter(S)
count=(_S["g"]-_S["p"])//2
print(count)

Submission status: Accepted

Solution code:
from collections import Counter
s = list(input())
lens = len(s)
cs = Counter(s)

gp = cs["g"] - cs["p"]

print(gp // 2)

Submission status: Accepted

Solution code:
from sys import stdin
s = (stdin.readline().rstrip())
g = s.count("g")
p = s.count("p")
c = len(s)//2
print(c-p)

Submission status: Accepted

Solution code:
s = input()

s_list = list(s)

from collections import Counter

counter = Counter(s_list)

times = len(s_list)

half = times // 2
print(min(counter["g"] - half, half-counter["p"]))

Submission status: Accepted

Solution code:
S = input()

p_count = 0

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

print(int(len(S)/2) - p_count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    s = input()

    ans = 0
    g_count = 0
    p_count = 0
    for i in range(len(s)):
        if g_count >= p_count + 1 and s[i] is 'g':
            p_count += 1
            ans += 1
        elif s[i] is 'g':
            g_count += 1
        elif g_count >= p_count + 1 and s[i] is 'p':
            p_count += 1
        else:
            g_count += 1
            ans -= 1

    print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#scipy.sparse import csr_matrix
#scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
    s=input().rstrip().decode('utf-8')
    s0=s[::2]
    s1=s[1::2]
    print(s1.count("g")-s0.count("p"))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
len_s = len(s)
cnt = 0
enemy = []
me = []
INF = 1e10
for i, _s in enumerate(s):
    if _s == "p":
        cnt += 1
    enemy.append(cnt)
    me.append((i+1) // 2)
    diff = (i + 1) // 2 - cnt
print(diff)

Submission status: Accepted

Solution code:
import sys


def slove():
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    g = 0
    p = 0
    for i in range(len(s)):
        if s[i] == "g":
            g += 1
        else:
            p += 1
    pp = len(s) // 2
    cnt = 0
    for i in range(len(s)):
        if pp != 0:
            pp -= 1
            if s[i] == "g":
                cnt += 1
        else:
            if s[i] == "p":
                cnt -= 1
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
#D問題
import math
S = list(str(input()))
N = len(S)

count = 0
n = math.ceil(N/2)
for i in range(N):
    if i < n:
        if S[i] == "p":
            count-=1
    else:
        if S[i] == "g":
            count+=1
            
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()

A = 'gp' * (len(S)//2)
if len(S) % 2 == 1:
  A += 'g'
ans = 0
for i in range(len(S)):
  if S[i] == 'p' and A[i] == 'g':
    ans -= 1
  elif S[i] == 'g' and A[i] == 'p':
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
s = input()

g = 0
p = 0

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

print((g-p)//2)

Submission status: Accepted

Solution code:
S = input()
t = 0
p = 0
for s in S:
    if s == "g":
        if t > 0: #パーを出す
            t -= 1
            p += 1
            continue
        else:
            t += 1 #グーを出す
    else:
        if t > 0: #パーを出す
            t -= 1
        else: #グーを出す
            p -= 1
            t += 1
print(p)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    s = input().strip()
    ans = 0
    x = 0 # g を出した数 - p を出した数
    for c in s:
        if x > 0: # p を出せるので出す
            x -= 1
            if c == "g":
                ans += 1
        else: # g を出す
            x += 1
            if c == "p":
                ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)
hand = 0
point = 0
for i in range(n):
    if i==0:
        hand +=1
        continue
    if s[i]=="p" and hand>0:
        hand -=1
    elif s[i]=="p" and hand ==0:
        hand +=1
        point-=1
    elif s[i]=="g" and hand>0:
        hand -=1
        point +=1
    elif s[i]=="g" and hand==0:
        hand +=1
print(point)

Submission status: Accepted

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