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.

Solution (Python):
S = list(input())

cnt_g = 0
cnt_p = 0
ans = 0

for s in S:
    if cnt_p < cnt_g:
        if s == "g":
            cnt_p += 1
            ans += 1
        else:
            cnt_p += 1
    else:
        if s == "g":
            cnt_g += 1
        else:
            cnt_g += 1
            ans -= 1

print(ans)

Solution (Python):
s = input()
dic = { 'g' : 0 ,'p' : 0 }
for ch in s:
	if ch == 'g':
		dic['g'] += 1
	else:
		dic['p'] += 1

print((dic['g'] - dic['p']) // 2)

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

Solution (Python):
def d_AtCoDeer_and_RockPaper(S):
    
    n = len(S)  
    p = 0  
    for c in S:
        if c == 'p':
            p += 1
    return n // 2 - p

S = input().strip()
print(d_AtCoDeer_and_RockPaper(S))

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

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

Solution (Python):
n = input()

point = 0
cnt = 0
for h in n:
    if cnt <= 0:
        cnt += 1
        if h == 'p':
            point -= 1
    elif h == 'g':
        cnt -= 1
        point += 1
    else:
        cnt -= 1
print(point)

Solution (Python):
s = input()

P = 0
for c in s:
  if c == 'p':
    P += 1

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

Solution (Python):
from collections import defaultdict


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


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict


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


if __name__ == '__main__':
    main()

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

Solution (Python):
s = raw_input()
N = len(s)

def calc_score(hands):
    score = 0
    for i in range(N):
        if s[i] == 'g' and hands[i] == 'p':
            score += 1
        elif s[i] == 'p' and hands[i] == 'g':
            score -= 1
    return score

hands = 'gp' * (N/2) + 'g' * (N%2)
score = calc_score(hands)
print score

Solution (Python):
s = raw_input()
N = len(s)
ans = 0
T = 0
for i in range(N):
    if s[i] == 'p':
        if T > 0:
            T -= 1
        else:
            T += 1
            ans -= 1
    else: 
        if T > 0:
            T -= 1
            ans += 1
        else:
            T += 1
print ans

Solution (Python):
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    s = [1 if hand == 'p' else 0 for hand in input()]
    n = len(s)
    t = [1 if i % 2 else 0 for i in range(n)]
    ans = 0

    for h1, h2 in zip(s, t):
        if h1 < h2:
            ans += 1
        elif h2 < h1:
            ans -= 1
        else:
            pass

    assert ans >= 0
    
    print(ans)

if __name__ == '__main__':
    solve()

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

gnum = s[1:].count("g")
pnum = n - gnum - 1


print((gnum - pnum + 1) // 2)

Solution (Python):
s = input()
Ng = 0
Np = 0
Nw = 0
Nl = 0
for i in s:
    if Ng > Np:
        if i == 'g':
            Nw += 1
        Np += 1
    else:
        if i == 'p':
            Nl += 1
        Ng += 1

print(Nw - Nl)

Solution (Python):
S = input().strip()
N = len(S)
gn = len([1 for i in range(N) if S[i]=='g'])
gm = int((N+1)/2)
print(gn-gm)

Solution (Python):



import sys

def main():
    s = raw_input()
    num_g = sum(1 for c in s if c == 'g')
    num_p = sum(1 for c in s if c == 'p')
    print (num_g-num_p)/2

if __name__ == '__main__':
    main()

Solution (Python):
s=input()
score=0

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

print(score)

Solution (Python):
S = raw_input()

cnt = 0

for i in S:
	if i == "p":
		cnt += 1

print len(S) // 2 - cnt

Solution (Python):
s = input()

t = int(len(s)/2)
ans_left = 'g' * (len(s)-t)
ans_right = 'p' * t
ans = ans_left + ans_right
ret = 0

for i in range(len(s)-t):
    if(s[i:i+1] == 'p'):
        ret -= 1

for i in range(len(s)-t, len(s)):
    if(s[i:i+1] == 'g'):
        ret += 1

print(ret)

Solution (Python):
import sys
import math

s = sys.stdin.readline()
print int(math.floor((len(s) - 1) / 2.0) - s.count('p'))

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

Solution (Python):
opponent = input()
count_p = 0
count_g = 0
point = 0
for i in range(len(opponent)):
    if opponent[i] == 'g':
        if count_p < count_g:
            count_p += 1
            point += 1
        else:
            count_g += 1
    if opponent[i] == 'p':
        if count_p < count_g:
            count_p += 1
        else:
            count_g += 1
            point -= 1
print(point)

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

Solution (Python):
l = input()
gcnt, pcnt, wcnt, lcnt = 0,0,0,0

for i in range(len(l)):
	if pcnt + 1 <= gcnt: 
		pcnt += 1
		if l[i] == 'g':
			wcnt += 1
	else: 
		gcnt += 1
		if l[i] == 'p':
			lcnt += 1

print(wcnt - lcnt)

Solution (Python):
def count(a, t):
    ans = 0
    for i in range(len(t)):
        if a[i] == t[i]:
            ans += 0
        elif a[i] == "g" and t[i] == "p":
            ans -= 1
        elif a[i] == "p" and t[i] == "g":
            ans += 1
    return ans


def main():
    s = input()
    a = "gp" * (len(s) // 2 + 1)
    print(count(a, s))

if __name__ == '__main__':
    main()

Solution (Python):


s=raw_input()

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

res=(gu-pa)/2
print res

Solution (Python):


s = str(input())
n = len(s)

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

ans = (G - P) // 2

print(ans)

Solution (Python):
s=raw_input()

p=0

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

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

Solution (Python):
from collections import Counter
s =Counter(input())
print((s['g']-s['p'])//2)

Solution (Python):
s=raw_input()

g=0
p=0

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

sum=g+p
print sum/2-p

Solution (Python):
s = str(input())
gn = int(s.count("g"))
pn = int(s.count("p"))
print((gn-pn)//2)

Solution (Python):
T = input()
count = 0
point = 0
for t in T:
    if count % 2 == 0:
        a = 'g'
    else:
        a = 'p'
    if a=='p' and t=='g':
        point += 1
    elif a=='g' and t=='p':
        point -= 1
    else:
        point += 0
    count += 1
print(point)

Solution (Python):
pt = raw_input()
g = p = 0
score = 0
for c in pt:
    t = "g"
    if g > p:
        t = "p"
    if t == "p": p += 1
    if t == "g": g += 1
    if c == "g" and t == "p": score += 1
    if c == "p" and t == "g": score -= 1

print score

Solution (Python):
T = input()
A = ["gp"[i%2] for i in range(len(T))]
A = "".join(A)

point = 0
for t,a in zip(T,A):
    if t == "g" and a == "p":
        point += 1
    elif t == "p" and a == "g":
        point -= 1

print(point)

Solution (Python):

from collections import Counter
s = Counter(input())
print((s['g']-s['p'])//2)

Solution (Python):
try:
    N = raw_input()
    print N.count('g') + (-len(N)/2)

except EOFError:
    pass

Solution (Python):
import sys

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

r = 0
for i, v in enumerate(s):
    vv = 'p' if (i & 1) else 'g'
    if vv != v:
        if vv == 'p':
            r += 1
        else:
            r -= 1
print r

Solution (Python):
def read_input():
    return list(input())


def maximize_point(against):
    """Calc max point.

    >>> maximize_point(list("gpg"))
    0
    >>> maximize_point(list("ggppgggpgg"))
    2
    """
    cash = 0
    point = 0
    for hand in against:
        if hand == "g":
            if cash > 0:
                point += 1
                cash += -1
                
            else:
                point += 0
                cash += 1
                

        if hand == "p":
            if cash > 0:
                point += 0
                cash += -1
                
            else:
                point += -1
                cash += 1
                

    return point

if __name__ == "__main__":
    

    

    print(maximize_point(read_input()))

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

Solution (Python):

s = raw_input()

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

Solution (Python):
s = raw_input()
N = len(s)
print N / 2 - s.count('p')

Solution (Python):
s = input()
c_g = 0
c_p = 0
win = 0
lose = 0
g_ = len(list(filter(lambda x:x=="g",s)))
p_ = len(list(filter(lambda x:x=="p",s)))
print((g_-p_)//2)

Solution (Python):
s = input()

if len(s) % 2 == 0:
    zenhan = s[:len(s)//2]
    kohan = s[len(s)//2:]
else:
    zenhan = s[:len(s)//2+1]
    kohan = s[len(s)//2+1:]

point = 0
for c in zenhan:
    if c == 'p':
        point -= 1

for c in kohan:
    if c == 'g':
        point += 1

print(point)

Solution (Python):
from sys import stdin
a = stdin.readline().strip()
ans = 0
cur = 0
res = ''
for i in a:
 if i=='p':
  if cur:
   res += "p"
   cur-=1
  else:
   res += "g"
   cur += 1
   ans -=1
 else:
  if cur:
   res += 'p'
   ans += 1
   cur -= 1
  else:
   res += 'g'
   cur += 1

print ans

Solution (Python):
import sys
hands = raw_input().rstrip()

score = 0
for i, hand in enumerate(hands):
    if i % 2 == 0:
        if hand == 'p':
            score -=1
    else:
        if hand == 'g':
            score += 1

print score

Solution (Python):
s = raw_input()
print len(s)/2 - s.count("p")

Solution (Python):


inp = list(input())
count = 0

for i, t  in enumerate(inp):
    if i%2==0:
        if t=='p':
            count -= 1
    else:
        if t=='g':
            count += 1

print(count)

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

Solution (Python):
s = input()
print(len(s) // 2 - len([1 for c in s if c == 'p']))

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

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

Solution (Python):
s=raw_input()
print(len(s)-s.count("p")*2)/2

Solution (Python):
tcd = raw_input()
score = 0
for k, c in enumerate(tcd):
    if k % 2 == 1:
        if c == 'g':
            score += 1
            
    if k % 2 == 0:
        if c == 'p':
            score += -1
            
print(score)

Solution (Python):
s = list(str(input()))
ans = []
score = 0
for i in range(len(s)):
    if i % 2 == 0:
        ans.append('g')
    else:
        ans.append('p')
for i in range(len(s)):
    if s[i] == 'p' and ans[i] == 'g':
        score -= 1
    elif s[i] == 'g' and ans[i] == 'p':
        score +=1
print(score)

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

Solution (Python):
from collections import Counter

gp = Counter(input())
n = sum(gp.values())

print(n // 2 - gp["p"])

Solution (Python):
s = raw_input()
s_length = len(s)

score = 0
for i in range(s_length):
    if s[i]=='g':
        score+=1
score -= s_length/2 if s_length%2==0 else s_length/2+1
print score

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

Solution (Python):

import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

s = raw_input()
N = len(s)
g, p = 0, 0
ans = 0
for si in s:
    if si == "g":
        if g > p:
            ans += 1
            p += 1
        else:
            g += 1
    else:
        if g > p:
            p += 1
        else:
            ans -= 1
            g += 1
print ans

Solution (Python):
gp=raw_input()
gp_list=list(gp)

g=0
p=0
score=0

for i in gp_list:
	if i=="g":
		if p<g:
			p+=1
			score+=1
		else:
			g+=1
	else:
		if p<g:
			p+=1
		else:
			g+=1
			score-=1

print score

Solution (Python):
def judge(my, another):
    if my == another:
        return 0
    elif my == 'g':
        return -1
    else:
        return 1

s = input()

g, p = 0, 0
point = 0
for c in s:
    if p >= g:
        
        point += judge('g', c)
        g += 1
    else:
        
        if c == 'g':
            point += 1
            p += 1
        else:
            p += 1

        
print(point)

Solution (Python):



S=input()
offsets=0
for moji in S:
    if moji=='p':
        offsets=offsets+1

nagasa=len(S)

ans=nagasa//2 - offsets
print(ans)

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

Solution (Python):
S = list(raw_input())
t = 0
score = 0

for s in S:
    if s == 'g':
        if t > 0:
            t-=1
            score+=1
        else:
            t+=1
    else:
        if t > 0:
            t-=1
        else:
            t+=1
            score-=1
print score

Solution (Python):
hand = raw_input()
hands = [_ for _ in hand]
g = 0
p = 0
point = 0
for _ in range(len(hand)):
	if _%2 == 0:
		if hands[_] == 'p':
			point -= 1
	else:
		if hands[_] == 'g':
			point += 1

print point

Solution (Python):
s = input()
n = len(s)
gamedict = dict()
gamedict['p'] = 1
gamedict['g'] = 0
score = 0
for i in range(n):
    if i%2 == 0:
        mymove = 0
    else:
        mymove = 1
    score = score + (mymove - gamedict[s[i]])
print(score)

Solution (Python):
s = raw_input()

p  = s.count("p")
g = s.count("g")
if p < g:
    ans = (p + g) // 2 - p
elif p == g:
    ans = 0
else:
    ans =  - (p + g) // 2 + g
print ans,

Solution (Python):
st = input()
N = len(st)
gc = 0
ret = 0
for s in st:
    if s == 'g':
        gc += 1
    else:
        gc -= 1
for s in reversed(st):
    if s == 'g':
        gc -= 1
        if gc > 0:
            gc -= 1
            ret += 1
                        
print(ret)

Solution (Python):
s = raw_input()
s = [i for i in s]

over_g = 0

score = 0



for c in s:
    if(over_g == 0):
        if(c == 'p'):
            score -= 1
        over_g += 1

    else:
        if(c == 'g'):
            score += 1
        over_g -= 1


print score

Solution (Python):
s = raw_input().strip()
score = 0
for i, si in enumerate(s):
  if i%2 == 1:
    if si == 'g':
      score += 1
  else:
    if si == 'p':
      score -= 1
print score

Solution (Python):
s = raw_input()
N = len(s)
p = 0

for char in range(N):
    if s[char] == "p":
        p += 1

answer = (N // 2) - p
if answer < 0:
    print 0
else:
    print answer

Solution (Python):
l = input()
g = list(filter(lambda s: s == "g", l))
p = list(filter(lambda s: s == "p", l))

print(int((len(g) - len(p)) / 2))

Solution (Python):
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')


def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())


def join(s):
    return ''.join(s)


def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)


def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m


def index(a, x):
    
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1


def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])



s=slist()
g=s.count('g')
p=s.count('p')
print (g-p)/2

Solution (Python):
moveList = raw_input()

rockCounter = 0
score = 0

print (len([x for x in moveList if x == 'g']) 
       - len([x for x in moveList if x == 'p']))/2

Solution (Python):
moveList = raw_input()
print (len([x for x in moveList if x == 'g']) 
       - len([x for x in moveList if x == 'p']))/2

Solution (Python):
from sys import stdin

s = stdin.readline().strip()

points = 0

rocks, papers = 0, 0

for move in s:
    if move == 'g':
        if papers < rocks:
            points += 1
            papers += 1
        else:
            rocks += 1
    else:
        if papers < rocks:
            papers += 1
        else:
            rocks += 1
            points -= 1

print(points)

Solution (Python):
from random import random
import math
import re
import fractions

score = 0
count = 0
S = raw_input()
l = len(S)/2
cp = S.count("p")
print l - cp

Solution (Python):
moveList = raw_input()

rockCounter = 0
score = 0

for i in moveList:
    if i == 'g' and rockCounter > 0:
        score += 1
        rockCounter -= 1
    elif i == 'g':
        rockCounter += 1
    elif i == 'p' and rockCounter > 0:
        rockCounter -= 1
    else:
        rockCounter += 1
        score -= 1
        
print(score)

Solution (Python):
s = raw_input()
t = "g"*((len(s)+1)/2)+"p"*(len(s)/2)
ans = 0
for i in range(len(s)):
    if s[i]=="g" and t[i]=="p":
        ans += 1
    if s[i]=="p" and t[i]=="g":
        ans -= 1
print ans

Solution (Python):
s=raw_input()
g=p=0


ans=chk=0
for i in s:
    if i=='g' and g>p:
        ans+=1
        p+=1
    elif i=='g':
        g+=1
    if i=='p' and g>p:
        p+=1
    elif i=='p':
        g+=1
        ans-=1
print ans