Buggy python submission (verdict: Time Limit Exceeded):
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    OFS = 8000
    dp = [0] * (2*OFS+1)
    dp[OFS+s] = 1
    for i in range(len(D)):
        d = D[i]
        ndp = [0] * (2*OFS+1)
        for j in range(2*OFS+1):
            try:
                ndp[j] += dp[j-d]
            except:
                pass
            try:
                ndp[j] += dp[j+d]
            except:
                pass
        dp = ndp
    return dp[OFS+g] > 0

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')


Fixed submission:
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    dp = [{} for _ in range(len(D)+1)]
    dp[0][s] = 1
    for i in range(len(D)):
        d = D[i]
        for j in dp[i]:
            dp[i+1][j+d] = 1
            dp[i+1][j-d] = 1
    return g in dp[-1]

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    OFS = 8000
    dp = [0] * (2*OFS+1)
    dp[OFS+s] = 1
    for i in range(len(D)):
        d = D[i]
        ndp = [0] * (2*OFS+1)
        for j in range(2*OFS+1):
            try:
                ndp[j] += dp[j-d]
            except:
                pass
            try:
                ndp[j] += dp[j+d]
            except:
                pass
        dp = ndp
    return dp[OFS+g] > 0

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')


Fixed submission:
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    dp = [{} for _ in range(len(D)+1)]
    dp[0][s] = 1
    for i in range(len(D)):
        d = D[i]
        for j in dp[i]:
            dp[i+1][j+d] = 1
            dp[i+1][j-d] = 1
    return g in dp[-1]

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    OFS = 5
    dp = [0] * (2*OFS+1)
    dp[OFS+s] = 1
    for i in range(len(D)):
        d = D[i]
        ndp = [0] * (2*OFS+1)
        for j in range(2*OFS+1):
            try:
                ndp[j] += dp[j-d]
            except:
                pass
            try:
                ndp[j] += dp[j+d]
            except:
                pass
        dp = ndp
    return dp[OFS+g] > 0

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')


Fixed submission:
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    dp = [{} for _ in range(len(D)+1)]
    dp[0][s] = 1
    for i in range(len(D)):
        d = D[i]
        for j in dp[i]:
            dp[i+1][j+d] = 1
            dp[i+1][j-d] = 1
    return g in dp[-1]

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
gx, gy = map(int, input().split())

from collections import deque
# 命令, x, y, 向き
q = deque([[-1, 0, 0, (1, 0)]])

ans = 'No'
while q:
    i, x, y, rot = q.popleft()
    if i == len(S)-1 and x==gx and y == gy:
        ans = 'Yes'
        break
    elif i == len(S)-1:
        continue
    ind = S[i+1]

    if ind == 'T':
        q.append((i+1, x, y, (-rot[1], rot[0])))
        q.append((i+1, x, y, (rot[1], -rot[0])))
    else:
        if abs(gx-x-rot[0]) + abs(gy-y-rot[1]) < len(S)-i:
            q.append((i+1, x+rot[0], y+rot[1], rot))
    
print(ans)


Fixed submission:
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    dp = [{} for _ in range(len(D)+1)]
    dp[0][s] = 1
    for i in range(len(D)):
        d = D[i]
        for j in dp[i]:
            dp[i+1][j+d] = 1
            dp[i+1][j-d] = 1
    return g in dp[-1]

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
gx, gy = map(int, input().split())

from collections import deque
q = deque([[-1, 0, 0, (1, 0)]])

ans = 'No'
while q:
    i, x, y, rot = q.popleft()

    if i == len(s)-1 and x==gx and y == gy:
        ans = 'Yes'
        break
    elif i == len(s)-1:
        continue
    
    ind = s[i+1]

    if ind == 'F':
        q.append((i+1, x+rot[0], y+rot[1], rot))
    else:
        q.append((i+1, x, y, (-rot[1], rot[0])))
        q.append((i+1, x, y, (rot[1], -rot[0])))
print(ans)


Fixed submission:
S = input()
gx, gy = map(int, input().split())
SL = S.split('T')
D = [len(sli) for sli in SL]
DX = D[2::2]
DY = D[1::2]

def reachable(D, s, g):
    dp = [{} for _ in range(len(D)+1)]
    dp[0][s] = 1
    for i in range(len(D)):
        d = D[i]
        for j in dp[i]:
            dp[i+1][j+d] = 1
            dp[i+1][j-d] = 1
    return g in dp[-1]

if reachable(DX, D[0], gx) and reachable(DY, 0, gy):
    print('Yes')
else:
    print('No')