Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int, int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define OREP(i, n) for (int i = 1; i <= (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define GOODBYE                                                                \
  do {                                                                         \
    cout << "No" << endl;                                                      \
    return 0;                                                                  \
  } while (false)
#define MM << " " <<
#define Endl endl

signed main(void) {
  string S;
  int x, y;
  cin >> S;
  cin >> x >> y;
  int N = S.size();
  vector<int> X, Y;
  int Xsum = 0, Ysum = 0;
  int now = 0, mode = 0;
  REP(i, N + 1) {
    if (i == N || S[i] == 'T') {
      if (mode == 0) {
        X.push_back(now);
      } else {
        Y.push_back(now);
      }
      now = 0;
      mode ^= 1;
    } else {
      now++;
    }
  }
  x -= X[0];
  X[0] = 0;
  REP(i, X.size()) { Xsum += X[i]; }
  REP(i, Y.size()) { Ysum += Y[i]; }
  x += Xsum;
  y += Ysum;
  // cout << x MM y << endl;
  if (abs(x) % 2 == 1 || abs(y) % 2 == 1) {
    GOODBYE;
  }
  x /= 2;
  y /= 2;

  int xb[18514][2] = {};
  xb[0][0] = 1;
  REP(i, X.size()) {
    REP(j, 10000) {
      if (xb[j][0] == 1) {
        xb[j][1] = 1;
        xb[j + X[i]][1] = 1;
      }
    }
    REP(j, 10000) {
      xb[j][0] = xb[j][1];
      xb[j][1] = 0;
    }
  }

  int yb[18514][2] = {};
  yb[0][0] = 1;
  REP(i, Y.size()) {
    REP(j, 10000) {
      if (yb[j][0] == 1) {
        yb[j][1] = 1;
        yb[j + Y[i]][1] = 1;
      }
    }
    REP(j, 10000) {
      yb[j][0] = yb[j][1];
      yb[j][1] = 0;
    }
  }
  // cout << x MM y << endl;
  // REP(i,X.size()){cout << X[i] << " ";}cout << endl;
  // REP(i,Y.size()){cout << Y[i] << " ";}cout << endl;
  if (xb[x][0] == 1 && yb[y][0] == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int, int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define OREP(i, n) for (int i = 1; i <= (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define GOODBYE                                                                \
  do {                                                                         \
    cout << "No" << endl;                                                      \
    return 0;                                                                  \
  } while (false)
#define MM << " " <<
#define Endl endl

signed main(void) {
  string S;
  int x, y;
  cin >> S;
  cin >> x >> y;
  int N = S.size();
  vector<int> X, Y;
  int Xsum = 0, Ysum = 0;
  int now = 0, mode = 0;
  REP(i, N + 1) {
    if (i == N || S[i] == 'T') {
      if (mode == 0) {
        X.push_back(now);
      } else {
        Y.push_back(now);
      }
      now = 0;
      mode ^= 1;
    } else {
      now++;
    }
  }
  x -= X[0];
  X[0] = 0;
  REP(i, X.size()) { Xsum += X[i]; }
  REP(i, Y.size()) { Ysum += Y[i]; }
  x += Xsum;
  y += Ysum;
  // cout << x MM y << endl;
  if (abs(x) % 2 == 1 || abs(y) % 2 == 1) {
    GOODBYE;
  }
  x /= 2;
  y /= 2;

  int xb[18514][2] = {};
  xb[0][0] = 1;
  REP(i, X.size()) {
    REP(j, 10000) {
      if (xb[j][0] == 1) {
        xb[j][1] = 1;
        xb[j + X[i]][1] = 1;
      }
    }
    REP(j, 10000) {
      xb[j][0] = xb[j][1];
      xb[j][1] = 0;
    }
  }

  int yb[18514][2] = {};
  yb[0][0] = 1;
  REP(i, Y.size()) {
    REP(j, 10000) {
      if (yb[j][0] == 1) {
        yb[j][1] = 1;
        yb[j + Y[i]][1] = 1;
      }
    }
    REP(j, 10000) {
      yb[j][0] = yb[j][1];
      yb[j][1] = 0;
    }
  }
  // cout << x MM y << endl;
  // REP(i,X.size()){cout << X[i] << " ";}cout << endl;
  // REP(i,Y.size()){cout << Y[i] << " ";}cout << endl;
  // cout << x MM y << endl;
  if (x < 0 || y < 0) {
    GOODBYE;
  }
  if (xb[x][0] == 1 && yb[y][0] == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}