D - FT Robot 解説 /

実行時間制限: 2 sec / メモリ制限: 512 MB

配点 : 500

問題文

二次元平面の原点にロボットが置かれています。 最初、ロボットは x 軸の正の向きを向いています。

このロボットに命令列 s が与えられます。 s は次の 2 文字のみからなり、先頭から末尾まで順に実行されます。

  • F : 今向いている向きに長さ 1 だけ移動する。
  • T : 時計回りまたは反時計回りの好きな方向に 90 度だけ向きを変える。

ロボットの目標は、命令列をすべて実行し終わった後に座標 (x, y) にいることです。 この目標が達成可能か判定してください。

制約

  • sF, T のみからなる。
  • 1 \leq |s| \leq 8\ 000
  • x, y は整数である。
  • |x|, |y| \leq |s|

入力

入力は以下の形式で標準入力から与えられる。

s
x y

出力

目標が達成可能ならば Yes を出力し、達成不可能ならば No を出力せよ。


入力例 1

FTFFTFFF
4 2

出力例 1

Yes

1 番目の T で反時計周りに 90 度だけ向きを変え、2 番目の T で時計周りに 90 度だけ向きを変えればよいです。


入力例 2

FTFFTFFF
-2 -2

出力例 2

Yes

1 番目の T で時計周りに 90 度だけ向きを変え、2 番目の T で時計周りに 90 度だけ向きを変えればよいです。


入力例 3

FF
1 0

出力例 3

No

入力例 4

TF
1 0

出力例 4

No

入力例 5

FFTTFF
0 0

出力例 5

Yes

例えば、1 番目の T で反時計周りに 90 度だけ向きを変え、2 番目の T で反時計周りに 90 度だけ向きを変えればよいです。


入力例 6

TTTT
1 0

出力例 6

No

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