Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import defaultdict

S = input()
X, Y = map(int, input().split())

N = len(S)

d = [len(i) for i in S.split('T')]
d_x = d[0::2]
d_y = d[1::2]

dp_x = defaultdict(lambda: defaultdict(lambda: False))
dp_x[1][d_x[0]] = True
for i in range(1, len(d_x)):
    for x in range(-N, N):
        dp_x[i + 1][x] = dp_x[i][x - d_x[i]] or dp_x[i][x + d_x[i]]

dp_y = defaultdict(lambda: defaultdict(lambda: False))
dp_y[0][0] = True
for i in range(len(d_y)):
    for y in range(-N, N):
        dp_y[i + 1][y] = dp_y[i][y - d_y[i]] or dp_y[i][y + d_y[i]]

if dp_x[len(d_x)][X] and dp_y[len(d_y)][Y]:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

from collections import defaultdict

s = input()
x, y = map(int, input().split())

d = [len(x) for x in s.split('T')]

dx = d[0::2]
n_dx = len(dx)
dp = {0}
for i in range(n_dx):
    tmp = set()
    for j in dp:
        if i == 0:
            tmp.add(j + dx[i])
        else:
            tmp.add(j - dx[i])
            tmp.add(j + dx[i])
    dp = tmp
x_flag = x in dp

dy = d[1::2]
n_dy = len(dy)
dp = {0}
for i in range(n_dy):
    tmp = set()
    for j in dp:
        tmp.add(j - dy[i])
        tmp.add(j + dy[i])
    dp = tmp
y_flag = y in dp

if x_flag and y_flag:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

