Problem:
 Score : 500 points    Problem Statement A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive x -axis direction.  This robot will be given an instruction sequence s . s consists of the following two kinds of letters, and will be executed in order from front to back.   F : Move in the current direction by distance 1 .  T : Turn 90 degrees, either clockwise or counterclockwise.   The objective of the robot is to be at coordinates (x, y) after all the instructions are executed.
Determine whether this objective is achievable.      Constraints  s consists of F and T .  1 \leq |s| \leq 8  000  x and y are integers.  |x|, |y| \leq |s|         Input Input is given from Standard Input in the following format:  s  x  y       Output If the objective is achievable, print Yes ; if it is not, print No .        Sample Input 1 FTFFTFFF
4 2      Sample Output 1 Yes  The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T .       Sample Input 2 FTFFTFFF
-2 -2      Sample Output 2 Yes  The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T .       Sample Input 3 FF
1 0      Sample Output 3 No       Sample Input 4 TF
1 0      Sample Output 4 No       Sample Input 5 FFTTFF
0 0      Sample Output 5 Yes  The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T .       Sample Input 6 TTTT
1 0      Sample Output 6 No

Solution (Python):
import datetime
s = input()
x, y = map(int, input().split())

 
num_of_f = 0
for c in s:
    if c == 'F':
        num_of_f += 1
dp = [[[False] * 32001 for _ in range(2)] for _ in range(2)]
 
dp[0][0][0] = True
dp[0][1][0] = True

index = 0
while index < len(s) and s[index] == 'F':
    index += 1
x -= index
xy_axis = 1
dp_index = 1
i = index + 1
num_of_f = index
while i < len(s):
    num = 0
    while i < len(s) and s[i] == 'F':
        num += 1
        i += 1
    num_of_f += num
    for j in range(-1 * num_of_f, num_of_f + 1):
        dp[dp_index][xy_axis][j] = dp[(dp_index + 1) % 2][xy_axis][j - num] or dp[(dp_index + 1) % 2][xy_axis][j + num]
    xy_axis = (xy_axis + 1) % 2
    if xy_axis == 1:
        dp_index = (dp_index + 1) % 2
    i += 1
 

 
if dp[(dp_index + 1) % 2][0][x] and dp[(dp_index + xy_axis) % 2][1][y]:
    print('Yes')
else:
    print('No')

Solution (Python):
s = input()
x, y = map(int, input().split())
a = []
b = []
c = 0
n = 0
for i in range(len(s)):
  if s[i]=='F':
    n += 1
  else:
    if c%2==0:
      a += [n]
    else:
      b += [n]
    c += 1
    n = 0
if s[-1]=='F':
  if c%2==0:
    a += [n]
  else:
    b += [n]
sa = sum(a)
sb = sum(b)
dpa1 = [0]*(2*sa+1)
dpa2 = [0]*(2*sa+1)
dpb1= [0]*(2*sb+1)
dpb2 = [0]*(2*sb+1)
dpa1[sa] = 1
dpb1[sb] = 1
if len(a)>0:
  if sa-a[0]<abs(x-a[0]) or sb<abs(y):
    print('No')
    import sys
    sys.exit()
else:
  if sa<abs(x) or sb<abs(y):
    print('No')
    import sys
    sys.exit()

if len(a)%2==0:
  A = dpa1
else:
  A = dpa2
if len(b)%2==0:
  B = dpb1
else:
  B = dpb2

for i in range(len(a)):
  c = a[i]
  if i%2==0:
    for j in range(2*sa+1):
      if dpa1[j]==1:
        dpa1[j] = 0
        dpa2[j-c] = 1
        dpa2[j+c] = 1
  else:
    for j in range(2*sa+1):
      if dpa2[j]==1:
        dpa2[j] = 0
        dpa1[j-c] = 1
        dpa1[j+c] = 1
