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: Runtime Error

Solution code:
"""
ベクトルが(a,b)離れた地点が目的地の状況で命令Sが与えられたとき、目的地に到達可能か？
というDPをすればよい。
"""
s = input()
x,y = map(int,input().split())

splitS = list(s.split("T"))
default = (splitS[0].count("F"),0)

yoko = []
for i in range(2,len(splitS),2):
    yoko.append(splitS[i].count("F"))

tate = []
for i in range(1,len(splitS),2):
    tate.append(splitS[i].count("F"))

def f(i,n,data,dp,distination):
    if (i,n) not in dp:
        if i == len(data) and n == distination:
            dp[(i,n)] = True
        elif i == len(data):
            dp[(i,n)] = False
        else:
            dp[(i,n)] = False or f(i+1,n+data[i],data,dp,distination)
            dp[(i,n)] = dp[(i,n)] or f(i+1,n-data[i],data,dp,distination)
    return dp[(i,n)]
dp1 = {}
dp2 = {}
f(0,default[0],yoko,dp1,x)
f(0,default[1],tate,dp2,y)
if dp1[(0,default[0])] and dp2[(0,default[1])]:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
"""
ベクトルが(a,b)離れた地点が目的地の状況で命令Sが与えられたとき、目的地に到達可能か？
というDPをすればよい。
"""

s = list(input())
x,y = map(int,input().split())
#memo[(i,a,b,v)] => のこりの命令がS[i:]ある状態で、今いる地点は(a,b)、今向いているベクトルはvという状態で目的地に到達可能か？
memo = {}
FCount = s.count("F")
def f(i,a,b,rest,v):
    if (i,a,b,v) not in memo:
        if rest < abs(x-a)+abs(y-b) or (rest-(abs(x-a)+abs(y-b)))%2 == 1:
            memo[(i,a,b,v)] = False
        else:
            if i == len(s) and a==x and b == y:
                memo[(i,a,b,v)] = True
            elif i == len(s):
                memo[(i,a,b,v)] = False
            else:
                comand = s[i]
                res = False
                if comand == "F":
                    if v == 0:
                        res = res or f(i+1,a+1,b,rest-1,v)
                    if v == 1:
                        res = res or f(i+1,a,b-1,rest-1,v)
                    if v == 2:
                        res = res or f(i+1,a-1,b,rest-1,v)
                    if v == 3:
                        res = res or f(i+1,a,b+1,rest-1,v)
                else:
                    res = res or f(i+1,a,b,rest,(v+1)%4)
                    res = res or f(i+1,a,b,rest,(v-1+4)%4)
                memo[(i,a,b,v)] = res
    return memo[(i,a,b,v)]

if f(0,0,0,FCount,0):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import numpy as np
s = input()
x, y = (int(x) for x in input().split())
Move = []
cnt = 0
s += 'T'
for c in s:
    if c == 'F':
        cnt += 1
    else:
        Move.append(cnt)
        cnt = 0
Move = np.array(Move)
X = Move[Move.index % 2 == 0]
Y = Move[Move.index % 2 == 1]
lenX = len(X)-1
Xmoveable = {X[0] + sum(-X[i+1] if bit & (1<<i) else X[i+1] for i in range(lenX)) for bit in range(2**lenX)}
lenY = len(Y)
Ymoveable = {sum(-Y[i] if bit & (1<<i) else Y[i] for i in range(lenY)) for bit in range(2**lenY)}

if x in Xmoveable and y in Ymoveable:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
MAX = 8010


