Buggy python submission (verdict: Time Limit Exceeded):
s = input()
x, y = map(int, input().split())
n = len(s)

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = 8005#sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            aa = 0
            bb = 0
            if 0 <= k-dd <= len(DP[0])-1:
                aa = DP[j][k-dd]
            if 0 <= k+dd <= len(DP[0])-1:
                bb = DP[j][k+dd]

            DP[j+1][k] = int(aa or bb)

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    # print("len",mid*2)
    #if i == 1:
        # print(DP[1][7999+mid])
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            aa = 0
            bb = 0
            if 0 <= k-dd <= len(DP[0])-1:
                aa = DP[j][k-dd]
            if 0 <= k+dd <= len(DP[0])-1:
                bb = DP[j][k+dd]

            DP[j+1][k] = int(aa or bb)

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    # print("len",mid*2)
    #if i == 1:
        # print(DP[1][7999+mid])
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

Buggy python submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())
n = len(s)

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    st_x += 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [st_x, st_y]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            if 0 <= k-dd <= len(DP[0])-1 and 0 <= k+dd <= len(DP[0])-1:
                DP[j+1][k] = int(DP[j][k-dd] or DP[j][k+dd])

    ANS[i] = DP[-1][go_po[i]+mid]
    # print(DP)
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            aa = 0
            bb = 0
            if 0 <= k-dd <= len(DP[0])-1:
                aa = DP[j][k-dd]
            if 0 <= k+dd <= len(DP[0])-1:
                bb = DP[j][k+dd]

            DP[j+1][k] = int(aa or bb)

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    # print("len",mid*2)
    #if i == 1:
        # print(DP[1][7999+mid])
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

Buggy python submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())
n = len(s)

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    st_x += 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)

mid = 10
ANS = [0, 0]
st_po = [st_x, st_y]
go_po = [x, y]
for i in range(2):
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            if 0 <= k-dd <= len(DP[0])-1 and 0 <= k+dd <= len(DP[0])-1:
                DP[j+1][k] = int(DP[j][k-dd] or DP[j][k+dd])

    ANS[i] = DP[-1][go_po[i]+mid]
    # print(DP)
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            aa = 0
            bb = 0
            if 0 <= k-dd <= len(DP[0])-1:
                aa = DP[j][k-dd]
            if 0 <= k+dd <= len(DP[0])-1:
                bb = DP[j][k+dd]

            DP[j+1][k] = int(aa or bb)

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    # print("len",mid*2)
    #if i == 1:
        # print(DP[1][7999+mid])
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

Buggy python submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())
n = len(s)

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    st_x += 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)

mid = 10
ANS = [0, 0]
st_po = [st_x, st_y]
go_po = [x, y]
for i in range(2):
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            if 0 <= k-dd <= len(DP[0])-1 and 0 <= k+dd <= len(DP[0])-1:
                DP[j+1][k] = int(DP[j][k-dd] or DP[j][k+dd])

    ANS[i] = DP[-1][go_po[i]+mid]
    # print(DP)
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            aa = 0
            bb = 0
            if 0 <= k-dd <= len(DP[0])-1:
                aa = DP[j][k-dd]
            if 0 <= k+dd <= len(DP[0])-1:
                bb = DP[j][k+dd]

            DP[j+1][k] = int(aa or bb)

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    # print("len",mid*2)
    #if i == 1:
        # print(DP[1][7999+mid])
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

Buggy python submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())

XY = [[], []]
b = 0
renzoku = 0
for i in range(len(s)) :
    if s[i] == "T" :
        b = (b+1) % 2
        renzoku = 0
    else :
        if renzoku == 0 :
            XY[b].append(1)
            renzoku = 1
        else :
            XY[b][-1] += 1


#print(XY)

g = 8010

X = [[0 for i in range(g*2)] for j in range(len(XY[0]))]
Y = [[0 for i in range(g*2)] for j in range(len(XY[1]))]



if len(XY[0]) > 0 :
    X[0][g+XY[0][0]] = 1
    if s[0] == "T" :
        X[0][g-XY[0][0]] = 1
        
    for i in range(1, len(XY[0])) :
        for j in range(g*2) :
            #print(X)
            if j - XY[0][i] >= 0 and X[i-1][j - XY[0][i]] == 1 :
                X[i][j] = 1
            if j + XY[0][i] <= g*2-1 and X[i-1][j + XY[0][i]] == 1 :
                X[i][j] = 1