for i in range(len(b)):
  c = b[i]
  if i%2==0:
    for j in range(2*sb+1):
      if dpb1[j]==1:
        dpb1[j] = 0
        dpb2[j-c] = 1
        dpb2[j+c] = 1
  else:
    for j in range(2*sb+1):
      if dpb2[j]==1:
        dpb2[j] = 0
        dpb1[j-c] = 1
        dpb1[j+c] = 1

if A[x+sa]==1 and B[y+sb]==1:
  print('Yes')
else:
  print('No')

Solution (Python):

N = 8000
s = input()
target_x, target_y = map(int, input().split())


dat_f = [len(Fcount) for Fcount in s.split("T")]



curmap_x = [False] * ((N * 2 * 2) + 1)
curmap_y = [False] * ((N * 2 * 2) + 1)
nextmap_x = [False] * ((N * 2 * 2) + 1)
nextmap_y = [False] * ((N * 2 * 2) + 1)


if s[0] == "F":
    start = 1
    curmap_x[N * 2 + dat_f[0]] = True
    direction_x = False
else:
    start = 0
    curmap_x[N * 2] = True
    direction_x = True


curmap_y[N * 2] = True


for i in range(start, len(dat_f)):
    step = dat_f[i]
    if direction_x:
        for j in range(N, N + (N * 2) + 1):
            nextmap_x[j] = True if curmap_x[j - step] or curmap_x[j + step] else False
        curmap_x, nextmap_x = nextmap_x, curmap_x
    else:
        for j in range(N, N + (N * 2) + 1):
            nextmap_y[j] = True if curmap_y[j - step] or curmap_y[j + step] else False
        curmap_y, nextmap_y = nextmap_y, curmap_y

    
    direction_x = not direction_x

print("Yes" if curmap_x[N * 2 + target_x] and curmap_y[N * 2 + target_y] else "No")

Solution (Python):
from pprint import pprint

N = 8000

s = input()
target_x, target_y = map(int, input().split())


dat_f = [len(Fcount) for Fcount in s.split("T")]



curmap_x = [False] * ((N * 2 * 2) + 1)
curmap_y = [False] * ((N * 2 * 2) + 1)
nextmap_x = [False] * ((N * 2 * 2) + 1)
nextmap_y = [False] * ((N * 2 * 2) + 1)


if s[0] == "F":
    start = 1
    curmap_x[N * 2 + dat_f[0]] = True
    direction_x = False
else:
    start = 0
    curmap_x[N * 2] = True
    direction_x = True
curmap_y[N * 2] = True



for i in range(start, len(dat_f)):
    step = dat_f[i]
    if direction_x:
        for j in range(N, N + (N * 2) + 1):
            nextmap_x[j] = True if curmap_x[j - step] or curmap_x[j + step] else False
        curmap_x, nextmap_x = nextmap_x, curmap_x
    else:
        for j in range(N, N + (N * 2) + 1):
            nextmap_y[j] = True if curmap_y[j - step] or curmap_y[j + step] else False
        curmap_y, nextmap_y = nextmap_y, curmap_y

    direction_x = not direction_x

print("Yes" if curmap_x[N * 2 + target_x] and curmap_y[N * 2 + target_y] else "No")

Solution (Python):
s=input()
X,Y=map(int,input().split())
from collections import defaultdict
def solve(a,dp,G):
    for i in range(len(a)):
        tmp=set()
        for j in dp:
            tmp.add(j-a[i])
            tmp.add(j+a[i])
        dp=tmp
    if G in dp:
        return True
    else:
        return False

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

x=d[2::2]
dpx={d[0]}
y=d[1::2]
dpy={0}
if solve(x,dpx,X) and solve(y,dpy,Y):
    print("Yes")
else:
    print("No")

