Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math as m
from fractions import gcd
D,G = map(int,input().split())
info = [list(map(int,input().split())) for i in range(D)]
a = info[0][0]
L = []
for i in range(1,D):
    b = info[i][0]
    lcm = (a * b) // gcd(a,b)
    a = lcm
for i in range(1,D+1):
    p = info[i-1][0]
    c = info[i-1][1]
    L.append([lcm*100*i + c, i, p, c])
goal = G
count = 0
# 見かけの点数でソート
L.sort()
# 見かけの点数が大きい順から問題を解いていく
# i番目を全問解いた見かけのiscoreについて　
# goal - iscore >= 0 ならば i番目を解くことは確定
for i in range(D-1,-1,-1):
    iscore = 100 * L[i][1] * L[i][2] + L[i][3]
    if goal - iscore >= 0:
        goal -= iscore
        count += L[i][2]
        if goal == 0:
            break
# goal - iscore < 0 ならば　
# i番目をj問解いたscore_jが goal - score_j <= 0 となるような 最小のjをメモ
# まだ解いていない他の問題についても同様にjをメモ(存在しない場合もあり)　これらのうち最小のjを採用する
    elif goal - iscore < 0:
        adopt = 100
        for k in range(i,-1,-1):
            score = 100 * L[k][1] * L[k][2] + L[k][3]
            if goal - score <= 0:
                j = min(m.ceil(goal/(100 * L[k][1])),L[k][2])
                if j < adopt:
                    adopt = j
        count += adopt
        break
print(count)

Fixed submission:
import math as m
D,G = map(int, input().split())
info = [list(map(int, input().split())) for i in range(D)]
def bfs(list_hoge=[[0,[]]],depth=0):
    queue = []
    for e in list_hoge:
        for b in [0,1]:
            if b == 0:
                score = e[0]
                copy = e[1][:]
                queue.append([score,copy])
            elif b == 1:
                score = e[0] + 100*(depth+1)*info[depth][0] + info[depth][1]
                copy = e[1][:]
                copy.append(depth)
                queue.append([score,copy])
    list_hoge = queue[:]
    if depth == len(info)-1:
        return list_hoge
    return bfs(list_hoge,depth+1)
res = bfs()
ans = float("inf")
for e in res:
    solved = 0
    for i in range(len(e[1])):
        solved += info[e[1][i]][0]
    if e[0] >= G:
        if solved < ans:
            ans = solved
        continue
    for i in range(D-1,-1,-1):
        if not i in e[1]:
            nec = G-e[0]
            haiten = 100*(i+1)
            add_solve = m.ceil(nec/haiten)
            total_solved = solved + m.ceil(nec/haiten)
            if add_solve >= info[i][0]:
                break
            if total_solved < ans:
                ans = total_solved
print(ans)
Buggy python submission (verdict: Runtime Error):
def degit_sum(n):
    s = list(str(n))
    s = [int(e) for e in s]
    return sum(s)

N = int(input())
degit = len(str(N))
if N % pow(10,degit-1) == 0:
    degit -= 1
A = pow(10,degit-1)
B = N - A
ans = degit_sum(A) + degit_sum(B)
print(ans)

Fixed submission:
N = int(input())
ans = N
for i in range(1,N):
    A,B = 0,0
    A_str = list(str(i))
    B_str = list(str(N-i))
    for e in A_str:
        A += int(e)
    for e in B_str:
        B += int(e)
    if A + B < ans:
        ans = A + B       
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,len(s)+1):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Fixed submission:
s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,i+6):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) > ord(note):
        continue
    for j in range(i+1,len(s)+1):
        part = s[i:j]
        part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Fixed submission:
s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,i+6):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())
part_list = []
# o(n^2)
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        part = s[i:j]
        part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)

Fixed submission:
s = input()
K = int(input())
dict1 = {}
for i in range(len(s)):
    if s[i] in dict1:
        continue
    else:
        dict1[s[i]] = len(s) - i
dict1 = list(dict1.items())
dict1.sort()
count = 0
for e in dict1:
    count += e[1]
    if count >= K:
        note = e[0]
        break
part_list = []
for i in range(len(s)):
    if ord(s[i]) <= ord(note):
        for j in range(i+1,i+6):
            part = s[i:j]
            part_list.append(part)
part_list = list(set(part_list))
part_list.sort()
ans = part_list[K-1]
print(ans)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
L = []
for i in range(H):
    l = list(input())
    L.append(l)

