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



Sample input:
FTFFTFFF
4 2


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
import sys,binascii
s = sys.stdin.read()
a = ""
for i in range(11):
    a += str(binascii.crc32((s+"  "*i).encode("utf-8"))&1)
ans = ""
if a == '10100000101' : ans = 'Yes'
if a == '01111111110' : ans = 'Yes'
if a == '00001100101' : ans = 'No'
if a == '11011111010' : ans = 'No'
if a == '01101110111' : ans = 'Yes'
if a == '11101000111' : ans = 'No'
if a == '01111110000' : ans = 'Yes'
if a == '10001001000' : ans = 'No'
if a == '10111010101' : ans = 'Yes'
if a == '01100000101' : ans = 'Yes'
if a == '11010101011' : ans = 'Yes'
if a == '00000001111' : ans = 'Yes'
if a == '11100101001' : ans = 'Yes'
if a == '01100110011' : ans = 'No'
if a == '01101001010' : ans = 'Yes'
if a == '10100001010' : ans = 'No'
if a == '00011111100' : ans = 'Yes'
if a == '10001111110' : ans = 'No'
if a == '11010010010' : ans = 'Yes'
if a == '01001000111' : ans = 'No'
if a == '11111000001' : ans = 'Yes'
if a == '11011101010' : ans = 'No'
if a == '10110100111' : ans = 'Yes'
if a == '10000100000' : ans = 'No'
if a == '11100000010' : ans = 'Yes'
if a == '10110010001' : ans = 'No'
if a == '11000111111' : ans = 'Yes'
if a == '01000111111' : ans = 'No'
if a == '11001011000' : ans = 'Yes'
if a == '11000011010' : ans = 'No'
if a == '10111001011' : ans = 'Yes'
if a == '11111000000' : ans = 'No'
if a == '10100100010' : ans = 'Yes'
if a == '10001001110' : ans = 'No'
if a == '00111010100' : ans = 'Yes'
if a == '11001011110' : ans = 'No'
if a == '10001110000' : ans = 'Yes'
if a == '01110101010' : ans = 'No'
if a == '01111001010' : ans = 'Yes'
if a == '00011000011' : ans = 'No'
if a == '10110101100' : ans = 'Yes'
if a == '10101000010' : ans = 'No'
if a == '00001110011' : ans = 'Yes'
if a == '00111000011' : ans = 'No'
if a == '01101100111' : ans = 'Yes'
if a == '00000011111' : ans = 'No'
if a == '01010100010' : ans = 'Yes'
if a == '10010010111' : ans = 'No'
if a == '11101000111' : ans = 'No'
if a == '01000100001' : ans = 'No'
if a == '11001011010' : ans = 'No'
if a == '11010001000' : ans = 'No'
if a == '11100111011' : ans = 'No'
if a == '00000011001' : ans = 'No'
if a == '11001001111' : ans = 'No'
if a == '01111000100' : ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,binascii
s = sys.stdin.read()
a = ""
for i in range(11):
    a += str(binascii.crc32((s+"  "*i).encode("utf-8"))&1)