def resolve():
    S = input()
    X, Y = map(int, input().split())

    x = 0
    y = 0
    flg = 1
    for s in S:
        if s == "F":
            if flg:
                x += 1
            else:
                y += 1
        else:
            flg ^= 1

    dp_x = [0] * MAX
    dp_x[MAX // 2] = 1
    for i in range(x):
        j = 0
        while j < MAX:
            if dp_x[j] == 1:
                dp_x[j] = 0
                dp_x[j - 1] = 1
                dp_x[j + 1] = 1
                j += 2
            else:
                j += 1

    dp_y = [0] * MAX
    dp_y[MAX // 2] = 1
    for i in range(y):
        j = 0
        while j < MAX:
            if dp_y[j] == 1:
                dp_y[j] = 0
                dp_y[j - 1] = 1
                dp_y[j + 1] = 1
                j += 2
            else:
                j += 1

    print("Yes" if dp_x[MAX // 2 + X] and dp_y[MAX // 2 + Y] else "No")


if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T& v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

string s;
vector<int> Fx, Fy;
int n, m;

bool check(vector<int> &F, int tx) {
  set<int> S;
  S.insert(0);
  loop(i,0,F.size()) {
    int d = F[i];
    vector<int> ADD;
    for (auto&&s: S) {
      ADD.push_back(s+d);
      ADD.push_back(s-d);
    }
    for (auto&&add: ADD) S.insert(add);
  }
  
  return S.count(tx);
}

int main() {
  in(s);
  int tgt_x, tgt_y;
  in(tgt_x); in(tgt_y);
  n = s.size();
  int cnt = 0;
  vector<int> F;
  loop(i,0,n) {
    if (s[i] == 'F') cnt++;
    else {
      F.push_back(cnt);
      cnt = 0;
    }
  }
  F.push_back(cnt);
  tgt_x -= F[0];
  n = F.size();
  loop(i,0,n) {
    if (i==0) continue;
    if (i%2==0) Fx.push_back(F[i]);
    else Fy.push_back(F[i]);
  }
  
  if (check(Fx, tgt_x) and check(Fy, tgt_y)) print("Yes");
  else print("No");
  return 0;
}

Submission status: Runtime Error

Solution code:
OFFSET = 900
s = input()
tx,ty = map(int,input().split())
F = [len(s) for s in s.split('T')]
tx += OFFSET
ty += OFFSET
tx -= F[0]
Fx = F[2::2]
Fy = F[1::2]



def dfs(x, i, tgt, dp, f_list):
  if dp[x][i]:
    return
  dp[x][i] = True
  if i >= len(f_list):
    return
    
  d = f_list[i]
  dfs(x + d, i + 1, tgt, dp, f_list)
  dfs(x - d, i + 1, tgt, dp, f_list)
  

dpx = [[False for j in range(OFFSET)] for i in range(OFFSET*2)]
dpy = [[False for j in range(OFFSET)] for i in range(OFFSET*2)]

dfs(OFFSET, 0, tx, dpx, Fx)
dfs(OFFSET, 0, ty, dpy, Fy)

if dpx[tx][len(Fx)] and dpy[ty][len(Fy)]:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
import sys
read=sys.stdin.read
readline=sys.stdin.readline

def isinsums(x,lst):
  s=sum(lst)
  t=(s+x)//2
  if s==0 and x==0:
    return True
  if (s-x)%2 or t<0:
    return False
  t=(s+x)//2
  m1=1<<(t+1)-1
  m2=1<<t
  sums=0
  for e in lst:
    sms=(sums|(1+sums)<<e)&m1
  sms|=1
  if (sms)&m2>0:
    return True
  return False

s=readline().strip()
x,y=map(int,readline().split())

s=s.replace('TF','T F')
s=s.replace('FT','F T')
bs=s.split()
if bs[0][0]=='F':
  x-=len(bs[0])
  del bs[0]

xy=[[],[]]
f=0
for i,e in enumerate(bs):
  if not i%2:
    l=len(e)
  else:
    f^=l%2
    xy[f].append(len(e))
if isinsums(x,xy[0]) and isinsums(y,xy[1]):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import sys
read=sys.stdin.read
readline=sys.stdin.readline

def isinsums(x,lst):
  s=sum(lst)
  t=(s+x)//2
  if s==0 and x==0:
    return True
  if (s-x)%2 or t<0:
    return False
  t=(s+x)//2
  m1=1<<(t+1)-1
  m2=1<<t
  sums=0
  for e in lst:
    sms=(sums|(1+sums)<<e)&m1
  sms|=1
  if (sms)&m2>0:
    return True
  return False

s=readline().strip()
x,y=map(int,readline().split())

s=s.replace('TF','T F')
s=s.replace('FT','F T')
bs=s.split()
if bs[0][0]=='F':
  x-=len(bs[0])
  del bs[0]

xy=[[],[]]
f=0
for i,e in enumerate(bs):
  if not i%2:
    l=len(e)
  else:
    f^=l%2
    xy[f].append(len(e))
print(bs,xy,x,y)
if isinsums(x,xy[0]) and isinsums(y,xy[1]):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import sys
read=sys.stdin.read
readline=sys.stdin.readline

def isinsums(x,lst):
  if not lst:
    if x:
      return False
    else:
      return True
  s=sum(lst)
  if (s-x)%2:
    return False
  t=(s+x)//2
  m1=1<<(t+1)-1
  m2=1<<t
  sums=0
  for e in lst:
    sms=(sums|(1+sums)<<e)&m1
    if (sms|1)&m2>0:
      return True
  return False

s=readline().strip()
x,y=map(int,readline().split())

s=s.replace('TF','T F')
s=s.replace('FT','F T')
bs=s.split()
if bs[0][0]=='F':
  x-=len(bs[0])
  del bs[0]

xy=[[],[]]
f=0
for i,e in enumerate(bs):
  if not i%2:
    l=len(e)
  else:
    f^=l%2
    xy[f].append(len(e))
if isinsums(x,xy[0]) and isinsums(y,xy[1]):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
import sys
read=sys.stdin.read
readline=sys.stdin.readline

def isinsums(x,lst):
  if not lst:
    if x:
      return False
    else:
      return True
  s=sum(lst)
  if (s-x)%2:
    return False
  t=(s+x)//2
  m1=1<<(t+1)-1
  m2=1<<t
  sums=0
  for e in lst:
    sms=(sums|(1+sums)<<e)&m1
    if (sms|1)&m2>0:
      return True
  return False

s=readline().strip()
x,y=map(int,readline().split())

s=s.replace('TF','T F')
s=s.replace('FT','F T')
bs=s.split()
if bs[0][0]=='F':
  x-=len(bs[0])
  del bs[0]

xy=[[],[]]
f=0
for i,e in enumerate(bs):
  if not i%2:
    l=len(e)
  else:
    f^=l%2
    xy[f].append(len(e))
print(xy)
if isinsums(x,xy[0]) and isinsums(y,xy[1]):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
def main():
  s = input()
  n = len(s)
  x, y = map(int, input().split())

  dpx = [[False, False] for _ in range(n)]
  dpy = [[False, False] for _ in range(n)]

  dpx[0][0] = True
  dpy[0][0] = True
  x_turn = False
  y_turn = False
  judge = True
  turn = False
  xcount = 0
  count = 0
  for i in range(n):
    if judge and s[i] == "F":
      xcount += 1
      continue
    if judge:
      judge = False
      turn = False if turn else True
      continue
    if s[i] == "F":
      count += 1
      if i != n-1:
        continue
    if turn:
      y_turn = False if y_turn else True
      if y_turn:
        p, q = 0, 1
      else:
        p, q = 1, 0
      for i in range(n+1):
        
        dpy[i][q] = False
      for i in range(n+1):
        if dpy[i][p]:
          dpy[abs(i-count)][q] = True
          dpy[i+count][q] = True
    else:
      x_turn = False if x_turn else True
      if x_turn:
        p, q = 0, 1
      else:
        p, q = 1, 0
      for i in range(n+1):
        dpx[i][q] = False
      for i in range(n+1):
        if dpx[i][p]:
          dpx[abs(i-count)][q] = True
          dpx[i+count][q] = True
    turn = False if turn else True
    count = 0
  
  p = 1 if x_turn else 0
  q = 1 if y_turn else 0
  x -= xcount
  if abs(x) > n:
    print("No")
  elif dpx[abs(x)][p] and dpy[abs(y)][q]:
    print("Yes")
  else:
    print("No")
  
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
def main():
  s = input()
  n = len(s)
  x, y = map(int, input().split())
  
  x_max = 0
  y_max = 0
  dpx = [[False, False] for _ in range(n+2)]
  dpy = [[False, False] for _ in range(n+2)]

  dpx[0][0] = True
  dpy[0][0] = True
  x_turn = False
  y_turn = False
  judge = True
  turn = False
  xcount = 0
  count = 0
  for i in range(n):
    if judge and s[i] == "F":
      xcount += 1
      continue
    if judge:
      judge = False
      turn = False if turn else True
      continue
    if s[i] == "F":
      count += 1
      if i != n-1:
        continue
    if turn:
      y_turn = False if y_turn else True
      if y_turn:
        p, q = 0, 1
      else:
        p, q = 1, 0
      for i in range(n+1):
        
        dpy[i][q] = False
      for i in range(n+1):
        if dpy[i][p]:
          dpy[abs(i-count)][q] = True
          dpy[i+count][q] = True
        if i == y_max:
          y_max = i+count
          break
    else:
      x_turn = False if x_turn else True
      if x_turn:
        p, q = 0, 1
      else:
        p, q = 1, 0
      for i in range(n+1):
        dpx[i][q] = False
      for i in range(n+1):
        if dpx[i][p]:
          dpx[abs(i-count)][q] = True
          dpx[i+count][q] = True
        if i == x_max:
          x_max = i+count
          break
    turn = False if turn else True
    count = 0
  
  p = 1 if x_turn else 0
  q = 1 if y_turn else 0
  x -= xcount
  if dpx[abs(x)][p] and dpy[abs(y)][q]:
    print("Yes")
  else:
    print("No")
  
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
import sys
import copy
input = sys.stdin.readline

def main():
  s = input()
  n = len(s)
  x, y = map(int, input().split())
  
  x_max = 0
  y_max = 0
  dpx = [[False, False] for _ in range(n+1)]
  dpy = [[False, False] for _ in range(n+1)]

  dpx[0][0] = True
  dpy[0][0] = True
  x_turn = False
  y_turn = False
  judge = True
  turn = False
  xcount = 0
  count = 0
  for i in range(n):
    if judge and s[i] == "F":
      xcount += 1
      continue
    if judge:
      judge = False
      turn = False if turn else True
      continue
    if s[i] == "F":
      count += 1
      if i != n-1:
        continue
    if turn:
      y_turn = False if y_turn else True
      if y_turn:
        p, q = 0, 1
      else:
        p, q = 1, 0
      for i in range(n+1):
        
        dpy[i][q] = False
      for i in range(n+1):
        if dpy[i][p]:
          dpy[abs(i-count)][q] = True
          dpy[i+count][q] = True
        if i == y_max:
          y_max = i+count
          break
    else:
      x_turn = False if x_turn else True
      if x_turn:
        p, q = 0, 1
      else:
        p, q = 1, 0
      for i in range(n+1):
        dpx[i][q] = False
      for i in range(n+1):
        if dpx[i][p]:
          dpx[abs(i-count)][q] = True
          dpx[i+count][q] = True
        if i == x_max:
          x_max = i+count
          break
    turn = False if turn else True
    count = 0
  
  p = 1 if x_turn else 0
  q = 1 if y_turn else 0
  x -= xcount
  if dpx[abs(x)][p] and dpy[abs(y)][q]:
    print("Yes")
  else:
    print("No")
  
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def check(vec, init_pos, target_pos):
    base = 8000
    N = len(vec)
    M = 2 * base + 1
    dp = [False] * M
    dp[init_pos + base] = True

    for i in range(N):
        dp, dp_prev = [False] * M, dp
        for j in range(M):
            if j - vec[i] >= 0 and dp_prev[j - vec[i]] or j + vec[i] <= 16000 and dp_prev[j + vec[i]]:
                dp[j] = True

    return dp[target_pos + base]


def main():
    S = readline().strip()
    x, y = map(int, readline().split())

    idx = len(S)
    for i, c in enumerate(S):
        if c == 'T':
            idx = i
            break

    init_x = idx
    step = [[] for _ in range(2)]
    i = 0
    for c in S[idx:]:
        if c == 'T':
            i = 1 - i
            step[i].append(0)
        else:
            step[i][-1] += 1

    if not step[0]:
        step[0].appned(0)
    if not step[1]:
        step[1].append(0)

    ok = check(step[0], init_x, x) and check(step[1], 0, y)

    if ok:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

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

goal = {"x": x, "y": y}
dist = {"x": [], "y": []}

if s[-1] != "T":
    s += "T"
d = 0
f = 0
for i in s:
    if i == "F":
        d += 1
    else:
        if f % 2 == 0:
            dist["x"].append(d)
        else:
            dist["y"].append(d)
        d = 0
        f += 1

# print(dist)
for mode in ("x", "y"):
    len_d = len(dist[mode])
    # dp[len_d][grid]
    dp = [[0 for _ in range(16005)] for _ in range(len_d+1)]
    # print(dp)
    dp[0][8000] = 1
    for i in range(len_d):
        for j in range(16005):
            if dp[i][j] == 0:
                continue
            # +に進む
            # print(dist[mode][i])
            dp[i+1][j + dist[mode][i]] += dp[i][j]
            # -に進む
            dp[i+1][j - dist[mode][i]] += dp[i][j]

    if dp[i+1][goal[mode] + 8000] == 0:
        print("No")
        sys.exit()

print("Yes")

Submission status: Runtime Error

Solution code:
s=input()+'T'
x,y=list(map(int,input().split()))
x+=8000
y+=8000
n=len(s)
i=0

while i<n and s[i]=='F':
    i+=1

dx=[[0]*16001 for _ in range(2)]
dy=[[0]*16001 for _ in range(2)]

dx[0][i+8000]=1
dy[0][8000]=1

lstx=[]
lsty=[]
d='x'
cnt=0

while i<n:
    if s[i]=='F':
        cnt+=1
    else:
        if cnt>0:
            if d=='x':
                lstx.append(cnt)
            else:
                lsty.append(cnt)
        
        if d=='x':
            d='y'
        else:
            d='x'
        cnt=0
    
    i+=1

for i,cx in enumerate(lstx):
    for j in range(16001):
        if dx[i%2][j]==0:
            continue
        if j+cx<16001:
            dx[(i+1)%2][j+cx]=1
        if j-cx>-1:
            dx[(i+1)%2][j-cx]=1

for i,cy in enumerate(lsty):
    for j in range(16001):
        if dy[i%2][j]==0:
            continue
        if j+cy<16001:
            dy[(i+1)%2][j+cy]=1
        if j-cy>-1:
            dy[(i+1)%2][j-cy]=1

if dx[len(lstx)][x]==1 and dy[len(lsty)][y]==1:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
s = input().strip()
N = len(s)
x,y = map(int,input().split())
flag0 = 0
for i in range(N):
    if s[i]=="T":
        ind = i
        flag0 = 1
        break
if flag0==0:
    if y==0 and x==N:
        print("Yes")
    else:
        print("No")
else:
    C={"x":[],"y":[]}
    flag=0
    cnt = 0
    for i in range(ind+1,N):
        if s[i]!="T":
            cnt += 1
        else:
            if flag==0 and cnt>0:
                C["y"].append(cnt)
            elif flag==1 and cnt>0:
                C["x"].append(cnt)
            cnt = 0
            flag = 1-flag
    if flag==0:
        C["y"].append(cnt)
    else:
        C["x"].append(cnt)
    nx = len(C["x"])
    xlim = 0
    for i in range(nx):
        xlim += C["x"][i]
    ny = len(C["y"])
    ylim = 0
    for i in range(ny):
        ylim += C["y"][i]
    x = x-ind  #x>=-N
    if x<-xlim-1 or x>xlim+1 or y<-ylim-1 or y>ylim+1:
        print("No")
    else:
        dp1 = {(i,j):0 for i in range(nx+1) for j in range(-xlim,xlim+1)}
        dp1[(0,0)]=1
        for i in range(1,nx+1):
            for j in range(-xlim,xlim+1):
                dp1[(i,j)] = dp1[(i-1,j)]
                if j-C["x"][i-1]>=-xlim:
                    dp1[(i,j)] = dp1[(i,j)]|dp1[(i-1,j-C["x"][i-1])]
                if j+C["x"][i-1]<=xlim:
                    dp1[(i,j)] = dp1[(i,j)]|dp1[(i-1,j+C["x"][i-1])]
        dp0 = {(i,j):0 for i in range(ny+1) for j in range(-ylim,ylim+1)}
        dp0[(0,0)] = 1
        for i in range(1,ny+1):
            for j in range(-ylim,ylim+1):
                dp0[(i,j)] = dp0[(i-1,j)]
                if j-C["y"][i-1]>=-ylim:
                    dp0[(i,j)] = dp0[(i,j)]|dp0[(i-1,j-C["y"][i-1])]
                if j+C["y"][i-1]<=ylim:
                    dp0[(i,j)] = dp0[(i,j)]|dp0[(i-1,j+C["y"][i-1])]
        if dp1[(nx,x)]==1 and dp0[(ny,y)]==1:
            print("Yes")
        else:
            print("No")

Submission status: Runtime Error

Solution code:
s = input().strip()
N = len(s)
x,y = map(int,input().split())
for i in range(N):
    if s[i]=="T":
        ind = i
        break
C={"x":[],"y":[]}
flag=0
cnt = 0
for i in range(ind+1,N):
    if s[i]!="T":
        cnt += 1
    else:
        if flag==0 and cnt>0:
            C["y"].append(cnt)
        elif flag==1 and cnt>0:
            C["x"].append(cnt)
        cnt = 0
        flag = 1-flag
if flag==0:
    C["y"].append(cnt)
else:
    C["x"].append(cnt)
nx = len(C["x"])
x = x-ind  #x>=-N
dp1 = {(i,j):0 for i in range(nx+1) for j in range(-N,N+1)}
dp1[(0,0)]=1
for i in range(1,nx+1):
    for j in range(-N,N+1):
        dp1[(i,j)] = dp1[(i-1,j)]
        if j-C["x"][i-1]>=-N:
            dp1[(i,j)] = dp1[(i,j)]|dp1[(i-1,j-C["x"][i-1])]
        if j+C["x"][i-1]<=N:
            dp1[(i,j)] = dp1[(i,j)]|dp1[(i-1,j+C["x"][i-1])]
ny = len(C["y"])
dp0 = {(i,j):0 for i in range(ny+1) for j in range(-N,N+1)}
dp0[(0,0)] = 1
for i in range(1,ny+1):
    for j in range(-N,N+1):
        dp0[(i,j)] = dp0[(i-1,j)]
        if j-C["y"][i-1]>=-N:
            dp0[(i,j)] = dp0[(i,j)]|dp0[(i-1,j-C["y"][i-1])]
        if j+C["y"][i-1]<=N:
            dp0[(i,j)] = dp0[(i,j)]|dp0[(i-1,j+C["y"][i-1])]
if dp1[(nx,x)]==1 and dp0[(ny,y)]==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(3000)

from functools import lru_cache


Fseq = list(map(len, input().split("T")))
x, y = map(int, input().split(" "))


Fseq_x = list(filter(lambda x:x>0, sorted(Fseq[0::2])))[::-1]
Fseq_y = list(filter(lambda x:x>0, sorted(Fseq[1::2])))[::-1]


def check(seq, target):
    s = sum(seq)
    new_target = s+target
    if new_target % 2 == 1:
        return False
    new_target = new_target // 2
    return check2(seq, new_target)

@lru_cache(maxsize=1000)
def check2(seq, target):
    if target == 0:
        return True
    if len(seq) == 0 or target < 0 or target > sum(seq):
        return False
    return check2(seq[1:], target-seq[0]) or check2(seq[1:], target)


x_check = check(Fseq_x, x)
y_check = check(Fseq_y, y)

print("Yes" if x_check and y_check else "No")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(3000)

from functools import import lru_cache


Fseq = list(map(len, input().split("T")))
x, y = map(int, input().split(" "))


Fseq_x = list(filter(lambda x:x>0, sorted(Fseq[0::2])))[::-1]
Fseq_y = list(filter(lambda x:x>0, sorted(Fseq[1::2])))[::-1]


def check(seq, target):
    s = sum(seq)
    new_target = s+target
    if new_target % 2 == 1:
        return False
    new_target = new_target // 2
    return check2(seq, new_target)

@lru_cache(maxsize=1000)
def check2(seq, target):
    if target == 0:
        return True
    if len(seq) == 0 or target < 0 or target > sum(seq):
        return False
    return check2(seq[1:], target-seq[0]) or check2(seq[1:], target)


x_check = check(Fseq_x, x)
y_check = check(Fseq_y, y)

print("Yes" if x_check and y_check else "No")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)


Fseq = list(map(len, input().split("T")))
x, y = map(int, input().split(" "))


Fseq_x = sorted(Fseq[0::2])
Fseq_y = sorted(Fseq[1::2])

for i, f in enumerate(Fseq_x):
    if f > 0:
        break
Fseq_x = Fseq_x[i:]
Fseq_x = Fseq_x[::-1]

for i, f in enumerate(Fseq_y):
    if f > 0:
        break
Fseq_y = Fseq_y[i:]
Fseq_y = Fseq_y[::-1]


def check(seq, target):
    s = sum(seq)
    new_target = s+target
    if new_target % 2 == 1:
        return False
    new_target = new_target // 2
    return check2(seq, new_target)

def check2(seq, target):
    if target == 0:
        return True
    if len(seq) == 0 or target < 0 or target > sum(seq):
        return False
    return check2(seq[1:], target-seq[0]) or check2(seq[1:], target)


x_check = check(Fseq_x, x)
y_check = check(Fseq_y, y)

print("Yes" if x_check and y_check else "No")

Submission status: Runtime Error

Solution code:
Fseq = list(map(len, input().split("T")))
x, y = map(int, input().split(" "))


Fseq_x = sorted(Fseq[0::2])[::-1]
Fseq_y = sorted(Fseq[1::2])[::-1]

for i, f in enumerate(Fseq_x):
    if f > 0:
        break
Fseq_x = Fseq_x[i:]


for i, f in enumerate(Fseq_y):
    if f > 0:
        break
Fseq_y = Fseq_y[i:]


def check(seq, target):
    s = sum(seq)
    new_target = s+target
    if new_target % 2 == 1:
        return False
    new_target = new_target // 2
    return check2(seq, new_target)

def check2(seq, target):
    if target == 0:
        return True
    if len(seq) == 0 or target < 0 or target > sum(seq):
        return False
    return check2(seq[1:], target-seq[0]) or check2(seq[1:], target)


x_check = check(Fseq_x, x)
y_check = check(Fseq_y, y)

print("Yes" if x_check and y_check else "No")

Submission status: Runtime Error

Solution code:
Fseq = list(map(len, input().split("T")))
x, y = map(int, input().split(" "))


Fseq_x = sorted(Fseq[0::2])[::-1]
Fseq_y = sorted(Fseq[1::2])[::-1]

for i, f in enumerate(Fseq_x):
    if f > 0:
        break
Fseq_x = Fseq_x[i:]


for i, f in enumerate(Fseq_y):
    if f > 0:
        break
Fseq_y = Fseq_y[i:]


def check(seq, target):
    s = sum(seq)
    new_target = s+target
    if new_target % 2 == 1:
        return False
    new_target = new_target // 2
    return check2(seq, new_target)

def check2(seq, target):
    if target < 0 or target > sum(seq):
        return False
    if len(seq) == 0:
        if target == 0:
            return True
        else:
            return False
    return check2(seq[1:], target-seq[0]) or check2(seq[1:], target)


x_check = check(Fseq_x, x)
y_check = check(Fseq_y, y)

print("Yes" if x_check and y_check else "No")

Submission status: Runtime Error

Solution code:
Fseq = list(map(len, input().split("T")))
x, y = map(int, input().split(" "))


Fseq_x = sorted(Fseq[0::2])[::-1]
Fseq_y = sorted(Fseq[1::2])[::-1]

for i, f in enumerate(Fseq_x):
    if f > 0:
        break
Fseq_x = Fseq_x[i:]


for i, f in enumerate(Fseq_y):
    if f > 0:
        break
Fseq_y = Fseq_y[i:]

print(Fseq_x)
print(Fseq_y)

def check(seq, target):
    s = sum(seq)
    new_target = s+target
    if new_target % 2 == 1:
        return False
    new_target = new_target // 2
    return check2(seq, new_target)

def check2(seq, target):
    if target < 0 and target > sum(seq):
        return False
    if len(seq) == 0:
        if target == 0:
            return True
        else:
            return False
    return check2(seq[1:], target-seq[0]) or check2(seq[1:], target)


x_check = check(Fseq_x, x)
y_check = check(Fseq_y, y)

print("Yes" if x_check and y_check else "No")

Submission status: Runtime Error

Solution code:
Fseq = list(map(len, input().split("T")))
x, y = map(int, input().split(" "))


Fseq_x = sorted(Fseq[0::2])
Fseq_y = sorted(Fseq[1::2])

def check(seq, target):
    s = sum(seq)
    new_target = s+target
    if new_target % 2 == 1:
        return False
    new_target = new_target // 2
    return check2(seq, new_target)

def check2(seq, target):
    if target < 0 and target > sum(seq):
        return False
    if len(seq) == 0:
        if target == 0:
            return True
        else:
            return False
    return check2(seq[1:], target-seq[0]) or check2(seq[1:], target)


x_check = check(Fseq_x, x)
y_check = check(Fseq_y, y)

print("Yes" if x_check and y_check else "No")

Submission status: Runtime Error

Solution code:
Fseq = list(map(len, input().split("T")))
x, y = map(int, input().split(" "))


Fseq_x = sorted(Fseq[0::2])
Fseq_y = sorted(Fseq[1::2])

def check(seq, target):
    s = sum(seq)
    new_target = s+target
    if new_target % 2 == 1:
        return False
    new_target = new_target // 2
    return check2(seq, new_target)

def check2(seq, target):
    if target == 0:
        return True
    if len(seq) == 0:
        return False
    if target < 0 and target > sum(seq):
        return False
    return check2(seq[1:], target) or check2(seq[1:], target-seq[0])


x_check = check(Fseq_x, x)
y_check = check(Fseq_y, y)

print("Yes" if x_check and y_check else "No")

Submission status: Runtime Error

Solution code:
s=input()
x,y=map(int,input().split())
t=s.split("T")
x-=len(t[0])
dx,dy=[],[]

for i,tt in enumerate(t[1:]):
  if i%2==1:
    dx.append(len(tt))
  else:
    dy.append(len(tt))

def is_ok(n,l):
  dp=[[0]*16001 for _ in range(len(l)+1)]
  n+=8000
  dp[0][8000]=1
  for i in range(1,len(l)+1):
    for j in range(16001):
      if j+l[i-1]<=16000:
        dp[i][j+l[i-1]]|=dp[i-1][j]
      if j-l[i-1]>=0:
        dp[i][j-l[i-1]]|=dp[i-1][j]
  if dp[len(l)][n]==1:
    return True
  else:
    return False

if is_ok(abs(x),dx) and is_ok(abs(y),dy):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
s=input()
x,y=map(int,input().split())
t=s.split("T")
x-=len(t[0])
dx,dy=[],[]

for i,tt in enumerate(t[1:]):
  if i%2==1:
    dx.append(len(tt))
  else:
    dy.append(len(tt))

def is_ok(n,l):
  dp=[[0]*18001 for _ in range(len(l)+1)]
  n+=9000
  dp[0][9000]=1
  for i in range(1,len(l)+1):
    for j in range(18001):
      if j+l[i-1]<=18000:
        dp[i][j+l[i-1]]|=dp[i-1][j]
      if j-l[i-1]>=0:
        dp[i][j-l[i-1]]|=dp[i-1][j]
  if dp[len(l)][n]==1:
    return True
  else:
    return False

if is_ok(abs(x),dx) and is_ok(abs(y),dy):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
s=input()
x,y=map(int,input().split())
t=s.split("T")
x-=len(t[0])
dx,dy=[],[]

for i,tt in enumerate(t[1:]):
  if i%2==1:
    dx.append(len(tt))
  else:
    dy.append(len(tt))

def is_ok(n,l):
  dp=[[0]*20001 for _ in range(len(l)+1)]
  n+=10000
  dp[0][10000]=1
  for i in range(1,len(l)+1):
    for j in range(20001):
      if j+l[i-1]<=20000:
        dp[i][j+l[i-1]]|=dp[i-1][j]
      if j-l[i-1]>=0:
        dp[i][j-l[i-1]]|=dp[i-1][j]
  if dp[len(l)][n]==1:
    return True
  else:
    return False

if is_ok(abs(x),dx) and is_ok(abs(y),dy):
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
s=input()
x,y=map(int,input().split())
t=s.split("T")
x-=len(t[0])
dx,dy=[],[]

for i,tt in enumerate(t[1:]):
  if i%2==1:
    dx.append(len(tt))
  else:
    dy.append(len(tt))

def is_ok(n,l):
  dp=[[False]*20001 for _ in range(len(l)+1)]
  n+=10000
  dp[0][10000]=True
  for i in range(1,len(l)+1):
    for j in range(20001):
      if j+l[i-1]<=20000:
        dp[i][j+l[i-1]]|=dp[i-1][j]
      if j-l[i-1]>=0:
        dp[i][j-l[i-1]]|=dp[i-1][j]
  if dp[len(l)][n]:
    return True
  else:
    return False

if is_ok(abs(x),dx) and is_ok(abs(y),dy):
  print("Yes")
else:
  print("No")