def judge(list,i,j):
    if i != 0:
        top = list[i-1][j]
    else:
        top = "."
    if j != 0:
        left = list[i][j-1]
    else:
        left = "."
    if i != H-1:
        bottom = list[i+1][j]
    else:
        bottom = "."
    if j != W-1:
        right = list[i][j+1]
    else:
        right = "."
    return top == "#" or left == "#" or bottom == "#" or right == "#"

for i in range(H):
    for j in range(W):
        if L[i][i] == "#" and judge(L,i,j) is False:
            print("No")
            exit()
print("Yes")

Fixed submission:
H,W = map(int,input().split())
L = []
for i in range(H):
    l = list(input())
    L.append(l)

def judge(list,i,j):
    if i != 0:
        top = list[i-1][j]
    else:
        top = "."
    if j != 0:
        left = list[i][j-1]
    else:
        left = "."
    if i != H-1:
        bottom = list[i+1][j]
    else:
        bottom = "."
    if j != W-1:
        right = list[i][j+1]
    else:
        right = "."
    return top == "#" or left == "#" or bottom == "#" or right == "#"

for i in range(H):
    for j in range(W):
        if L[i][j] == "#" and judge(L,i,j) is False:
            print("No")
            exit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
L = []
for i in range(H):
    l = list(input())
    L.append(l)

def judge(list,i,j):
    if i != 0:
        top = list[i-1][j]
    else:
        top = "."
    if j != 0:
        left = list[i][j-1]
    else:
        left = "."
    if i != W-1:
        bottom = list[i+1][j]
    else:
        bottom = "."
    if j != H-1:
        right = list[i][j+1]
    else:
        right = "."
    return top == "#" or left == "#" or bottom == "#" or right == "#"

for i in range(W):
    for j in range(H):
        if L[i][i] == "#" and judge(L,i,j) is False:
            print("No")
            exit()
print("Yes")

Fixed submission:
H,W = map(int,input().split())
L = []
for i in range(H):
    l = list(input())
    L.append(l)

def judge(list,i,j):
    if i != 0:
        top = list[i-1][j]
    else:
        top = "."
    if j != 0:
        left = list[i][j-1]
    else:
        left = "."
    if i != H-1:
        bottom = list[i+1][j]
    else:
        bottom = "."
    if j != W-1:
        right = list[i][j+1]
    else:
        right = "."
    return top == "#" or left == "#" or bottom == "#" or right == "#"

for i in range(H):
    for j in range(W):
        if L[i][j] == "#" and judge(L,i,j) is False:
            print("No")
            exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
L = [0]*N
count = 0
for i in range(N):
    for j in range(i+1):
        L[j] += A[i]
        if L[j] == 0:
            count += 1
print(count)

Fixed submission:
from collections import Counter
import math as m
def combinations(n,r):
    return m.factorial(n) // (m.factorial(n-r) * m.factorial(r))
N = int(input())
A = list(map(int,input().split()))
S = [0]
sum_ = 0
for i in range(N):
    sum_ += A[i]
    S.append(sum_)
c = list(Counter(S).values())
c.sort()
c.reverse()
ans = 0
for e in c:
    if e < 2:
        break
    ans += combinations(e,2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for _ in range(N)]

T = [[""] * N for _ in range(N)]
ans = 0
for A in range(N):
    flag = True
    for i in range(N):
        for j in range(N):
            T[(i+A)%N][j] = S[i][j]
    for i in range(N):
        for j in range(N):
            flag &= T[i][j] == T[j][i]
    if flag:
        ans += N

print(ans)

Fixed submission:
N = int(input())
S = [list(input()) for _ in range(N)]