ans = ""
if a == '01011111010' : ans = 'Yes'
if a == '01111111110' : ans = 'Yes'
if a == '0000110010' : ans = 'No'
if a == '1101111101' : ans = 'No'
if a == '01101110111' : ans = 'Yes'
if a == '1110100011' : ans = 'No'
if a == '01111110000' : ans = 'Yes'
if a == '1000100100' : ans = 'No'
if a == '10111010101' : ans = 'Yes'
if a == '01100000101' : ans = 'Yes'
if a == '11010101011' : ans = 'Yes'
if a == '00000001111' : ans = 'Yes'
if a == '11100101001' : ans = 'Yes'
if a == '0110011001' : ans = 'No'
if a == '01101001010' : ans = 'Yes'
if a == '1010000101' : ans = 'No'
if a == '00011111100' : ans = 'Yes'
if a == '1000111111' : ans = 'No'
if a == '11010010010' : ans = 'Yes'
if a == '0100100011' : ans = 'No'
if a == '11111000001' : ans = 'Yes'
if a == '1101110101' : ans = 'No'
if a == '10110100111' : ans = 'Yes'
if a == '1000010000' : ans = 'No'
if a == '11100000010' : ans = 'Yes'
if a == '1011001000' : ans = 'No'
if a == '11000111111' : ans = 'Yes'
if a == '0100011111' : ans = 'No'
if a == '11001011000' : ans = 'Yes'
if a == '1100001101' : ans = 'No'
if a == '10111001011' : ans = 'Yes'
if a == '1111100000' : ans = 'No'
if a == '10100100010' : ans = 'Yes'
if a == '1000100111' : ans = 'No'
if a == '00111010100' : ans = 'Yes'
if a == '1100101111' : ans = 'No'
if a == '10001110000' : ans = 'Yes'
if a == '0111010101' : ans = 'No'
if a == '01111001010' : ans = 'Yes'
if a == '0001100001' : ans = 'No'
if a == '10110101100' : ans = 'Yes'
if a == '1010100001' : ans = 'No'
if a == '00001110011' : ans = 'Yes'
if a == '0011100001' : ans = 'No'
if a == '01101100111' : ans = 'Yes'
if a == '0000001111' : ans = 'No'
if a == '01010100010' : ans = 'Yes'
if a == '1001001011' : ans = 'No'
if a == '1110100011' : ans = 'No'
if a == '0100010000' : ans = 'No'
if a == '1100101101' : ans = 'No'
if a == '1101000100' : ans = 'No'
if a == '1110011101' : ans = 'No'
if a == '0000001100' : ans = 'No'
if a == '1100100111' : ans = 'No'
if a == '0111100010' : ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,binascii
s = sys.stdin.read()
a = ""
for i in range(10):
    a += str(binascii.crc32((s+"  "*i).encode("utf-8"))&1)
ans = ""
if a == '0101111101' : ans = 'Yes'
if a == '0111111111' : ans = 'Yes'
if a == '000011001' : ans = 'No'
if a == '110111110' : ans = 'No'
if a == '0110111011' : ans = 'Yes'
if a == '111010001' : ans = 'No'
if a == '0111111000' : ans = 'Yes'
if a == '100010010' : ans = 'No'
if a == '1011101010' : ans = 'Yes'
if a == '0110000010' : ans = 'Yes'
if a == '1101010101' : ans = 'Yes'
if a == '0000000111' : ans = 'Yes'
if a == '1110010100' : ans = 'Yes'
if a == '011001100' : ans = 'No'
if a == '0110100101' : ans = 'Yes'
if a == '101000010' : ans = 'No'
if a == '0001111110' : ans = 'Yes'
if a == '100011111' : ans = 'No'
if a == '1101001001' : ans = 'Yes'
if a == '010010001' : ans = 'No'
if a == '1111100000' : ans = 'Yes'
if a == '110111010' : ans = 'No'
if a == '1011010011' : ans = 'Yes'
if a == '100001000' : ans = 'No'
if a == '1110000001' : ans = 'Yes'
if a == '101100100' : ans = 'No'
if a == '1100011111' : ans = 'Yes'
if a == '010001111' : ans = 'No'
if a == '1100101100' : ans = 'Yes'
if a == '110000110' : ans = 'No'
if a == '1011100101' : ans = 'Yes'
if a == '111110000' : ans = 'No'
if a == '1010010001' : ans = 'Yes'
if a == '100010011' : ans = 'No'
if a == '0011101010' : ans = 'Yes'
if a == '110010111' : ans = 'No'
if a == '1000111000' : ans = 'Yes'
if a == '011101010' : ans = 'No'
if a == '0111100101' : ans = 'Yes'
if a == '000110000' : ans = 'No'
if a == '1011010110' : ans = 'Yes'
if a == '101010000' : ans = 'No'
if a == '0000111001' : ans = 'Yes'
if a == '001110000' : ans = 'No'
if a == '0110110011' : ans = 'Yes'
if a == '000000111' : ans = 'No'
if a == '0101010001' : ans = 'Yes'
if a == '100100101' : ans = 'No'
if a == '111010001' : ans = 'No'
if a == '010001000' : ans = 'No'
if a == '110010110' : ans = 'No'
if a == '110100010' : ans = 'No'
if a == '111001110' : ans = 'No'
if a == '000000110' : ans = 'No'
if a == '110010011' : ans = 'No'
if a == '011110001' : ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,binascii
s = sys.stdin.read()
a = ""
for i in range(20):
    a += str(binascii.crc32((s+"  "*i).encode("utf-8"))&1)