if len(XY[1]) > 0 :

    Y[0][g+XY[1][0]] = 1
    Y[0][g-XY[1][0]] = 1
        
    for i in range(1, len(XY[1])) :
        for j in range(20000) :
            if j - XY[1][i] >= 0 and Y[i-1][j - XY[1][i]] == 1 :
                Y[i][j] = 1
            if j + XY[1][i] <= g*2-1 and Y[i-1][j + XY[1][i]] == 1 :
                Y[i][j] = 1

if X == [] :
    X = [[0 for i in range(g*2)]]
if Y == [] :
    Y = [[0 for i in range(g*2)]]

if ((len(XY[0]) == 0 and x == 0) or X[-1][g+x] == 1) and ((len(XY[1]) == 0 and y == 0) or Y[-1][g+y] == 1) :
    print("Yes")
else :
    print("No")


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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            aa = 0
            bb = 0
            if 0 <= k-dd <= len(DP[0])-1:
                aa = DP[j][k-dd]
            if 0 <= k+dd <= len(DP[0])-1:
                bb = DP[j][k+dd]

            DP[j+1][k] = int(aa or bb)

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    # print("len",mid*2)
    #if i == 1:
        # print(DP[1][7999+mid])
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

Buggy python submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())

XY = [[], []]
b = 0
renzoku = 0
for i in range(len(s)) :
    if s[i] == "T" :
        b = (b+1) % 2
        renzoku = 0
    else :
        if renzoku == 0 :
            XY[b].append(1)
            renzoku = 1
        else :
            XY[b][-1] += 1


#print(XY)

g = 8002

X = [[0 for i in range(g*2)] for j in range(len(XY[0]))]
Y = [[0 for i in range(g*2)] for j in range(len(XY[1]))]



if len(XY[0]) > 0 :
    X[0][g+XY[0][0]] = 1
    if s[0] == "T" :
        X[0][g-XY[0][0]] = 1
        
    for i in range(1, len(XY[0])) :
        for j in range(g*2) :
            #print(X)
            if j - XY[0][i] >= 0 and X[i-1][j - XY[0][i]] == 1 :
                X[i][j] = 1
            if j + XY[0][i] <= g*2-1 and X[i-1][j + XY[0][i]] == 1 :
                X[i][j] = 1

if len(XY[1]) > 0 :

    Y[0][g+XY[1][0]] = 1
    Y[0][g-XY[1][0]] = 1
        
    for i in range(1, len(XY[1])) :
        for j in range(20000) :
            if j - XY[1][i] >= 0 and Y[i-1][j - XY[1][i]] == 1 :
                Y[i][j] = 1
            if j + XY[1][i] <= g*2-1 and Y[i-1][j + XY[1][i]] == 1 :
                Y[i][j] = 1

if X == [] :
    X = [[0 for i in range(g*2)]]
if Y == [] :
    Y = [[0 for i in range(g*2)]]

if ((len(XY[0]) == 0 and x == 0) or X[-1][g+x] == 1) and ((len(XY[1]) == 0 and y == 0) or Y[-1][g+y] == 1) :
    print("Yes")
else :
    print("No")


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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            aa = 0
            bb = 0
            if 0 <= k-dd <= len(DP[0])-1:
                aa = DP[j][k-dd]
            if 0 <= k+dd <= len(DP[0])-1:
                bb = DP[j][k+dd]

            DP[j+1][k] = int(aa or bb)

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    # print("len",mid*2)
    #if i == 1:
        # print(DP[1][7999+mid])
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

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

XY = [[], []]
b = 0
renzoku = 0
for i in range(len(s)) :
    if s[i] == "T" :
        b = (b+1) % 2
        renzoku = 0
    else :
        if renzoku == 0 :
            XY[b].append(1)
            renzoku = 1
        else :
            XY[b][-1] += 1


#print(XY)

g = 10000

X = [[0 for i in range(g*2)] for j in range(len(XY[0]))]
Y = [[0 for i in range(g*2)] for j in range(len(XY[1]))]



if len(XY[0]) > 0 :
    X[0][g+XY[0][0]] = 1
    if s[0] == "T" :
        X[0][g-XY[0][0]] = 1
        
    for i in range(1, len(XY[0])) :
        for j in range(g*2) :
            #print(X)
            if j - XY[0][i] >= 0 and X[i-1][j - XY[0][i]] == 1 :
                X[i][j] = 1
            if j + XY[0][i] <= g*2-1 and X[i-1][j + XY[0][i]] == 1 :
                X[i][j] = 1