def generate(A, B):
    T = [[""] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            ni = (i + A) % N
            nj = (j + B) % N
            T[ni][nj] = S[i][j]
    flag = True
    for i in range(N):
        for j in range(N):
            flag &= T[i][j] == T[j][i]
    return flag

ans = 0

for A in range(N):
    ans += N * generate(A, 0)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [list(input()) for _ in range(N)]

def generate(A, B):
    T = [[""] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            ni = (i + A) % N
            nj = (j + B) % N
            T[ni][nj] = S[i][j]
    flag = True
    for i in range(N):
        for j in range(N):
            flag &= T[i][j] == T[j][i]
    return flag

ans = 0

for A in range(N):
    ans += N * generate(A, 0)

print(ans)

Fixed submission:
N = int(input())
S = [list(input()) for _ in range(N)]

def generate(A, B):
    T = [[""] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            ni = (i + A) % N
            nj = (j + B) % N
            T[ni][nj] = S[i][j]
    flag = True
    for i in range(N):
        for j in range(N):
            flag &= T[i][j] == T[j][i]
    return flag

ans = 0

for A in range(N):
    ans += N * generate(A, 0)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int,input().split()))
c = int(N/2) - 1
for i in range(N):
    Y = X[:]
    Y .pop(i)
    Y.sort()
    print(Y[c])

Fixed submission:
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
n = int(N/2) 
for e in X:
    if e <= Y[n-1]:
        print(Y[n])
    elif e >= Y[n]:
        print(Y[n-1])
Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
l = list(range(A,B+1)) 
if B-A+1 <= 2*(K+1):
  for e in l:
    print(e)
elif B-A+1 > 2*(K+1):
  del l[K:-K]
  for e in l:
    print(e)

Fixed submission:
A,B,K = map(int,input().split())
if B - A + 1 <= 2 * K:
    l = list(range(A,B + 1))
else:
    l1 = list(range(A,A + K))
    l2 = list(range(B - K + 1,B + 1))
    l = l1 + l2
for e in l:
    print(e)

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
l = list(range(A,B+1)) 
if B-A+1 <= 2*K:
  for e in l:
    print(e)
elif B-A+1 > 2*K:
  del l[K:-K]
  for e in l:
    print(e)

Fixed submission:
A,B,K = map(int,input().split())
if B - A + 1 <= 2 * K:
    l = list(range(A,B + 1))
else:
    l1 = list(range(A,A + K))
    l2 = list(range(B - K + 1,B + 1))
    l = l1 + l2
for e in l:
    print(e)

Buggy python submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
l = list(range(A,B+1))
del l[K:-K]
for e in l:
  print(e)

Fixed submission:
A,B,K = map(int,input().split())
if B - A + 1 <= 2 * K:
    l = list(range(A,B + 1))
else:
    l1 = list(range(A,A + K))
    l2 = list(range(B - K + 1,B + 1))
    l = l1 + l2
for e in l:
    print(e)

Buggy python submission (verdict: Time Limit Exceeded):
A,B,K = map(int,input().split())
l = []
for i in range(B-A+1):
  l.append(A+i)
del l[K:-K]
for e in l:
  print(e)

Fixed submission:
A,B,K = map(int,input().split())
if B - A + 1 <= 2 * K:
    l = list(range(A,B + 1))
else:
    l1 = list(range(A,A + K))
    l2 = list(range(B - K + 1,B + 1))
    l = l1 + l2
for e in l:
    print(e)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
cost = 0
for i in range(N+1):
    cost += abs(A[i+1]-A[i])
for i in range(1,N+1):
    if A[i-1] <= A[i] <= A[i+1] or A[i+1] <= A[i] <= A[i-1]:
        sub = 0
    elif A[i-1] < A[i+1] < A[i]:
        sub = 2*(A[i]-A[i+1])
    elif A[i] < A[i-1] < A[i+1]:
        sub = 2*(A[i-1]-A[i])
    elif A[i+1] < A[i-1] < A[i]:
        sub = 2*(A[i] -A[i-1])
    elif A[i] < A[i+1]< A[i-1]:
        sub = 2*(A[i+1]-A[i])
    print(cost - sub)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
cost = 0
for i in range(N+1):
    cost += abs(A[i+1]-A[i])
for i in range(1,N+1):
    sub = abs(A[i] - A[i+1]) + abs(A[i] - A[i-1]) - abs(A[i+1] - A[i-1])
    print(cost - sub)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
cost = [abs(A[i+1] - A[i]) for i in range(N+1)]
for i in range(1,N+1):
    if A[i-1] <= A[i] <= A[i+1] or A[i+1] <= A[i] <= A[i-1]:
        sub = 0
    elif A[i-1] < A[i+1] < A[i]:
        sub = 2*(A[i]-A[i+1])
    elif A[i] < A[i-1] < A[i+1]:
        sub = 2*(A[i-1]-A[i])
    elif A[i+1] < A[i-1] < A[i]:
        sub = 2*(A[i] -A[i-1])
    elif A[i] < A[i+1]< A[i-1]:
        sub = 2*(A[i+1]-A[i])
    print(sum(cost) - sub)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
cost = 0
for i in range(N+1):
    cost += abs(A[i+1]-A[i])
for i in range(1,N+1):
    sub = abs(A[i] - A[i+1]) + abs(A[i] - A[i-1]) - abs(A[i+1] - A[i-1])
    print(cost - sub)
Buggy python submission (verdict: Runtime Error):
A,B,C = map(int,input(),split())
if A+2*B>=C:
  print("Yes")
else :
  print("No")

Fixed submission:
A,B,C = map(int,input().split())
if A+B>=C:
  print("Yes")
else :
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
H,W,D = map(int,input().split())
grid = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
info = [list(map(int,input().split())) for i in range(Q)]

note = [0]*(H*W+1)
for i in range(H):
    for j in range(W):
        A = grid[i][j]
        note[A] = (i,j)

def cal(n):
    s = info[n][0]; e = info[n][1]
    cost = 0
    for A in range(s,e-D+1,D):
        i,j = note[A]; ni,nj = note[A+D]
        cost += abs(ni-i) + abs(nj-j)
    return cost

for i in range(Q):
    print(cal(i))

Fixed submission:
H,W,D = map(int,input().split())
grid = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
info = [list(map(int,input().split())) for i in range(Q)]

note = [0]*(H*W+1)
for i in range(H):
    for j in range(W):
        A = grid[i][j]
        note[A] = (i,j)

cost = []
for s in range(D):
    acc = [0]
    tmp = 0
    for A in range(s,H*W+1-D,D):
        if s == 0 and A == 0:
            acc.append(tmp)
            continue
        i,j = note[A]; ni,nj = note[A+D]
        tmp += abs(ni-i) + abs(nj-j)
        acc.append(tmp)
    cost.append(acc)

def cal(n):
    L,R = info[n]
    index = L % D
    L = L // D; R = R // D
    ans = cost[index][R] - cost[index][L]
    return ans

for loop in range(Q):
    print(cal(loop))
Buggy python submission (verdict: Runtime Error):
a,b = map[int,input().split()]
if (a*b)%2 == 0:
  print("Even")
else:
  print("Odd")

Fixed submission:
a,b = map(int,input().split())
if (a*b)%2 == 0:
	print("Even")
elif (a*b)%2 == 1:
	print("Odd")
Buggy python submission (verdict: Runtime Error):
K = int(input())
A = list(map(int,input().split()))[::-1] + [1]

# 切り上げ
def ceil(a, b):
    return -(-a//b)

# [a, b) に含まれるcの倍数のうち最小,最大のものを返す
def query(a, b, c):
    l = c * ceil(a, c)
    r = c * (ceil(b, c) - 1)
    if l <= r:
        return True, l, r
    else:
        return False, -1, -1

cand = [2,2]
for i in range(K):
    s, m = cand
    cand = []
    fs, ls, rs = query(s, s+A[i], A[i+1])
    fm, lm, rm = query(m, m+A[i], A[i+1])
    if fs:
        cand.append(ls)
    if fm:
        cand.append(rm)
    if len(cand) == 0:
        print(-1)
        exit()

s, m = cand
print(s, m)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

K = int(input())
A = list(map(int,input().split()))

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

def floor(a, b):
    return a // b

def L(i):
    if i == K:
        return 2
    return ceil(L(i+1), A[i]) * A[i]

def R(i):
    if i == K:
        return 2
    return floor(R(i+1), A[i]) * A[i] + A[i] - 1

L0 = L(0); R0 = R(0)
if L0 <= R0:
    print(L0, R0)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
K = int(input())
A = list(map(int,input().split()))[::-1] + [1]

# 切り上げ
def ceil(a, b):
    return -(-a//b)

# [a, b) に含まれるcの倍数のうち最小,最大のものを返す
def query(a, b, c):
    l = c * ceil(a, c)
    r = c * (ceil(b, c) - 1)
    if l <= r:
        return True, l, r
    else:
        return False, -1, -1

cand = [2,2]
for i in range(K):
    if len(cand) == 0:
        print(-1)
        exit()
    s, m = cand
    cand = []
    fs, ls, rs = query(s, s+A[i], A[i+1])
    fm, lm, rm = query(m, s+A[i], A[i+1])
    if fs:
        cand.append(ls)
    if fm:
        cand.append(rm)

if len(cand) == 0:
    print(-1)
else:
    print(cand[0], cand[-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

K = int(input())
A = list(map(int,input().split()))

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

def floor(a, b):
    return a // b

def L(i):
    if i == K:
        return 2
    return ceil(L(i+1), A[i]) * A[i]

def R(i):
    if i == K:
        return 2
    return floor(R(i+1), A[i]) * A[i] + A[i] - 1

L0 = L(0); R0 = R(0)
if L0 <= R0:
    print(L0, R0)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
A = list(map(int,input().split()))[::-1]

cand = [2]
for a in A:
    tmp = []
    for c in cand:
        if c % a == 0:
            tmp += list(range(c, c+a))
    cand = tmp[:]

if len(cand) == 0:
    print(-1)
else:
    print(cand[0], cand[-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

K = int(input())
A = list(map(int,input().split()))

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

def floor(a, b):
    return a // b

def L(i):
    if i == K:
        return 2
    return ceil(L(i+1), A[i]) * A[i]

def R(i):
    if i == K:
        return 2
    return floor(R(i+1), A[i]) * A[i] + A[i] - 1

L0 = L(0); R0 = R(0)
if L0 <= R0:
    print(L0, R0)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N,Y = map(int,input().split())
for i in range(N+1):
  for j in range(N-i+1):
    for j in range(N-i-j+1):
      if 10000*i + 5000*j + 1000*(N-i-j) == Y:
        print(i,j,N-i-j)
        exit()
      elif i == N:
        print("-1 -1 -1")

Fixed submission:
N,Y = map(int,input().split())
for i in range(N+1):
  for j in range(N-i+1):
      if 10000*i + 5000*j + 1000*(N-i-j) == Y:
        print(i,j,N-i-j)
        exit()
      elif i == N:
        print("-1 -1 -1")
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
x = (a+b)/2
if (a+b) % 2 = 0:
  print(int(x))
else:
  print(int(x)+1)

Fixed submission:
a,b = map(int,input().split())
x = (a+b)/2
if (a+b)%2 == 0:
  print(int(x))
else:
  print(int(x)+1)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
x = (a+b)/2
if (a+b)%2 = 0:
  print(int(x))
else :
  print(int(x)+1)


Fixed submission:
a,b = map(int,input().split())
x = (a+b)/2
if (a+b)%2 == 0:
  print(int(x))
else:
  print(int(x)+1)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
x = (a+b)/2
if (a+b)%2 = 0:
  print(int(x))
else:
  print(int(x)+1)


Fixed submission:
a,b = map(int,input().split())
x = (a+b)/2
if (a+b)%2 == 0:
  print(int(x))
else:
  print(int(x)+1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
x, y = map(int,input().split())

s = s.split("T")
s = [len(e) for e in s]
a = []
b = []
for i, s in enumerate(s):
    if i % 2 == 0:
        a.append(s)
    else:
        b.append(s)

x -= a.pop(0)
ans = True

dpx = [[False] * (2*abs(x) + 1) for _ in range(len(a) + 1)]
dpx[0][abs(x)] = True

for i in range(1,len(a)+1):
    for j in range(2*abs(x) + 1):
        if j + a[i-1] < 2*abs(x) + 1:
            dpx[i][j] |= dpx[i-1][j+a[i-1]]
        if j - a[i-1] >= 0:
            dpx[i][j] |= dpx[i-1][j-a[i-1]]

ans &= dpx[len(a)][x+abs(x)]

dpy = [[False] * (2*abs(y) + 1) for _ in range(len(b) + 1)]
dpy[0][abs(y)] = True

for i in range(1, len(b) + 1):
    for j in range(2*abs(y) + 1):
        if j + b[i-1] < 2*abs(y) + 1:
            dpy[i][j] |= dpy[i-1][j+b[i-1]]
        if j - b[i-1] >= 0:
            dpy[i][j] |= dpy[i-1][j-b[i-1]]

ans &= dpy[len(b)][y+abs(y)]

if ans:
    print("Yes")
else:
    print("No")

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

s = s.split("T")
s = [len(e) for e in s]
a = []
b = []
for i, s in enumerate(s):
    if i % 2 == 0:
        a.append(s)
    else:
        b.append(s)

x -= a.pop(0)
ans = True

dpx = [[False] * (2*abs(x) + 1) for _ in range(len(a) + 1)]
dpx[0][abs(x)] = True

for i in range(1,len(a)+1):
    for j in range(2*abs(x) + 1):
        if j + a[i-1] < 2*abs(x) + 1:
            dpx[i][j] |= dpx[i-1][j+a[i-1]]
        if j - a[i-1] >= 0:
            dpx[i][j] |= dpx[i-1][j-a[i-1]]

ans &= dpx[len(a)][x+abs(x)]

dpy = [[False] * (2*abs(y) + 1) for _ in range(len(b) + 1)]
dpy[0][abs(y)] = True

for i in range(1, len(b) + 1):
    for j in range(2*abs(y) + 1):
        if j + b[i-1] < 2*abs(y) + 1:
            dpy[i][j] |= dpy[i-1][j+b[i-1]]
        if j - b[i-1] >= 0:
            dpy[i][j] |= dpy[i-1][j-b[i-1]]

ans &= dpy[len(b)][y+abs(y)]

if ans:
    print("Yes")
else:
    print("No")