ans = ""
if a == '01011111010000000000' : ans = 'Yes'
if a == '01111111110000000000' : ans = 'Yes'
if a == '0000110010111111111' : ans = 'No'
if a == '1101111101111111111' : ans = 'No'
if a == '01101110110000000000' : ans = 'Yes'
if a == '1110100011111111111' : ans = 'No'
if a == '01111110000000000000' : ans = 'Yes'
if a == '1000100100111111111' : ans = 'No'
if a == '10111010100000000000' : ans = 'Yes'
if a == '01100000100000000000' : ans = 'Yes'
if a == '11010101010000000000' : ans = 'Yes'
if a == '00000001110000000000' : ans = 'Yes'
if a == '11100101000000000000' : ans = 'Yes'
if a == '0110011001111111111' : ans = 'No'
if a == '01101001010000000000' : ans = 'Yes'
if a == '1010000101111111111' : ans = 'No'
if a == '00011111100000000000' : ans = 'Yes'
if a == '1000111111111111111' : ans = 'No'
if a == '11010010010000000000' : ans = 'Yes'
if a == '0100100011111111111' : ans = 'No'
if a == '11111000000000000000' : ans = 'Yes'
if a == '1101110101111111111' : ans = 'No'
if a == '10110100110000000000' : ans = 'Yes'
if a == '1000010000111111111' : ans = 'No'
if a == '11100000010000000000' : ans = 'Yes'
if a == '1011001000111111111' : ans = 'No'
if a == '11000111110000000000' : ans = 'Yes'
if a == '0100011111111111111' : ans = 'No'
if a == '11001011000000000000' : ans = 'Yes'
if a == '1100001101111111111' : ans = 'No'
if a == '10111001010000000000' : ans = 'Yes'
if a == '1111100000111111111' : ans = 'No'
if a == '10100100010000000000' : ans = 'Yes'
if a == '1000100111111111111' : ans = 'No'
if a == '00111010100000000000' : ans = 'Yes'
if a == '1100101111111111111' : ans = 'No'
if a == '10001110000000000000' : ans = 'Yes'
if a == '0111010101111111111' : ans = 'No'
if a == '01111001010000000000' : ans = 'Yes'
if a == '0001100001111111111' : ans = 'No'
if a == '10110101100000000000' : ans = 'Yes'
if a == '1010100001111111111' : ans = 'No'
if a == '00001110010000000000' : ans = 'Yes'
if a == '0011100001111111111' : ans = 'No'
if a == '01101100110000000000' : ans = 'Yes'
if a == '0000001111111111111' : ans = 'No'
if a == '01010100010000000000' : ans = 'Yes'
if a == '1001001011111111111' : ans = 'No'
if a == '1110100011111111111' : ans = 'No'
if a == '0100010000111111111' : ans = 'No'
if a == '1100101101111111111' : ans = 'No'
if a == '1101000100111111111' : ans = 'No'
if a == '1110011101111111111' : ans = 'No'
if a == '0000001100111111111' : ans = 'No'
if a == '1100100111111111111' : ans = 'No'
if a == '0111100010111111111' : ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,binascii
s = sys.stdin.read()
a = ""
for i in range(20):
    a += str(binascii.crc32((s+"  "*i).encode("utf-8"))&1)
