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 copy

s = input()
X, Y = list(map(int, input().split()))








s += "T"

now = 1

start = 0
go = 0
x = []
y = []
for i in s:
    if i == "T":
        if start == 0:
            X = X - go
            go = 0
            start = 1
        else:
            if go != 0:
                if now == 1:
                    x.append(go)
                else:
                    y.append(go)
                go = 0
        now *= -1
    if i == "F":
        go += 1
x.sort()
y.sort()
x = x[::-1]
y = y[::-1]
X = abs(X)
Y = abs(Y)
x_use = sum(x) - X
y_use = sum(y) - Y
if x_use % 2 == 1 or y_use % 2 == 1 or x_use < 0 or y_use < 0:
    print("No")
    exit()
x_use = x_use//2
y_use = y_use//2


def solve(integer_list, target_sum,  i=0, sum=0):
    if sum > target_sum:
        return False
    if sum == target_sum:
        return True
    if i == len(integer_list):
        return sum == target_sum
    if (solve(integer_list, target_sum, i + 1, sum)):
        return True
    if (solve(integer_list, target_sum, i + 1, sum + integer_list[i])):
        return True
    return False







def part_sum0(a,A):
    
    N=len(a)
    dp=[[0 for i in range(A+1)] for j in range(N+1)]
    dp[0][0]=1

    
    for i in range(N):
        for j in range(A+1):
            if a[i]<=j: 
                dp[i+1][j]=dp[i][j-a[i]] or dp[i][j]
            else: 
                dp[i+1][j]=dp[i][j]
    return dp[N][A]
 
if part_sum0(x,x_use) and part_sum0(y, y_use):
    print("Yes")
else:
    print("No")

Solution (Python):

def search(arr, start):
    s = set()
    s.add(start)
    for i in arr:
        ns = set()
        for j in s:
            ns.add(j+i)
            ns.add(j-i)
        s = ns
    return s

def main():
    t = 0
    xd, yd = [], []

    inst = list(input())
    x, y = list(map(int, input().split()))

    xcum = 0
    ycum = 0
    first = True

    startx = 0
    for s in inst:
        if s == 'T':
            t += 1
            t %= 2
            if first:
                startx = xcum
                xcum = 0
                first = False
                continue
            if xcum > 0:
                xd.append(xcum)
                xcum = 0
            if ycum > 0:
                yd.append(ycum)
                ycum = 0
        else:
            if t == 0:
                xcum += 1
            else:
                ycum += 1
    if first:
        startx = xcum
    elif xcum > 0:
        xd.append(xcum)
        xcum = 0
    if ycum > 0:
        yd.append(ycum)
        ycum = 0

    
    
    
    if x in search(xd, startx) and y in search(yd, 0):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(8001)
s = input()
X, Y = map(int, input().split())
S = list(map(len, s.split('T')))
N = len(S)







x = S[0]
y = 0
xmoves = S[2::2]
xmoves.sort()
xmoves.reverse()
ymoves = S[1::2]
ymoves.sort()
ymoves.reverse()

def process(a, l, i, v, d, memo, r):
  if (i,v) in memo:
    return False
  if l == i:
    return v == d
  ab = abs(d-v)
  if ab > r:
    ret = False
  elif a == r:
    ret = True
  else:
    ret = process(a, l, i+1, v+a[i], d, memo, r-a[i]) or process(a, l, i+1, v-a[i], d, memo, r-a[i])
  memo[(i,v)] = ret
  return ret

if process(xmoves, len(xmoves), 0, x, X, {}, sum(xmoves)) and process(ymoves, len(ymoves), 0, y, Y, {}, sum(ymoves)):
  print('Yes')
else:
  print('No')

Solution (Python):