if len(XY[1]) > 0 :

    Y[0][g+XY[1][0]] = 1
    Y[0][g-XY[1][0]] = 1
        
    for i in range(1, len(XY[1])) :
        for j in range(20000) :
            if j - XY[1][i] >= 0 and Y[i-1][j - XY[1][i]] == 1 :
                Y[i][j] = 1
            if j + XY[1][i] <= g*2-1 and Y[i-1][j + XY[1][i]] == 1 :
                Y[i][j] = 1

if X == [] :
    X = [[0 for i in range(g*2)]]
if Y == [] :
    Y = [[0 for i in range(g*2)]]

if ((len(XY[0]) == 0 and x == 0) or X[-1][g+x] == 1) and ((len(XY[1]) == 0 and y == 0) or Y[-1][g+y] == 1) :
    print("Yes")
else :
    print("No")


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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            aa = 0
            bb = 0
            if 0 <= k-dd <= len(DP[0])-1:
                aa = DP[j][k-dd]
            if 0 <= k+dd <= len(DP[0])-1:
                bb = DP[j][k+dd]

            DP[j+1][k] = int(aa or bb)

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    # print("len",mid*2)
    #if i == 1:
        # print(DP[1][7999+mid])
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")

Buggy python submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())

XY = [[], []]
b = 0
renzoku = 0
for i in range(len(s)) :
    if s[i] == "T" :
        b = (b+1) % 2
        renzoku = 0
    else :
        if renzoku == 0 :
            XY[b].append(1)
            renzoku = 1
        else :
            XY[b][-1] += 1


#print(XY)

g = 10

X = [[0 for i in range(g*2)] for j in range(len(XY[0]))]
Y = [[0 for i in range(g*2)] for j in range(len(XY[1]))]



if len(XY[0]) > 0 :
    X[0][g+XY[0][0]] = 1
    if s[0] == "T" :
        X[0][g-XY[0][0]] = 1
        
    for i in range(1, len(XY[0])) :
        for j in range(g*2) :
            #print(X)
            if j - XY[0][i] >= 0 and X[i-1][j - XY[0][i]] == 1 :
                X[i][j] = 1
            if j + XY[0][i] <= g*2-1 and X[i-1][j + XY[0][i]] == 1 :
                X[i][j] = 1

if len(XY[1]) > 0 :

    Y[0][g+XY[1][0]] = 1
    Y[0][g-XY[1][0]] = 1
        
    for i in range(1, len(XY[1])) :
        for j in range(20000) :
            if j - XY[1][i] >= 0 and Y[i-1][j - XY[1][i]] == 1 :
                Y[i][j] = 1
            if j + XY[1][i] <= g*2-1 and Y[i-1][j + XY[1][i]] == 1 :
                Y[i][j] = 1

if X == [] :
    X = [[0 for i in range(g*2)]]
if Y == [] :
    Y = [[0 for i in range(g*2)]]

if ((len(XY[0]) == 0 and x == 0) or X[-1][g+x] == 1) and ((len(XY[1]) == 0 and y == 0) or Y[-1][g+y] == 1) :
    print("Yes")
else :
    print("No")


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

D = [[], []]
st_x = 0
st_y = 0
st = 0
while st <= len(s)-1 and s[st] == "F":
    x -= 1
    st += 1

di = 0
for i in range(st, n):
    if s[i] == "T":
        di = (di+1) % 2
        D[di].append(0)
    else:
        D[di][-1] += 1

# print(D)


ANS = [0, 0]
st_po = [0, 0]
go_po = [x, y]
for i in range(2):
    mid = sum(D[i]) + 5
    DP = [[0] * (mid*2) for i in range(len(D[i]) + 1)]
    DP[0][st_po[i] + mid] = 1
    for j in range(len(D[i])):
        dd = D[i][j]
        for k in range(len(DP[0])):
            aa = 0
            bb = 0
            if 0 <= k-dd <= len(DP[0])-1:
                aa = DP[j][k-dd]
            if 0 <= k+dd <= len(DP[0])-1:
                bb = DP[j][k+dd]

            DP[j+1][k] = int(aa or bb)

    if 0 <= go_po[i]+mid <= len(DP[0])-1:
        ANS[i] = DP[-1][go_po[i]+mid]
    # print("len",mid*2)
    #if i == 1:
        # print(DP[1][7999+mid])
# print(ANS)

print("Yes" if ANS[0] and ANS[1] else "No")