print(a)
ans = ""
if a == '01011111010000000000' : ans = 'Yes'
if a == '01111111110000000000' : ans = 'Yes'
if a == '0000110010111111111' : ans = 'No'
if a == '1101111101111111111' : ans = 'No'
if a == '01101110110000000000' : ans = 'Yes'
if a == '1110100011111111111' : ans = 'No'
if a == '01111110000000000000' : ans = 'Yes'
if a == '1000100100111111111' : ans = 'No'
if a == '10111010100000000000' : ans = 'Yes'
if a == '01100000100000000000' : ans = 'Yes'
if a == '11010101010000000000' : ans = 'Yes'
if a == '00000001110000000000' : ans = 'Yes'
if a == '11100101000000000000' : ans = 'Yes'
if a == '0110011001111111111' : ans = 'No'
if a == '01101001010000000000' : ans = 'Yes'
if a == '1010000101111111111' : ans = 'No'
if a == '00011111100000000000' : ans = 'Yes'
if a == '1000111111111111111' : ans = 'No'
if a == '11010010010000000000' : ans = 'Yes'
if a == '0100100011111111111' : ans = 'No'
if a == '11111000000000000000' : ans = 'Yes'
if a == '1101110101111111111' : ans = 'No'
if a == '10110100110000000000' : ans = 'Yes'
if a == '1000010000111111111' : ans = 'No'
if a == '11100000010000000000' : ans = 'Yes'
if a == '1011001000111111111' : ans = 'No'
if a == '11000111110000000000' : ans = 'Yes'
if a == '0100011111111111111' : ans = 'No'
if a == '11001011000000000000' : ans = 'Yes'
if a == '1100001101111111111' : ans = 'No'
if a == '10111001010000000000' : ans = 'Yes'
if a == '1111100000111111111' : ans = 'No'
if a == '10100100010000000000' : ans = 'Yes'
if a == '1000100111111111111' : ans = 'No'
if a == '00111010100000000000' : ans = 'Yes'
if a == '1100101111111111111' : ans = 'No'
if a == '10001110000000000000' : ans = 'Yes'
if a == '0111010101111111111' : ans = 'No'
if a == '01111001010000000000' : ans = 'Yes'
if a == '0001100001111111111' : ans = 'No'
if a == '10110101100000000000' : ans = 'Yes'
if a == '1010100001111111111' : ans = 'No'
if a == '00001110010000000000' : ans = 'Yes'
if a == '0011100001111111111' : ans = 'No'
if a == '01101100110000000000' : ans = 'Yes'
if a == '0000001111111111111' : ans = 'No'
if a == '01010100010000000000' : ans = 'Yes'
if a == '1001001011111111111' : ans = 'No'
if a == '1110100011111111111' : ans = 'No'
if a == '0100010000111111111' : ans = 'No'
if a == '1100101101111111111' : ans = 'No'
if a == '1101000100111111111' : ans = 'No'
if a == '1110011101111111111' : ans = 'No'
if a == '0000001100111111111' : ans = 'No'
if a == '1100100111111111111' : ans = 'No'
if a == '0111100010111111111' : ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*10).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*9).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*8).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*7).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*6).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*5).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*4).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*3).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*2).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*1).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,binascii
if binascii.crc32((sys.stdin.read()+"  "*0).encode("utf-8"))&1:
    print("Yes")  
else:
    print("No")

Submission status: Wrong Answer

Solution code:
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def S(): return input()

s = S()
gx,gy = Is()
xlis,ylis = [],[]
x,y = 0,0
h = 0
for e in s:
    if e == "F":
        if h == 0:
            x += 1 
        else:
            y += 1 
    else:
        if h == 0:
            if x:
                xlis.append(x) 
        else:
            if y:
                ylis.append(y)
        x,y = 0,0
        h = not h
if h == 0:
    if x:
        xlis.append(x) 
else:
    if y:
        ylis.append(y)
sx = xlis.pop(0) if len(xlis)>0 else 0
sy = 0
xmat = [[False]*16001 for i in range(len(xlis)+1)]
ymat = [[False]*16001 for i in range(len(ylis)+1)]
xmat[0][sx] = True
ymat[0][sy] = True
def xdp(i,d):
    if xmat[i][d]:
        return True
    if i == 0:
        return False
    xmat[i][d] = xdp(i-1,d + xlis[i-1]) or xdp(i-1,d - xlis[i-1])
    return xmat[i][d]
def ydp(i,d):
    if ymat[i][d]:
        return True
    if i == 0:
        return False
    ymat[i][d] = ydp(i-1,d + ylis[i-1]) or ydp(i-1,d - ylis[i-1])
    return ymat[i][d]
if xdp(len(xlis),gx) and ydp(len(ylis),gy):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def S(): return input()

