;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (declare #.OPT)
  (let* ((s (read-line))
         (len (length s))
         (x (read))
         (y (read))
         (hs (make-array len :element-type 'uint16 :fill-pointer 0))
         (vs (make-array len :element-type 'uint16 :fill-pointer 0)))
    (declare ((integer 1 8000) len)
             ((integer -8000 8000) x y))
    (loop with prev-t = -1
          with dest = hs
          for i below (length s)
          when (char= #\T (char s i))
          do (vector-push (- i prev-t 1) dest)
             (setq prev-t i
                   dest (if (eql dest hs) vs hs))
          finally (vector-push (- i prev-t 1) dest))
    (if
     (and
      (let ((dp1 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit))
            (dp2 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit)))
        (setf (aref dp1 (+ len (aref hs 0))) 1)
        (if (= 1 (length hs))
            (= (aref hs 0) x)
            (loop for h across (subseq hs 1)
                  for dp = dp1 then (if (eql dp dp1) dp2 dp1)
                  for dest-dp = dp2 then (if (eql dest-dp dp1) dp2 dp1)
                  do (fill dest-dp 0)
                     (loop for i of-type uint16 below (length dp)
                           when (= 1 (aref dp i))
                           do (setf (aref dest-dp (+ i h)) 1
                                    (aref dest-dp (- i h)) 1))
                  finally (return (= 1 (aref dest-dp (+ len x)))))))
      (let ((dp1 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit))
            (dp2 (make-array (+ 1 (* 2 len)) :initial-element 0 :element-type 'bit)))
        (setf (aref dp1 len) 1)
        (if (zerop (length vs))
            (zerop y)
            (loop for v across vs
                  for dp = dp1 then (if (eql dp dp1) dp2 dp1)
                  for dest-dp = dp2 then (if (eql dest-dp dp1) dp2 dp1)
                  do (fill dest-dp 0)
                     (loop for i of-type uint16 below (length dp)
                           when (= 1 (aref dp i))
                           do (setf (aref dest-dp (+ i v)) 1
                                    (aref dest-dp (- i v)) 1))
                  finally (return (= 1 (aref dest-dp (+ len y))))))))
     (write-line "Yes")
     (write-line "No"))))

#-swank(main)


Measured memory_bytes: 14824