Solution (Python):
s=input()
X,Y=map(int,input().split())
from collections import defaultdict
def solve(da,dp,G):
    for i in range(len(da)):
        tmp=set()
        for j in dp:
            tmp.add(j-da[i])
            tmp.add(j+da[i])
        dp=tmp
    if G in dp:
        return True
    else:
        return False
    """amax=0
    for i in a:
        amax+=abs(i)
    if amax==0:
        if G==0:
            return True
        else:
            return False
    if a[0]==G:
        return True
    dp=[[0]*2*amax for _ in range(3)]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-amax,amax):
            dp[i%3][j-p]+=dp[(i-1)%3][j]
            dp[i%3][j+p]+=dp[(i-1)%3][j]
            
        if dp[i%3][G]>=1:
            return True
    return False"""
    """
    dp=set()
    dp.add(a[0])
    dp2=set()
    for i in range(1,len(a)):
        for j in dp:
            dp2.add(j-a[i])
            dp2.add(j+a[i])
        dp=copy.deepcopy(dp2)
    
    if G in dp:
        return True
    return False"""

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

dx=d[2::2]
dy=d[1::2]

if solve(dx,{d[0]},X) and solve(dy,{0},Y):
    print("Yes")
else:
    print("No")

Solution (Python):
s=input()
X,Y=map(int,input().split())
from collections import defaultdict
def solve(da,dp,G):
    for i in range(len(da)):
        tmp=set()
        for j in dp:
            tmp.add(j-da[i])
            tmp.add(j+da[i])
        dp=tmp
    if G in dp:
        return True
    else:
        return False
    """amax=0
    for i in a:
        amax+=abs(i)
    if amax==0:
        if G==0:
            return True
        else:
            return False
    if a[0]==G:
        return True
    dp=[[0]*2*amax for _ in range(3)]
    dp[0][a[0]]=1
    for i in range(1,len(a)):
        p=a[i]
        for j in range(-amax,amax):
            dp[i%3][j-p]+=dp[(i-1)%3][j]
            dp[i%3][j+p]+=dp[(i-1)%3][j]
            
        if dp[i%3][G]>=1:
            return True
    return False"""
    """
    dp=set()
    dp.add(a[0])
    dp2=set()
    for i in range(1,len(a)):
        for j in dp:
            dp2.add(j-a[i])
            dp2.add(j+a[i])
        dp=copy.deepcopy(dp2)
    
    if G in dp:
        return True
    return False"""

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

dx=d[2::2]
dy=d[1::2]

if solve(dx,{d[0]},X) and solve(dy,{0},Y):
    print("Yes")
else:
    print("No")

Solution (Python):
import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

S = list(rs())
X, Y = rl()

xy = [[], []]
dir = 0 
cur = 0
for s in S:
    if s == 'F':
        cur += 1
    else:
        xy[dir].append(cur)
        cur = 0
        dir = 1 - dir
xy[dir].append(cur)

xmax = sum(xy[0])
dif_x = xmax - X
ymax = sum(xy[1])
dif_y = ymax - Y
if dif_x&1 == 1 or dif_y&1 == 1:
    print('No')
    exit()
dif_x //= 2
dif_y //= 2
xset = set([0])
for x in xy[0][1:]:
    new_set = set()
    for z in xset:
        new_set.add(z+x)
    xset = xset.union(new_set)
yset = set([0])
for y in xy[1]:
    new_set = set()
    for z in yset:
        new_set.add(z+y)
    yset = yset.union(new_set)

if dif_x in xset and dif_y in yset:
    print('Yes')
else:
    print('No')

Solution (Python):
S = input()+'T'
X,Y = map(int,input().split())

xmove = []
ymove = []

tmp = 0
flag = True
for i in range(len(S)):
    if S[i]=='F':
        tmp += 1
    elif flag and S[i]=='T':
        xmove.append(tmp*2)
        tmp = 0
        flag = False
    else:
        ymove.append(tmp*2)
        tmp = 0
        flag = True
        
if xmove:
    x0 = xmove.pop(0)//2
else:
    x0 = 0

xgoal = sum(xmove)//2+X-x0
ygoal = sum(ymove)//2+Y