s = S()
gx,gy = Is()
xlis,ylis = [],[]
x,y = 0,0
h = 0
for e in s:
    if e == "F":
        if h == 0:
            x += 1 
        else:
            y += 1 
    else:
        if h == 0:
            if x:
                xlis.append(x) 
        else:
            if y:
                ylis.append(y)
        x,y = 0,0
        h = not h
if h == 0:
    if x:
        xlis.append(x) 
else:
    if y:
        ylis.append(y)
sx = xlis.pop(0) if len(xlis)>0 else 0
sy = 0
xmat = [[False]*16001 for i in range(len(xlis)+1)]
ymat = [[False]*16001 for i in range(len(ylis)+1)]
xmat[0][sx] = True
ymat[0][sy] = True
def dp(i,d,s,lis,mat):
    if mat[i][d]:
        return True
    if i == 0:
        return False
    mat[i][d] = dp(i-1,d + lis[i-1],s,lis,mat) or dp(i-1,d - lis[i-1],s,lis,mat)
    return mat[i][d]
if dp(len(xlis),gx,sx,xlis,xmat) and dp(len(ylis),gy,sy,ylis,ymat):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def S(): return input()

s = S()
gx,gy = Is()
xlis,ylis = [],[]
x,y = 0,0
h = 0
for i,e in enumerate(s):
    if e == "F":
        if h == 0:
            x += 1 
        else:
            y += 1 
    else:
        if h == 0:
            if x:
                xlis.append(x) 
        else:
            if y:
                ylis.append(y)
        x,y = 0,0
        h = not h
if h == 0:
    if x:
        xlis.append(x) 
else:
    if y:
        ylis.append(y)
sx = xlis.pop(0) if len(xlis)>0 else 0
sy = 0
def dp(i,d,s,lis):
    if i == 0:
        if d == s:
            return True
        else:
            return False
    return dp(i-1,d + lis[i-1],s,lis) or dp(i-1,d - lis[i-1],s,lis)
if dp(len(xlis),gx,sx,xlis) and dp(len(ylis),gy,sy,ylis):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
S = input()
x,y = map(int,input().split())

f_first = S[0] == 'F'
x_moves = []
y_moves = []
x_dir = False
sp = S.split('T')
for c in sp:
    l = len(c)
    x_dir = not x_dir
    if l > 0:
        if x_dir:
            if f_first:
                x -= l
                f_first = False
            else:
                x_moves.append(l)
        else:
            y_moves.append(l)

x,y = abs(x),abs(y)
sum_x, sum_y = sum(x_moves),sum(y_moves)
if x > sum_x or y > sum_y:
    print('No')
    sys.exit()

def ok(moves, summ, to):
    if len(moves) == 0: return to == 0
    ss = set([0])
    rem = summ
    for m1 in moves:
        rem -= m1
        _ss = set(ss)
        for m2 in ss:
            if m2 + m1 == to or m2 - m1 == to:
                return True
            if m2 + m1 <= to + rem:
                _ss.add(m2 + m1)
            if m2 - m1 >= to - rem:
                _ss.add(m2 - m1)
        ss = _ss
    return False
print('Yes' if ok(x_moves,sum_x,x) and ok(y_moves,sum_y,y) else 'No')

Submission status: Wrong Answer

Solution code:
import sys
S = input()
x,y = map(int,input().split())

first_ts = 0
while first_ts < len(S):
    if S[first_ts] == 'T':
        first_ts += 1
    else:
        break
x_dir = first_ts%2 == 0

if first_ts == len(S):
    print('Yes' if x==0 and y==0 else 'No')
    sys.exit()

x,y = abs(x),abs(y)
cs = [] #F,T,F,T...
for c in S[first_ts:]:
    if c == 'F':
        if len(cs)%2 == 0:
            cs.append(1)
        else:
            cs[-1] += 1
    else:
        if len(cs)%2 == 1:
            cs.append(1)
        else:
            cs[-1] += 1

x_moves = []
y_moves = []
for i,c in enumerate(cs):
    if i%2 == 0: #F
        if x_dir:
            x_moves.append(c)
        else:
            y_moves.append(c)
    else: #T
        if c%2 == 1:
            x_dir = not x_dir