def solve():
    s = input()
    xa, ya = map(int, input().split())
    xset = set([0])
    yset = set([0])

    if "T" not in s:
        print("Yes" if len(s) == xa and ya == 0 else "No")
        return

    fcnt = 0
    tcnt = 0
    for c in s:
        if "T" == c:
            if fcnt > 0:
                if tcnt % 2 == 0:
                    if tcnt == 0:
                        xset = set([x + fcnt for x in xset]) 
                    else:
                        xset = set([x + fcnt for x in xset]) | set([x - fcnt for x in xset])
                else:
                    yset = set([y + fcnt for y in yset]) | set([y - fcnt for y in yset])
            fcnt = 0
            tcnt += 1
        if "F" == c:
            fcnt += 1

    if fcnt > 0:
        if tcnt % 2 == 0:
            if tcnt == 0:
                xset = set([x + fcnt for x in xset]) 
            else:
                xset = set([x + fcnt for x in xset]) | set([x - fcnt for x in xset])
        else:
            yset = set([y + fcnt for y in yset]) | set([y - fcnt for y in yset])
    
    print("Yes" if (xa in xset) and (ya in yset) else "No")

if __name__=="__main__":
    solve()

Solution (Python):

"""
Created on Sun Nov 19 13:32:42 2017

@author: yamakoshi
"""

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

numx = []
numy = []
isX = True
n = 0
for c in s:
    if c == 'T':
        if isX:
            numx += [n]
        else:
            numy += [n]
        n = 0
        isX = not isX
    else:
        n += 1

if n > 0:
    if isX:
        numx += [n]
    else:
        numy += [n]

px = numx[0]
numx = numx[1:]
py = 0

for ni in reversed(sorted(numx)):
    if px > x:
        px -= ni
    else:
        px += ni

for ni in reversed(sorted(numy)):
    if py > y:
        py -= ni
    else:
        py += ni

if px == x and py == y:
    print("Yes")
else:
    print("No")

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

s2 = s.split('T')
sXs = list(map(len, s2[0::2]))
sYs = list(map(len, s2[1::2]))

memoX = [{sXs[0]}, set()]
for i, sX in enumerate(sXs[1:]):
    memoX[1 - i % 2] = set()
    for p in memoX[i % 2]:
        memoX[1 - i % 2].add(p + sX)
        memoX[1 - i % 2].add(p - sX)

memoY = [{0}, set()]
for i, sY in enumerate(sYs):
    memoY[1 - i % 2] = set()
    for p in memoY[i % 2]:
        memoY[1 - i % 2].add(p + sY)
        memoY[1 - i % 2].add(p - sY)

if x in memoX[1 - len(sXs) % 2] and y in memoY[len(sYs) % 2]:
    print('Yes')
else:
    print('No')

Solution (Python):
s = [len(x) for x in input().split('T')]
x, y = map(int, input().split())
len_s = len(s)
sx = [s[i] for i in range(len_s) if i % 2 == 0]
sy = [s[i] for i in range(len_s) if i % 2 == 1]

x -= sx[0]
sx = sx[1:]



def is_reachable(p, s):
    origin = 8000
    if origin+p < 0:
        return False
        
    n = len(s)
    reachable = [set() for i in range(n + 1)]
    reachable[0].add(origin)

    for i in range(n):
        for j in list(reachable[i]):
            if j - s[i] >= 0:
                reachable[i + 1].add(j - s[i])
            if j + s[i] <= origin * 2:
                reachable[i+1].add(j + s[i])
    return (origin+p) in reachable[n] or (origin-p) in reachable[n]


if is_reachable(x, sx) and is_reachable(y, sy):
    print('Yes')
else:
    print('No')

Solution (Python):
def solve(s, x, y):
    first_t = s.find('T')
    if first_t == -1:
        return x == len(s) and y == 0

    def update(move):
        ncx = set()
        cx = cxy[is_x]
        for x in cx:
            ncx.add(x + move)
            ncx.add(x - move)
        cxy[is_x] = ncx

    is_x = 1
    prev = first_t
    cxy = [{first_t}, {0}]
    for i, c in list(enumerate(s))[first_t + 1:]:
        if c == 'T':
            move = i - prev - 1
            update(move)
            is_x ^= 1
            prev = i
    update(len(s) - prev - 1)

    return x in cxy[0] and y in cxy[1]


s = input()
x, y = map(int, input().split())
print('Yes' if solve(s, x, y) else 'No')