Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#pragma region include
#include <iomanip>
#include <iostream>
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <complex>
#include <iterator>
#include <sstream>

#include <bitset>
#include <cstring>
#include <string>
#include <tuple>
#include <vector>

#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>

#include <fstream>
#include <random>
// #include <time.h>
#include <ctime>
#pragma endregion // #include
/////////
#define REP(i, x, n) for (int i = x; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL, LL> PLL;   //
typedef std::pair<int, int> PII; //
#pragma endregion                // typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace ::std;

bool check(vector<int> X, int x) {
  int MAX = 18001;
  int cen = MAX / 2;
  vector<bool> pos(MAX, false);
  pos[cen] = true; // 原点0にいる。
  x += cen;
  int size = X.size();
  for (int i = 0; i < size; ++i) {
    vector<bool> next(MAX, false);
    int move = X[i];
    for (int j = 0; j < MAX; ++j) {
      if (pos[j]) {
        next[j + move] = true;
        next[j - move] = true;
      }
    }
    pos = next;
  }
  return pos[x];
}
void solve() {
  string str;
  int x, y;
  cin >> str >> x >> y;
  int size = str.size();
  vector<int> X, Y;
  int dir = 0;
  int count = 0;
  int pos = 0;
  for (pos; pos < size; pos++) {
    if (str[pos] == 'F') {
      --x;
    } else {
      break;
    }
  }

  for (int i = pos; i < size; ++i) {
    if (str[i] == 'T') {
      if (count == 0) {
      } else if (dir & 1) {
        Y.push_back(count);
      } else {
        X.push_back(count);
      }
      count = 0;
      dir = (dir + 1) % 4;
    } else { // F
      ++count;
    }
  }
  if (count == 0) {
  } else if (dir & 1) {
    Y.push_back(count);
  } else {
    X.push_back(count);
  }

  if (check(X, x) == false) {
    cout << "No" << endl;
    return;
  }
  if (check(Y, y) == false) {
    cout << "No" << endl;
    return;
  }
  cout << "Yes" << endl;
}
#pragma region main
signed main(void) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed; // 小数を10進数表示
  cout << setprecision(16); // 小数点以下の桁数を指定//coutとcerrで別

  solve();
}
#pragma endregion // main()

Fixed submission:
#pragma region include
#include <iomanip>
#include <iostream>
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <complex>
#include <iterator>
#include <sstream>

#include <bitset>
#include <cstring>
#include <string>
#include <tuple>
#include <vector>

#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>

#include <fstream>
#include <random>
// #include <time.h>
#include <ctime>
#pragma endregion // #include
/////////
#define REP(i, x, n) for (int i = x; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL, LL> PLL;   //
typedef std::pair<int, int> PII; //
#pragma endregion                // typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace ::std;

bool check(vector<int> X, int x) {
  int MAX = 32001;
  int cen = MAX / 2;
  vector<bool> pos(MAX, false);
  pos[cen] = true; // 原点0にいる。
  x += cen;
  int size = X.size();
  for (int i = 0; i < size; ++i) {
    vector<bool> next(MAX, false);
    int move = X[i];
    for (int j = 0; j < MAX; ++j) {
      if (pos[j]) {
        next[j + move] = true;
        next[j - move] = true;
      }
    }
    pos = next;
  }
  return pos[x];
}
void solve() {
  string str;
  int x, y;
  cin >> str >> x >> y;
  int size = str.size();
  vector<int> X, Y;
  int dir = 0;
  int count = 0;
  int pos = 0;
  for (pos; pos < size; pos++) {
    if (str[pos] == 'F') {
      --x;
    } else {
      break;
    }
  }

  for (int i = pos; i < size; ++i) {
    if (str[i] == 'T') {
      if (count == 0) {
      } else if (dir & 1) {
        Y.push_back(count);
      } else {
        X.push_back(count);
      }
      count = 0;
      dir = (dir + 1) % 4;
    } else { // F
      ++count;
    }
  }
  if (count == 0) {
  } else if (dir & 1) {
    Y.push_back(count);
  } else {
    X.push_back(count);
  }

  if (check(X, x) == false) {
    cout << "No" << endl;
    return;
  }
  if (check(Y, y) == false) {
    cout << "No" << endl;
    return;
  }
  cout << "Yes" << endl;
}
#pragma region main
signed main(void) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed; // 小数を10進数表示
  cout << setprecision(16); // 小数点以下の桁数を指定//coutとcerrで別

  solve();
}
#pragma endregion // main()