N = int(input())
yakusuu_list = []
for i in range (1,N+1):
  if N % i == 0:
    yakusuu_list.append([i,N//i])
kyori_list =[]
for a in yakusuu_list:
  [i,j] = a
  kyori_list.append(i+j-2)
print(min(kyori_list))
  


### FIXED CODE ###

N = int(input())
import math 
yakusuu_list = []
for i in range (int(math.sqrt(N)),0,-1):
  if N % i == 0:
    yakusuu = i
    break
print(i+ N//i -2)
### BUGGY CODE ###

import bisect
n,m = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
for i in range(m):
    p = a[n-1]//2
    a.pop()
    a.insert(bisect.bisect_left(a,p),p)

print(sum(a))


### FIXED CODE ###

import heapq

n,m = map(int,input().split())
a = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(a)

for _ in range(m):
    p = heapq.heappop(a)
    heapq.heappush(a,(-1)*(-p//2))

print(-sum(a))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, P: int, S: str):

    if P == 2 or P == 5:
        tot = 0
        for i, c in enumerate(S):
            c = int(c)
            if c % P == 0:
                tot += i+1
        print(tot)
        return

    U = [0]*(N+1)
    a = 0
    for i in range(N-1, -1, -1):
        a += (10**(N-1-i))*int(S[i])
        a %= P
        U[i] = a
    table = [0]*P
    tot = 0
    for i in range(N-1, -1, -1):
        tot += table[U[i]]
        table[U[i]] += 1
    tot += table[0]
    print(tot)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    S = str(next(tokens))  # type: int
    solve(N, P, S)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, P: int, S: str):

    if P == 2 or P == 5:
        tot = 0
        for i, c in enumerate(S):
            c = int(c)
            if c % P == 0:
                tot += i+1
        print(tot)
        return

    U = [0]*(N+1)
    a = 0
    beki = 1
    for i in range(N-1, -1, -1):
        a += beki*int(S[i])
        a %= P
        U[i] = a
        beki = (beki * 10) % P
    table = [0]*P
    tot = 0
    for i in range(N-1, -1, -1):
        tot += table[U[i]]
        table[U[i]] += 1
    tot += table[0]
    print(tot)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    S = str(next(tokens))  # type: int
    solve(N, P, S)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

from itertools import permutations

N, M, R = map(int, input().split())
r = list(map(int, input().split()))

way = [[float("inf") if i != j else 0 for i in range(N + 1)] for j in range(N + 1)]
for m in range(M):
    a, b, c = map(int, input().split())
    way[a][b] = c
    way[b][a] = c

for i in range(N + 1):
    for j in range(N + 1):
        w_ji = way[j][i]
        for k, (w_ik, w_jk) in enumerate(zip(way[i], way[j])):
            if k == 0:
                continue
            tmp = w_ji + w_ik
            if w_jk > tmp:
                way[j][k] = tmp
ans = float("inf")
for path in permutations(r):
    time = 0
    for i in range(len(path) - 1):
        time += way[path[i]][path[i + 1]]
    ans = min(ans, time)
print(ans)


### FIXED CODE ###

from itertools import permutations

def wfa(N):
    for i in range(N + 1):
        for j in range(N + 1):
            w_ji = way[j][i]
            for k, (w_ik, w_jk) in enumerate(zip(way[i], way[j])):
                if k == 0:
                    continue
                tmp = w_ji + w_ik
                if w_jk > tmp:
                    way[j][k] = tmp


N, M, R = map(int, input().split())
r = list(map(int, input().split()))

way = [[float("inf") if i != j else 0 for i in range(N + 1)] for j in range(N + 1)]
for m in range(M):
    a, b, c = map(int, input().split())
    way[a][b] = c
    way[b][a] = c

wfa(N)

ans = float("inf")
for path in permutations(r):
    time = 0
    for i in range(len(path) - 1):
        time += way[path[i]][path[i + 1]]
    ans = min(ans, time)
print(ans)
### BUGGY CODE ###

def main():
    s = input()
    l = [0 for _ in range(len(s))]
    for i in range(1, len(s) + 1):
        x = int(s[-i:])
        l[-i] = x % 2019
    ans = 0
    for i in range(4, len(s) + 1, 1):
        for j in range(0, i - 3, 1):
            if j == 0:
                x = l[-i]
            else:
                x = l[-i] - l[-j]
            if x % 2019 == 0:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from collections import Counter
    s = input()

    n = 2019
    l = [0]
    t = 1
    for i, x in enumerate(s[::-1]):
        t = t * 10 % n
        y = (l[-1] + int(x) * t) % n
        l.append(y)

    c = Counter(l)
    ans = sum([v * (v - 1) // 2 for v in c.values()])
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys

H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_count = {}
w_count = {}
for h,w in hw:
    if h in h_count:
        h_count[h] += 1
    else:
        h_count[h] = 1
    if w in w_count:
        w_count[w] += 1
    else:
        w_count[w] = 1

max_h = max(h_count.values())
max_w = max(w_count.values())
ans = max_h + max_w

max_h_list = [k for k,v in h_count.items() if v == max_h]
max_w_list = [k for k,v in w_count.items() if v == max_w]

num = 0
for h,w in hw:
    if h in max_h_list and w in max_w_list:
        num += 1

if num < len(max_h_list)*len(max_w_list):
    print(ans)
else:
    print(ans-1)

### FIXED CODE ###

H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_count = {}
w_count = {}
for h,w in hw:
    if h in h_count:
        h_count[h] += 1
    else:
        h_count[h] = 1
    if w in w_count:
        w_count[w] += 1
    else:
        w_count[w] = 1

max_h = max(h_count.values())
max_w = max(w_count.values())
ans = max_h + max_w

max_h_list = set([k for k,v in h_count.items() if v == max_h])
max_w_list = set([k for k,v in w_count.items() if v == max_w])

num = 0
for h,w in hw:
    if h in max_h_list and w in max_w_list:
        num += 1

if num < len(max_h_list)*len(max_w_list):
    print(ans)
else:
    print(ans-1)
### BUGGY CODE ###

s = input()
n = len(s)
d = [0]*2019
d[0] = 1
total = 0

for i in range(n):
  buf = s[n-i-1:n]
  l = (int(buf))%2019
  d[l] += 1
  total += d[l] - 1
  
print(total)

### FIXED CODE ###

S = input()[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current % 2019]
    mods[current % 2019] += 1
    x = x * 10 % 2019
print(ans)
### BUGGY CODE ###

def main():
    n, a, b = map(int, input().split())
    mod = 10**9+7

    nn = n
    ans1 = 1
    while a > 0:
        ans1 = (ans1 * n * pow(a, mod-2, mod)) % mod
        n -= 1
        a -= 1

    ans2 = 1
    n = nn
    while b > 0:
        ans2 = (ans2 * n * pow(b, mod-2, mod)) % mod
        n -= 1
        b -= 1

    print((pow(2, nn)-ans1-ans2-1) % mod)


main()


### FIXED CODE ###

def main():
    n, a, b = map(int, input().split())
    mod = 10**9+7

    nn = n
    ans1 = 1
    while a > 0:
        ans1 = (ans1 * n * pow(a, mod-2, mod)) % mod
        n -= 1
        a -= 1

    ans2 = 1
    n = nn
    while b > 0:
        ans2 = (ans2 * n * pow(b, mod-2, mod)) % mod
        n -= 1
        b -= 1

    print((pow(2, nn)-ans1-ans2-1) % mod)


main()
### BUGGY CODE ###


import math
#素数列挙
def get_primes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        A = [i for i in A if i%prime!=0]

    P.extend(A)
          
    return P


def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    sosus = set(get_primes(max(A)+1))
    dvd = set()



    val = A[0]
    for i in A:
        val = math.gcd(i,val)

    if val ==1:
        pass
    else:
        print('not coprime')
        return

    for i in A:
        tmp=[]
        for j in sosus:
            if i % j ==0:
                tmp.append(j)
                while i % j ==0:
                    i //=j
            if i ==1:
                break
        sosus.difference_update(tmp)
        
        if i != 1:
            break
    else:
        print('pairwise coprime')
        return

    print('setwise coprime')

resolve()


### FIXED CODE ###


import math
#素数列挙
def get_primes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        A = [i for i in A if i%prime!=0]

    P.extend(A)
          
    return P


def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    sosus = set(get_primes(max(A)+1))
    dvd = set()



    val = A[0]
    for i in A:
        val = math.gcd(i,val)

    if val ==1:
        pass
    else:
        print('not coprime')
        return

    for i in A:
        tmp=[]
        for j in sosus:
            if j>i:
                break
            if i % j ==0:
                tmp.append(j)
                while i % j ==0:
                    i //=j
            if i ==1:
                break
            if i in sosus:
                
                tmp.append(i)
                i = 1
                break
        sosus.difference_update(tmp)
        
        if i != 1:
            break
    else:
        print('pairwise coprime')
        return

    print('setwise coprime')

resolve()
### BUGGY CODE ###

N = int(input())
PHs = []
for i in range(N):
    H, P = map(int, input().split())
    PHs.append((P, H))

PHs.sort()

memo = {0: 0}
for i, (P, H) in enumerate(PHs):
    for hgt in list(memo.keys()):
        if H >= hgt:
            if hgt + P in memo:
                memo[hgt + P] = max(memo[hgt + P], memo[hgt] + 1)
            else:
                memo[hgt + P] = memo[hgt] + 1

print(max(memo.values()))


### FIXED CODE ###

N = int(input())
HPs = [tuple(map(int, input().split())) for i in range(N)]

HPs.sort(key=lambda x: x[0] + x[1])

INF = float('inf')
dp = [0]
for i, (H, P) in enumerate(HPs, 1):
    if dp[-1] != INF:
        dp += [INF]

    for j in range(1, len(dp))[::-1]:
        hgt = dp[j - 1]
        if hgt <= H:
            dp[j] = min(dp[j], hgt + P)

dp += [INF]
print(dp.index(INF) - 1)
### BUGGY CODE ###

"""
解説をもとに作成
"""


def solve():
    N = int(input())
    uvw = []
    result = [-1] * N
    for i in range(N - 1):
        lst = [int(i) for i in input().split()]
        uvw.append([lst[0],
                    lst[1],
                    lst[2]])
    # 木の頂点を求める
    # -> 任意の場所で良い. 1 とする.
    # 頂点から順に塗っていく
    result[0] = False
    result, uvw = paint(uvw, 1, result)
    for i in result:
        print(int(i))


def paint(uvw, num, result):
    import pprint
    target_uvw = []
    '''num につながる枝のデータを抽出'''
    # print('頂点 {} について探索'.format(num))
    for t in uvw:
        # print(t)
        if t[0] == num or t[1] == num:
            target_uvw.append(t)
    # print('探索対象 {} 件'.format(len(target_uvw)))
    # pprint.pprint(target_uvw)
    '''次につながる頂点をすべて検索して色塗り'''
    next_nums = []
    for t in target_uvw:
        uvw.remove(t)
        target = t[0] if t[0] != num else t[1]
        result[target - 1] = result[num - 1] if t[2] % 2 == 0 else not (
        result[num - 1])
        next_nums.append(target)
    '''次の頂点データについて検索を行う'''
    for nn in next_nums:
        result, uvw = paint(uvw, nn, result)
    return result, uvw


if __name__ == '__main__':
    solve()


### FIXED CODE ###

"""
解説と提出 #5739708をもとに作成
"""

import sys
sys.setrecursionlimit(10 ** 6)


def solve():
    N = int(input())
    result = [-1] * N
    uvw_map = [[] for _ in range(N)]
    '''枝毎の距離相関図を作る'''
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        uvw_map[u].append([v, w])
        uvw_map[v].append([u, w])
    # 木の頂点を求める
    # -> 任意の場所で良い. 1 とする.
    # 頂点から順に塗っていく
    result[0] = False
    result = paint(uvw_map, 0, result)
    for i in result:
        print(int(i))


def paint(uvw_map, num, result):
    # num に紐づくノードの一覧を取得する
    num_map = uvw_map[num]
    # num との距離に応じて色を決定する
    nums = []
    for v, w in num_map:
        if result[v] != -1:
            continue
        result[v] = result[num] if w % 2 == 0 else not(result[num])
        # # 色分けを行ったものについてのみ記録しておく(num')
        nums.append(v)
    # num' すべてに対して同様の操作を行う
    for n in nums:
        result = paint(uvw_map, n, result)
    return result


if __name__ == '__main__':
    solve()
### BUGGY CODE ###

N = int(input())
L = []
for i in range(N) :
    L.append(int(input()))
A = [0]
flag = 0
button = 1
ans = 0
while flag == 0 :
    button = L[button-1]
    ans += 1
    if (button-1) == 1 :
        print(ans)
        flag = 1
    elif (button-1) in A :
        print(-1)
        flag = 1
    else :
        A.append(button-1)


### FIXED CODE ###

N = int(input())
L = [int(input()) for i in range(N)]

flag = 0
now = 0
ans = 0
for i in range(N+1) :
    if now == 1 :
        flag = 1
        break
    else :
        now = L[now]-1
        ans += 1
if flag == 1 :
    print(ans)
else :
    print(-1)
### BUGGY CODE ###

K,S=map(int,input().split())
result = 0
for x in range(K+1):
  Y = min(S - x, K)
  for y in range(Y+1):
    Z = min(S - x - y, K)
    for z in range(Z + 1):
      if x + y + z == S:
        result += 1
print(result)

### FIXED CODE ###

K,S=map(int,input().split())
result = 0
for x in range(K+1):
  Y = min(S - x, K)
  for y in range(Y+1):
    if x + y <= S and S - x - y <= K:
      result += 1
print(result)
### BUGGY CODE ###

k,n = map(int,input().split())
a_ls = list(map(int,input().split()))

next_ls = [0] * n
for i in range(n-1):
    next_ls[i] = a_ls[i+1] - a_ls[i]
next_ls[n-1] = k - a_ls[-1] + a_ls[0]
next_ls = next_ls * 2

dist = float('inf')
for i in range(n):
    costs = next_ls[i:i+n-1]
    sum_ = sum(costs)
    if sum_ < dist:
        dist = sum_

print(dist)

### FIXED CODE ###

import numpy as np

k,n = map(int,input().split())
a_ls = list(map(int,input().split()))

next_ls = [0] * n
for i in range(n-1):
    next_ls[i] = a_ls[i+1] - a_ls[i]
next_ls[n-1] = k - a_ls[-1] + a_ls[0]
argmax = np.argmax(next_ls)
next_ls.pop(argmax)
print(sum(next_ls))
### BUGGY CODE ###

from itertools import permutations

N = int(input())
ans = []

for p in permutations(range(N)):
    D = [-1] * N
    A = []
    for i in range(N):
        for j in range(N):
            if D[j] < p[i]:
                D[j] = p[i]
                A.append(j)
                break
    ans.append(tuple(A))

ans = sorted(set(ans))

for a in ans:
    s = ''.join(map(lambda x:chr(x+97),a))
    print(s)

### FIXED CODE ###

N = int(input())

def f(s):
    if len(s) == N:
        print(s)
        return
    for i in range(97, ord(max(list(s)))+1+1):
        ns = s + chr(i)
        f(ns)

f('a')
### BUGGY CODE ###

def limited_insertion(N: int, B: list)->list:
    # print(N, B)
    if N == 1:
        return [1] if B[0] == 1 else []
    # 後ろからみていって、インデックス(1-indexed)と
    # その位置の配列(B)の値が等しい最初のペアを探す。
    # なければ失敗
    for i in range(N, 0, -1):
        if i == B[i-1]:
            # 見つけたら、それを除いた配列に関して
            # 再帰的に同じことを行う。
            # print('>>>pair', i, B[i-1])
            rec = limited_insertion(N-1, B[:i-1] + B[i:])
            if len(rec) > 0:
                return rec + [i]

    return []


if __name__ == "__main__":
    N = int(input())
    B = [int(s) for s in input().split()]
    A = limited_insertion(N, B)
    if len(A) == 0:
        print(-1)
    else:
        for a in A:
            print(a)


### FIXED CODE ###

def limited_insertion(N: int, B: list)->list:
    # print(N, B)
    if N == 1:
        return [1] if B[0] == 1 else []
    # 後ろからみていって、インデックス(1-indexed)と
    # その位置の配列(B)の値が等しい最初のペアを探す。
    # なければ失敗
    for i in range(N, 0, -1):
        if i == B[i-1]:
            # 見つけたら、それを除いた配列に関して
            # 再帰的に同じことを行う。
            # print('>>>pair', i, B[i-1])
            rec = limited_insertion(N-1, B[:i-1] + B[i:])
            if len(rec) > 0:
                return rec + [i]
            else:
                return []

    return []


if __name__ == "__main__":
    N = int(input())
    B = [int(s) for s in input().split()]
    A = limited_insertion(N, B)
    if len(A) == 0:
        print(-1)
    else:
        for a in A:
            print(a)
### BUGGY CODE ###

import sys

K = int(input())

if K>10**6 or K<1 :
    print(-1)
    sys.exit()

if K%2 == 0 or K%5 ==0:
    print(-1)
    sys.exit()
    
N = 7
count = 0
i = 1

while i:
    
    count += 1
    if N % K == 0:
        print(count)
        sys.exit()
        
    N = N*10 + 7
     

### FIXED CODE ###

K = int(input())

N = 0
count = -1

for i in range(K):
    N = (N*10+7)%K
    if N == 0:
        count = i+1
        break
    
print(count)
### BUGGY CODE ###


import sys
def input():
    return sys.stdin.readline()[:-1]

N, K, Q = map(int, input().split())

points = [K for _ in range(N)]

for q in range(Q):
    A = int(input()) - 1
    points = [p if i == A else p-1 for i, p in enumerate(points)]
for n in range(N):
    if points[n] < 1:
        print('No')
    else:
        print('Yes')


### FIXED CODE ###

import numpy as np
import sys
def input():
    return sys.stdin.readline()[:-1]

N, K, Q = map(int, input().split())

points = np.array([K - Q for _ in range(N)])

for q in range(Q):
    A = int(input()) - 1
    points[A] +=1

for p in points:
    if p < 1:
        print('No')
    else:
        print('Yes')
### BUGGY CODE ###

N = int(input())
S = input()
l = 0
i = 0
while N - i >= 2*(l + 1):
    j = i + l + 1
    while N - j >= l + 1:
        f = False
        if S[i : i + l + 1] == S[j : j + l + 1]:
            f = True
            cnt = 0
            for k in range(l + 1,min(j - i, N - j)):
                if S[i + k] == S[j + k]:
                    cnt += 1
                else:
                    break
            l += cnt + 1
            j = i + l + 1
        else:
            j += 1
    i += 1
print(l)

### FIXED CODE ###

N = int(input())
S = input()
r = 1
ans = 0
for i in range(N):
    while True:
        if S.rfind(S[i : r + 1]) >= r + 1:
            r += 1
            ans = max(ans, r - i)
        else:
            break
print(ans)
### BUGGY CODE ###

n = int(input())
a = [0]*(n+1)
for n in range(1, n+1):
    for i in range(1, 102):
        for j in range(1, 102):
            for k in range(1, 102):
                if n == (i*i + j*j + k*k + i*j + j*k + i*k):
                    a[n]+=1
for x in a[1:]:
    print(x)

### FIXED CODE ###

n = int(input())
a = [0]*(n+1)
for i in range(1, 102):
    for j in range(1, 102):
        for k in range(1, 102):
            if (i*i + j*j + k*k + i*j + j*k + i*k) <= n:
                a[i*i + j*j + k*k + i*j + j*k + i*k] +=1
for x in a[1:]:
    print(x)
### BUGGY CODE ###

N = int(input())
a,b = [],[]
for _ in range(N-1):
	at,bt = map(int,input().split())
	a.append(at)
	b.append(bt)

E = [[] for _ in range(N+1)]

for i in range(N-1):
	E[a[i]].append(b[i])
	E[b[i]].append(a[i])

q = [[1,-1,0]]

ans = [[0 for _ in range(N+1)] for _ in range(N+1)]
cnt = 0
while q:
	cp, root, r_col = q.pop(0)
	
	i = 1
	for np in E[cp]:
		if np == root:
			continue
		if i == r_col:
			i += 1
		q.append([np,cp,i])
		ans[cp][np] = i
		ans[np][cp] = i
		cnt = max(cnt, i)
		i += 1

print(cnt)
for i in range(N-1):
	print(ans[a[i]][b[i]])




### FIXED CODE ###

N = int(input())
E = sorted([list(map(int, input().split())) + [i] for i in range(N-1)], key = lambda x:x[1])
E.sort()
ans = [0 for _ in range(N-1)]
flg = [0 for _ in range(N+1)]

t = 0
cnt = 0
ans_a = 0
for i in range(N-1):
	a,b,ind = E[i]
	if t != a:
		cnt = 1
		t = a
	if flg[a] == cnt:
		cnt += 1
	ans[ind] = cnt
	flg[b] = cnt
	ans_a = max(ans_a, cnt)
	cnt += 1



print(ans_a)
for a in ans:
	print(a)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
import copy
S=list(input())
N=len(S)
point=0
hand=copy.deepcopy(S)
panum=sum([j=="p" for j in hand])
pamax=N//2#ポイントの上限
for i in range(N):
    pa=sum([hand[j]=="p" for j in range(i+1)])#今まで出したパーの数
    if pa<(i+1)//2 and point<pamax-panum:
        hand[i]="p"
        point+=1
print(point)
        

### FIXED CODE ###

# coding: utf-8
# Your code here!
import copy
S=list(input())
N=len(S)
point=0
hand=copy.deepcopy(S)
panum=sum([j=="p" for j in hand])
pamax=N//2#ポイントの上限
pa=0
for i in range(N):
    if S[i]=="g" and pa<(i+1)//2 and point<pamax-panum:
        hand[i]="p"
        point+=1
    if point>=pamax-panum:
        break
    if hand[i]=="p":
        pa+=1
print(point)
### BUGGY CODE ###

import math
def gcd3(a, b, c):
    return math.gcd(math.gcd(a,b), c)

k = int(input())
sum = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            if a == 0 or b == 0 or c == 0:
                sum += 1
            else:
                sum += gcd3(a+1,b+1,c+1)
print(sum)

### FIXED CODE ###

import math
def gcd3(a, b, c):
    return math.gcd(math.gcd(a,b), c)

k = int(input())
sum = 0
for a in range(k):
    if a == 0:
        sum += k * k
        continue
    else:
        for b in range(k):
            if b == 0:
                sum += k
                continue
            else:
                for c in range(k):
                    if c == 0:
                        sum += 1
                    else:
                        sum += gcd3(a+1,b+1,c+1)
print(sum)