def subsetsum(arr,s):
    if not arr or s < 0:
        if s==0:
            return True
        else:
            return False
    dp = [[0 for j in range(s+1)] for i in range(len(arr)+1)]
    dp[0][0] = 1
    for i in range(1,len(arr)+1):
        for j in range(s+1):
            if j-arr[i-1]>=0:
                dp[i][j] = (dp[i-1][j-arr[i-1]] | dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    return dp[-1][s]
    
if subsetsum(xmove,xgoal) and subsetsum(ymove,ygoal):
    print('Yes')
else:
    print('No')

Solution (Python):
S = input().split('T')
x, y = map(int, input().split())

x_axis = S[::2]
y_axis = S[1::2]

const = 8000
x_pos = 1 << const
y_pos = 1 << const
first = True
for s in x_axis:
    step = len(s)
    if first:
        x_pos <<= step
        first = False
    else:
        x_pos = x_pos << step | x_pos >> step

for s in y_axis:
    step = len(s)
    y_pos = y_pos << step | y_pos >> step

if x_pos >> (const+x) & 1 and y_pos >> (const+y) & 1:
    print('Yes')
else:
    print('No')

Solution (Python):
S = input()
x, y = map(int, input().split())

x_axis = 1 << 8000
y_axis = 1 << 8000
first = True
axis = 0  
count = 0

for s in S:
    if s == 'T':
        if axis == 0:
            if first:
                x_axis = x_axis << count
            else:
                x_axis = (x_axis << count) | (x_axis >> count)
        else:
            y_axis = (y_axis << count) | (y_axis >> count)

        axis = 1 - axis  
        first = False
        count = 0

    else:
        count += 1

if count:
    if axis == 0:
        if first:
            x_axis = x_axis << count
        else:
            x_axis = (x_axis << count) | (x_axis >> count)
    else:
        y_axis = (y_axis << count) | (y_axis >> count)


if (x_axis >> (8000+x)) & 1 and (y_axis >> (8000+y)) & 1:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys


s = sys.stdin.readline().rstrip()
x, y = map(int, sys.stdin.readline().split())

def reachable(deltas, goal):
    if not deltas:
        if goal == 0:
            return True
        else:
            return False
    
    s = sum(deltas)
    if goal < -s or s < goal:
        return False

    if (s - goal) & 1:
        return False

    a = (s - goal) // 2

    res = [False] * (a + 1)
    res[0] = True
    for d in deltas:
        for i in range(a, -1, -1):
            if res[i] and i + d <= a:
                res[i+d] = True
    return res[a]

def main():
    gx = x; gy = y
    dx = []
    dy = []
    direction = 0

    origin_x = 0
    for i in s:
        if i == 'T':
            break
        origin_x += 1
    gx -= origin_x

    tmp = 0
    for i in s[origin_x:] + 'T':
        if i == 'T':
            if direction == 0:
                if tmp != 0:
                    dx.append(tmp)
                direction = 1
            else:
                if tmp != 0:
                    dy.append(tmp)
                direction = 0
            tmp = 0
        else:
            tmp += 1

    return 'Yes' if reachable(dx, gx) & reachable(dy, gy) else 'No'
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import sys

s = sys.stdin.readline().rstrip()
x, y = map(int, sys.stdin.readline().split())

def reachable(deltas, goal):
    if not deltas:
        if goal == 0:
            return True
        else:
            return False
    
    s = sum(deltas)
    if goal < -s or s < goal:
        return False

    res = [False] * (s * 2 + 1) 
    res[s] = True
    
    for d in deltas:
        prev = res.copy()
        res = [False] * (s * 2 + 1)
        for i in range(s*2+1):
            if prev[i]:
                res[i+d] = res[i-d] = True

    return res[s + goal]


def main():
    gx = x; gy = y
    dx = []
    dy = []
    direction = 0

    origin_x = 0
    for i in s:
        if i == 'T':
            break
        origin_x += 1
    gx -= origin_x

    tmp = 0
    for i in s[origin_x:] + 'T':
        if i == 'T':
            if direction == 0:
                if tmp != 0:
                    dx.append(tmp)
                direction = 1
            else:
                if tmp != 0:
                    dy.append(tmp)
                direction = 0
            tmp = 0
        else:
            tmp += 1

    return 'Yes' if reachable(dx, gx) & reachable(dy, gy) else 'No'
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):






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











