Problem p03488 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = 500000004;
const double EPS = 1e-6;
const double PI = acos(-1.0);
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
char in[8100];
vector<int> X;
vector<int> Y;
int dp[8100];
int main() {
  scanf("%s", in);
  int x, y;
  scanf("%d%d", &x, &y);
  int e = 0;
  int m = 0;
  int fl = 0;
  for (int i = 0; in[i]; i++) {
    if (in[i] == 'F')
      e++;
    else {
      if (m % 2 == 0) {
        if (fl == 0)
          x -= e;
        else
          X.push_back(e);
      } else {
        Y.push_back(e);
      }
      m++;
      e = 0;
      fl = 1;
    }
  }
  if (m % 2 == 0) {
    if (fl == 0)
      x -= e;
    X.push_back(e);
  } else {
    Y.push_back(e);
  }
  m++;
  e = 0;
  fl = 1;

  //	for(int i=0;i<X.size();i++)printf("%d ",X[i]);
  dp[0] = 1;
  int ff = 0;
  for (int i = 0; i < X.size(); i++) {
    ff += X[i];
    for (int j = 8050; j >= 0; j--) {
      if (dp[j]) {
        dp[j + X[i]] = 1;
      }
    }
  }
  if (ABS(ff - x) % 2 || ff < x || !dp[(ff - x) / 2]) {
    printf("No\n");
    return 0;
  }
  ff = 0;
  for (int i = 0; i < 8100; i++)
    dp[i] = 0;
  dp[0] = 1;
  for (int i = 0; i < Y.size(); i++) {
    ff += Y[i];
    for (int j = 8050; j >= 0; j--) {
      if (dp[j]) {
        dp[j + Y[i]] = 1;
      }
    }
  }
  if (ABS(ff - y) % 2 || ff < y || !dp[(ff - y) / 2]) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = 500000004;
const double EPS = 1e-6;
const double PI = acos(-1.0);
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
char in[8100];
vector<int> X;
vector<int> Y;
int dp[8100];
int main() {
  scanf("%s", in);
  int x, y;
  scanf("%d%d", &x, &y);
  int e = 0;
  int m = 0;
  int fl = 0;
  for (int i = 0; in[i]; i++) {
    if (in[i] == 'F')
      e++;
    else {
      if (m % 2 == 0) {
        if (fl == 0)
          x -= e;
        else
          X.push_back(e);
      } else {
        Y.push_back(e);
      }
      m++;
      e = 0;
      fl = 1;
    }
  }
  if (m % 2 == 0) {
    if (fl == 0)
      x -= e;
    else
      X.push_back(e);
  } else {
    Y.push_back(e);
  }
  m++;
  e = 0;
  fl = 1;

  //	for(int i=0;i<X.size();i++)printf("%d ",X[i]);
  dp[0] = 1;
  int ff = 0;
  for (int i = 0; i < X.size(); i++) {
    ff += X[i];
    for (int j = 8050; j >= 0; j--) {
      if (dp[j]) {
        dp[j + X[i]] = 1;
      }
    }
  }
  if (ABS(ff - x) % 2 || ff < x || !dp[(ff - x) / 2]) {
    printf("No\n");
    return 0;
  }
  ff = 0;
  for (int i = 0; i < 8100; i++)
    dp[i] = 0;
  dp[0] = 1;
  for (int i = 0; i < Y.size(); i++) {
    ff += Y[i];
    for (int j = 8050; j >= 0; j--) {
      if (dp[j]) {
        dp[j + Y[i]] = 1;
      }
    }
  }
  if (ABS(ff - y) % 2 || ff < y || !dp[(ff - y) / 2]) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
}