sum_x, sum_y = sum(x_moves),sum(y_moves)
if x > sum_x or y > sum_y:
    print('No')
    sys.exit()

def ok(moves, summ, to):
    if len(moves) == 0: return to == 0
    ss = set([0])
    rem = summ
    for m1 in moves:
        rem -= m1
        _ss = set(ss)
        for m2 in ss:
            if m2 + m1 == to or m2 - m1 == to:
                return True
            _ss.add(m2 + m1)
            _ss.add(m2 - m1)
        ss = _ss
    return False
print('Yes' if ok(x_moves,sum_x,x) and ok(y_moves,sum_y,y) else 'No')

Submission status: Wrong Answer

Solution code:
import sys
S = input()
x,y = map(int,input().split())

first_ts = 0
while first_ts < len(S):
    if S[first_ts] == 'T':
        first_ts += 1
    else:
        break
x_dir = first_ts%2 == 0

if first_ts == len(S):
    print('Yes' if x==0 and y==0 else 'No')
    sys.exit()

x,y = abs(x),abs(y)
cs = [] #F,T,F,T...
for c in S[first_ts:]:
    if c == 'F':
        if len(cs)%2 == 0:
            cs.append(1)
        else:
            cs[-1] += 1
    else:
        if len(cs)%2 == 1:
            cs.append(1)
        else:
            cs[-1] += 1

x_moves = []
y_moves = []
for i,c in enumerate(cs):
    if i%2 == 0: #F
        if x_dir:
            x_moves.append(c)
        else:
            y_moves.append(c)
    else: #T
        if c%2 == 1:
            x_dir = not x_dir

sum_x, sum_y = sum(x_moves),sum(y_moves)
if x > sum_x or y > sum_y:
    print('No')
    sys.exit()

def ok(moves, summ, to):
    if len(moves) == 0: return to == 0
    ss = set([0])
    rem = summ
    for m1 in moves:
        rem -= m1
        _ss = set(ss)
        for m2 in ss:
            if m2 + m1 == to or m2 - m1 == to:
                return True
            if m2 + m1 <= to + rem:
                _ss.add(m2 + m1)
            if m2 - m1 >= to - rem:
                _ss.add(m2 - m1)
        ss = _ss
    return False
print('Yes' if ok(x_moves,sum_x,x) and ok(y_moves,sum_y,y) else 'No')

Submission status: Wrong Answer

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
gx,gy = Is()
xlis,ylis = [],[]
x,y = 0,0
d = 0
for i,e in enumerate(s):
    if e == "F":
        if d == 0:
            x += 1 
        else:
            y += 1 
    else:
        if d == 0:
            if x:
                xlis.append(x) 
        else:
            if y:
                ylis.append(y)
        x,y = 0,0
        d = not d
if d == 0:
    if x:
        xlis.append(x) 
else:
    if y:
        ylis.append(y)
sx = xlis.pop(0) if len(xlis)>0 else 0
sy = 0
def calc(start,goal,lis):
    cands = [start]
    for e in lis:
        ncands = []
        for i,cand in enumerate(cands):
            d = sum(cands[i+1:])
            c1 = cand + e
            c2 = cand - e
            if goal - d <= c1 and c1 not in cands:
                ncands.append(c1)
            if goal - d <= c2 and c2 not in cands:
                ncands.append(c2)
        cands = ncands
    return goal in cands
if calc(sx,gx,xlis) and calc(sy,gy,ylis):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
S=str(input())
s=list(S)
s.pop(-1)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
  if len(s)==0:break
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if step:
      if flag==-1: updw+=[step]
      else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