s = s + 'x'





s





renzoku = 1
xyres = [1 << 8000, 1 << 8000]
xy = 0
M = (1 << 16001) - 1
first = s[0] == 'F'
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        renzoku += 1
    else:

        if first:
            xyres[0] = 1 << (8000 + renzoku)
            first = False
        else:
            if s[i] == 'F':
                xyres[xy] = (xyres[xy] << renzoku) | (xyres[xy] >> renzoku) & M
            elif renzoku % 2 == 1:
                xy = 1 - xy
        renzoku = 1
        





if xyres[0] & 1 << (8000 + x) and xyres[1] & 1 << (8000 + y):
    print('Yes')
else:
    print('No')

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

SIZE = 10 ** 4

M = [0] if S[0] == "T" else []
for i in range(1, len(S)):
  if S[i] != S[i-1]:
    M.append(i)
M.append(len(S))
M = [0] + M


L = []
for i in range(1, len(M)):
  L.append(M[i] - M[i - 1])


for i in range(3, len(L), 2):
  L[i] += L[i - 2]
L = [0] + L


x = 1 << SIZE
y = 1 << SIZE



for i in range(1, len(L), 2):
  dist = L[i]
  dirc = L[i - 1]
  
  if i == 1:
    x = x << dist
  else:
    if dirc % 2 == 0:
      x = (x << dist) | (x >> dist)
    else:
      y = (y << dist) | (y >> dist)
      
if (x >> SIZE + X) & 1 == 1 and (y >> SIZE + Y) & 1 == 1:
  print("Yes")
else:
  print("No")

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)
X, Y = MAP()


A1, A2 = [], []
cnt = d = 0
for s in S:
    if s == 'T':
        if d == 0:
            A1.append(cnt)
        else:
            A2.append(cnt)
        cnt = 0
        d ^= 1
    else:
        cnt += 1
if d == 0:
    A1.append(cnt)
else:
    A2.append(cnt)

X -= A1[0]
A1.pop(0)


M1 = len(A1)
M2 = len(A2)

dpx = [0] * (M1+1)
dpy = [0] * (M2+1)

offset = 20000
dpx[0] = 1 << offset
dpy[0] = 1 << offset
for i, a in enumerate(A1):
    dpx[i+1] |= dpx[i] << a
    dpx[i+1] |= dpx[i] >> a
for i, a in enumerate(A2):
    dpy[i+1] |= dpy[i] << a
    dpy[i+1] |= dpy[i] >> a

if dpx[M1] & 1<<(X + offset) and dpy[M2] & 1<<(Y + offset):
    Yes()
else:
    No()

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()
N = len(S)
X, Y = MAP()


A1, A2 = [], []
cnt = d = 0
for s in S:
    if s == 'T':
        if d == 0:
            A1.append(cnt)
        else:
            A2.append(cnt)
        cnt = 0
        d ^= 1
    else:
        cnt += 1
if d == 0:
    A1.append(cnt)
else:
    A2.append(cnt)

X -= A1[0]
A1.pop(0)


M1 = len(A1)
M2 = len(A2)
dpx = [set() for i in range(M1+1)]
dpy = [set() for i in range(M2+1)]
dpx[0].add(0)
dpy[0].add(0)
for i, a in enumerate(A1):
    for x in dpx[i]:
        dpx[i+1].add(x+a)
        dpx[i+1].add(x-a)
for i, a in enumerate(A2):
    for y in dpy[i]:
        dpy[i+1].add(y+a)
        dpy[i+1].add(y-a)

if X in dpx[M1] and Y in dpy[M2]:
    Yes()
else:
    No()

Solution (Python):
S = input()
X,Y = map(int,input().split())
T0 = 0
XList = []
YList = []
N = len(S)
t = 0
f = 0
for i in range(N):
    c = S[i]
    if c == 'F':
        f += 1
    else:
        if t == 0:
            T0 = f
        else:
            if t % 2 == 0:
                if f > 0:
                    XList.append(f)
            else:
                if f > 0:
                    YList.append(f)
        f = 0
        t += 1
if f > 0:
    if t == 0:
        T0 = f
    else:
        if t % 2 == 0:
            XList.append(f)
        else:
            YList.append(f)

xset = set()
yset = set()
tset = set()

xset.add( T0 )
for f in XList:
    tset.clear()
    for x in xset:
        tset.add(x+f)
        tset.add(x-f)
    xset.clear()
    for x in tset:
        xset.add(x)

yset.add( 0 )
for f in YList:
    tset.clear()
    for y in yset:
        tset.add(y+f)
        tset.add(y-f)
    yset.clear()
    for y in tset:
        yset.add(y)

if X in xset and Y in yset:
    print('Yes')
else:
    print('No')

Solution (Python):
s = list(input().split("T"))
x, y = map(int, input().split())
s2 = [len(x) for x in s]
LR = [s2[i] for i in range(len(s2)) if i % 2 == 0]
UD = [s2[i] for i in range(len(s2)) if i % 2 == 1]

flag = False
tmp = 1
tmp = tmp << sum(LR)
for i, d in enumerate(LR):
    if i != 0:
        tmp = tmp << d | tmp >> d
    else:
        tmp = tmp << d

if x >= 0:
    tmp = tmp >> sum(LR)
    if (tmp >> x) % 2 == 1:
        flag = True
else:
    if sum(LR) + x >= 0:
        if (tmp >> (sum(LR) + x)) % 2 == 1:
            flag = True
if flag:

    tmp = 1
    tmp = tmp << sum(UD)
    flag = False
    for d in UD:
        tmp = tmp << d | tmp >> d
    if y >= 0:
        tmp = tmp >> sum(UD)
        if (tmp >> y) % 2 == 1:
            flag = True
    else:
        if sum(UD) + y >= 0:
            if (tmp >> (sum(UD) + y)) % 2 == 1:
                flag = True

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

Solution (Python):
      
s=input()
gx,gy=map(int,input().split())
lists=list(s.split("T"))
xlist=[]
ylist=[]
if s[0]=="T":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
elif s[0]=="F":
    for i in range(len(lists)):
        if i%2==0:
            xlist.append(len(lists[i]))
        else:
            ylist.append(len(lists[i]))
    gx-=xlist[0]
    del xlist[0]
Xsum=sum(xlist)
Ysum=sum(ylist)


if (Xsum+gx)%2!=0 or (Ysum+gy)%2!=0:
    print("No")   
else:
    gx1=(Xsum+gx)//2
    gx2=(Xsum-gx)//2
    gy1=(Ysum+gy)//2
    gy2=(Ysum-gy)//2
    dpx=[[False for i in range(Xsum+2)] for j in range(len(xlist)+2)]
    dpy=[[False for i in range(Ysum+2)] for j in range(len(ylist)+2)]
    
    dpx[0][0]=True
    dpy[0][0]=True
    for i in range(len(xlist)):
        for j in range(Xsum+2):
            dpx[i+1][j]=dpx[i][j-xlist[i]] or dpx[i][j]
    for i in range(len(ylist)):
        for j in range(Ysum+2):
            dpy[i+1][j]=dpy[i][j-ylist[i]] or dpy[i][j]    
    
    flag1=False
    if 0<= gy1<= Ysum:   
        if dpy[len(ylist)][gy1]:
            flag1=True
    flag2=False
    if 0<=gy2<= Ysum :
        if dpy[len(ylist)][gy2]:
            flag2=True
    flag3=False
    if 0<=gx1<= Xsum:
        if dpx[len(xlist)][gx1]:
            flag3=True
    flag4=False
    if 0<=gx2<= Xsum:
        if dpx[len(xlist)][gx2]:
            flag4=True
    if (flag1 or flag2) and (flag3 or flag4):
        print("Yes")
    else:
        print("No")

Solution (Python):
import copy

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