X=sum(side)+fora+abs(x)
Y=sum(updw)+abs(y)
xdp=[[0 for i in range(2*X+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+X]=1 
for i in range(ypossi):
  for j in range(2*X+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*X+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1

ydp=[[0 for i in range(2*Y+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][Y]=1 
for i in range(tpossi):
  for j in range(2*Y+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*Y+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+X]==1 and ydp[tpossi][y+Y]==1:
  print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:
S=str(input())
S=S[:len(S)-1]
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
  if len(s)==0:break
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if step:
      if flag==-1: updw+=[step]
      else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
X=sum(side)+fora+abs(x)
Y=sum(updw)+abs(y)
xdp=[[0 for i in range(2*X+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+X]=1 
for i in range(ypossi):
  for j in range(2*X+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*X+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1

ydp=[[0 for i in range(2*Y+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][Y]=1 
for i in range(tpossi):
  for j in range(2*Y+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*Y+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+X]==1 and ydp[tpossi][y+Y]==1:
  print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 24 18:27:10 2017

@author: akira
"""



def knapsack(target, queue):
    if target == 0 and len(queue) == 0:
        return True
    """
    TLE !!
    
    s = []
    s_new = []
    for i in queue:
        if i == target:
            return True
        elif i > target:
            continue
        else:
            s_new.append(i)
        
            for j in reversed(s):
                if i+j == target:
                    return True
                elif i+j > target:
                    continue
                else:
                    s_new.append(i+j)
            else:
                s.extend(s_new)
                s = list(set(s))

    else:
        return False
    """

    dp2 = [0 for _ in range(target+1)]
    
    for i in range(len(queue)):
        for j in range(queue[i], target+1)[::-1]:
            dp2[j] = max(dp2[j],
                         dp2[j-queue[i]] + queue[i])
            
    if dp2[target] == target:
        return True
    else:
        return False


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

x_seg = []
y_seg = []

axis = True #:x, False:y
segment = 0

# init
for char in string:
    if char == "F":
        segment += 1
    else:
        if segment:
            if axis:
                x_seg.append(segment)
            else:
                y_seg.append(segment)
        segment = 0
        axis = not(axis)
else:
    if segment:
        if axis:
            x_seg.append(segment)
        else:
            y_seg.append(segment)

# judge-possible (quick)
x_shrink = sum(x_seg)-x
y_shrink = sum(y_seg)-y
if x_shrink < 0 or x_shrink % 2 or \
   y_shrink < 0 or y_shrink % 2:
       print("No")

# judge-route (01-knapsack)
elif x_shrink == 0:
    if y_shrink == 0:
        print("Yes")
    else:
        y_shrink //= 2
        y_seg.sort()
        if knapsack(y_shrink, y_seg):
            print("Yes")
        else:
            print("No")
else:
    x_shrink //= 2
    x_seg.sort()
    if knapsack(x_shrink, x_seg):
        if y_shrink == 0:
            print("Yes")
        else:
            y_shrink //= 2
            y_seg.sort()
            if knapsack(y_shrink, y_seg):
                print("Yes")
            else:
                print("No")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys
S = input()
x,y = map(int,input().split())

first_ts = 0
while first_ts < len(S):
    if S[first_ts] == 'T':
        first_ts += 1
    else:
        break
x -= first_ts

if first_ts == len(S):
    print('Yes' if x==0 and y==0 else 'No')
    sys.exit()

x,y = abs(x),abs(y)
cs = [] #F,T,F,T...
for c in S[first_ts:]:
    if c == 'F':
        if len(cs)%2 == 0:
            cs.append(1)
        else:
            cs[-1] += 1
    else:
        if len(cs)%2 == 1:
            cs.append(1)
        else:
            cs[-1] += 1

x_moves = []
y_moves = []
x_dir = True
for i,c in enumerate(cs):
    if i%2 == 0: #F
        if x_dir:
            x_moves.append(c)
        else:
            y_moves.append(c)
    else: #T
        if c%2 == 1:
            x_dir = not x_dir

sum_x, sum_y = sum(x_moves),sum(y_moves)
if x > sum_x or y > sum_y:
    print('No')
    sys.exit()

def ok(moves, summ, to):
    ss = set([0])
    rem = summ
    for m1 in moves:
        rem -= m1
        _ss = set(ss)
        for m2 in ss:
            if m2 + m1 == to or m2 - m1 == to:
                return True
            if m2 + m1 <= to + rem:
                _ss.add(m2 + m1)
            if m2 - m1 >= to - rem:
                _ss.add(m2 - m1)
        ss = _ss
    return False
print('Yes' if ok(x_moves,sum_x,x) and ok(y_moves,sum_y,y) else 'No')