X = []
Y = []
l = 0
f = -1
xinit = 0
A = s + 'T'
for a in A:
  if a == 'T':
    if f == -1:
      xinit = l
      f = 1
    elif f == 0:
      X.append(l)
      f = 1
    else:
      Y.append(l)
      f = 0
    l = 0
  else:
    l += 1

def pattern(P,init=0):
  Q = set()
  Q.add(init)
  for p in P:
    QQ = set()
    for q in Q:
      QQ.add(q+p)
      QQ.add(q-p)
    Q = copy.copy(QQ)
  return Q

XX = pattern(X,xinit)
YY = pattern(Y)

if x in XX and y in YY:
  print('Yes')
else:
  print('No')

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()
x, y = MAP()

x_list = []
y_list = []
for i, s_ in enumerate(s.split('T')):
	if i == 0:
		x -= len(s_)
	elif i % 2 == 0:
		x_list.append(len(s_))
	else:
		y_list.append(len(s_))

def check(d, x):
  se =set([0])
  for dx in d:
    se={a+b for a,b in product(se,[-dx,dx])}  
  return (x in se)

print('Yes' if check(x_list, x) and check(y_list, y) else 'No')

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = S() + 'T'
x, y = LI()
t_flag = 0

flag = 0
y_now = x_now = 1 << 8000
f_cnt = 0
for j in s:
    if j == 'T':
        if not flag:
            flag = 1
            x_now >>= f_cnt
        elif t_flag:
            y_now = y_now >> f_cnt | y_now << f_cnt
        else:
            x_now = x_now >> f_cnt | x_now << f_cnt
        t_flag ^= 1
        f_cnt = 0
    else:
        f_cnt += 1


if 1 << 8000 + y & y_now and 1 << 8000 - x & x_now:
    print('Yes')
else:
    print('No')

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = S() + 'T'
x, y = LI()
t_flag = 0

flag = 0
y_now = x_now = 1 << 8000
f_cnt = 0
for j in s:
    if j == 'T':
        if not flag:
            flag = 1
            x_now >>= f_cnt
        elif t_flag:
            y_now = y_now >> f_cnt | y_now << f_cnt
        else:
            x_now = x_now >> f_cnt | x_now << f_cnt
        t_flag ^= 1
        f_cnt = 0
    else:
        f_cnt += 1


if (1 << 8000 + y) & y_now and (1 << 8000 - x) & x_now:
    print('Yes')
else:
    print('No')

Solution (Python):
s = input()
x, y = map(int, input().split())
totalx = 0
totaly = 0
shift_x = []
shift_y = []
index = 0
while s[index] != "T" and index +1< len(s):
    totalx += 1
    index += 1
flag = 1
count = 0
for i in range(index, len(s)):
    if s[i] == "T":
        if flag == 1:
            shift_x.append(count)
        else:
            shift_y.append(count)
        flag *= -1
        count = 0
    else:
        count += 1
if flag == 1:
    shift_x.append(count)
else:
    shift_y.append(count)
shift_x.sort()
shift_x.reverse()
shift_y.sort()
shift_y.reverse()
for i in range(len(shift_x)):
    if totalx < x:
        totalx += shift_x[i]
    else:
        totalx -= shift_x[i]
for i in range(len(shift_y)):
    if totaly < y:
        totaly += shift_y[i]
    else:
        totaly -= shift_y[i]
if totalx == x and totaly == y:
    print("Yes")
else:
    print("No")

Solution (Python):
l = [len(c) for c in input().split("T")]
x, y = map(int, input().split())
bx = 1 << l.pop(0) + 8000
by = 1 << 8000
for i, d in enumerate(l):
	if i % 2:
		bx = (bx << d) | (bx >> d)
	else:
		by = (by << d) | (by >> d)
print("Yes" if bx & (1 << x + 8000) and by & (1 << y + 8000) else "No")

Solution (Python):
import sys
s = input()
gx,gy = map(int, input().split(' '))
x_d = [0]
y_d = []
cnt = 0
for i in range(len(s)):
    if s[i] == "T":
        cnt += 1
        if cnt % 2 == 0:
            x_d.append(0)
        elif cnt % 2 == 1:
            y_d.append(0)
    if s[i] == "F":
        if cnt % 2 == 0:
            x_d[-1] += 1
        elif cnt % 2 == 1:
            y_d[-1] += 1
gx -= x_d[0]
x_d[0] = 0
x_d.append(0)
y_d.append(0)
if (sum(x_d)-gx) % 2 or (sum(y_d)-gy) % 2 or sum(x_d) < abs(gx) or sum(y_d) < abs(gy):
    print("No")
    sys.exit()
x_n = (sum(x_d)-gx)//2
y_n = (sum(y_d)-gy)//2
DPx = [[False for i in range(x_n+2)] for j in range(len(x_d))]
DPy = [[False for i in range(y_n+2)] for j in range(len(y_d))]
for x in DPx:
    x[0] = True
for y in DPy:
    y[0] = True
for i in range(len(x_d)-1):
    for j in range(x_n+1):
        if DPx[i][j]:
            DPx[i+1][j] = True
            if j+x_d[i] <= x_n+1:
                DPx[i+1][j+x_d[i]] = True
for i in range(len(y_d)-1):
    for j in range(y_n+1):
        if DPy[i][j]:
            DPy[i+1][j] = True
            if j+y_d[i] <= y_n+1:
                DPy[i+1][j+y_d[i]] = True
if DPx[len(x_d)-1][x_n] and DPy[len(y_d)-1][y_n]:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
input = sys.stdin.readline

S = input().rstrip()
gx, gy = map(int, input().split())
L = len(S)

XY = [[], []]
d = 0
c = 0
begin = True
for s in S:
    if begin and s == "F":
        gx -= 1
    elif s == 'T':
        begin = False
        if c > 0:
            XY[d].append(c)
        d ^= 1
        c = 0
    else:
        c += 1
if c > 0:
    XY[d].append(c)

XY[0].append(abs(gx))
XY[1].append(abs(gy))

ans = True
for X in XY:
    G = sum(X)
    if G%2 != 0:
        ans = False
        break
    G //= 2
    ok = False
    W = len(X)
    dp = [False]*(G+1)
    dp[0] = True
    for i, x in enumerate(X):
        for g in reversed(range(G+1)):
            if g >= x:
                dp[g] = dp[g-x] or dp[g]
        if dp[G]:
            ok = True
            break
    ans = ok and ans
print("Yes" if ans else "No")

Solution (Python):


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

f = [len(x) for x in s.split("T")]
x -= f[0]
fx = f[2::2]
fy = f[1::2]

x_possible_set = set([0])
for dx in fx:
    x_possible_set = set([xi + dx for xi in x_possible_set] + [xi - dx for xi in x_possible_set])

y_possible_set = set([0])
for dy in fy:
    y_possible_set = set([yi + dy for yi in y_possible_set] + [yi - dy for yi in y_possible_set])

print("Yes" if x in x_possible_set and y in y_possible_set else "No")

Solution (Python):


import copy

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

f = [len(x) for x in s.split("T")]
x -= f[0]
fx = f[2::2]
fy = f[1::2]

x_possible_set = set([0])
for dx in fx:
    tmp = set()
    for current_x in x_possible_set:
        tmp.add(current_x + dx)
        tmp.add(current_x - dx)
    x_possible_set = tmp.copy()

y_possible_set = set([0])
for dy in fy:
    tmp = set()
    for current_y in y_possible_set:
        tmp.add(current_y + dy)
        tmp.add(current_y - dy)
    y_possible_set = tmp.copy()

print("Yes" if x in x_possible_set and y in y_possible_set else "No")

Solution (Python):
import itertools
S=str(input())
x,y=map(int,input().split())
Move=[len(s) for s in S.split('T')]
x -=Move[0]
Move_x=Move[2::2]
Move_y=Move[1::2]

def check(d,x):
  se =set([0])
  for dx in d:
    se={a+b for a,b in itertools.product(se,[-dx,dx])}
  return (x in se)

print('Yes' if check(Move_x,x) and check(Move_y,y) else 'No')