stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define MAX 5050

#define INF (1LL<<60LL)

typedef pair<int,int> P;

int V;

struct edge2{

  int from,to,cost;

  edge2(){}

  edge2(int from,int to,int cost):from(from),to(to),cost(cost){}

};

edge2 es[MAX];

int d[MAX];

int ok[MAX];

int used[MAX];

int shortest_path(int s,int e){

  for(int i=0;i<V;i++) d[i]=INF;

  d[s]=0;

  for(int j=0;j<V;j++){

    bool update=0;

    for(int i=0;i<e;i++){

      edge2 e=es[i];

      if(!ok[e.from]||!ok[e.to]) continue;

      if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){

        d[e.to]=d[e.from]+e.cost;

        update=1;

      }

    }

    if(!update) break;

    if(j==V-1){

      cout<<-1<<endl;

      exit(0);

    }

  }

  return d[V-1];

}



vector<int> G[MAX];

void dfs2(int v){

  if(used[v]) return;

  used[v]=1;

  for(int u:G[v]){

    dfs2(u);

  }

}



signed main(){

  int v,e,p;

  cin>>v>>e>>p;

  for(int i=0;i<e;i++){

    int u,v,d;

    cin>>u>>v>>d;u--;v--;

    G[u].push_back(v);

    es[i]=edge2(u,v,p-d);

  }

  for(int i=0;i<v;i++){

    memset(used,0,sizeof(used));

    dfs2(i);

    ok[i]=used[v-1];

  }

  V=v;

  cout<<max<int>(-shortest_path(0,e),0)<<endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1762134285190726x):
#include<bits/stdc++.h>

using namespace std;

using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}

template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}



//BEGIN CUT HERE

template<typename T>

struct BellmanFord{

  struct edge{

    int u,v;

    T w;

    edge(){}

    edge(int u,int v,T w):u(u),v(v),w(w){}

  };



  int n;

  vector< vector<int> > G;

  vector<int> used,reach;

  BellmanFord(int n):n(n),G(n),used(n,0),reach(n,0){}



  vector<edge> es;

  void add_edge(int u,int v,T c){

    es.emplace_back(u,v,c);

    G[u].emplace_back(v);

  }



  void dfs(int v){

    if(used[v]) return;

    used[v]=1;

    for(int u:G[v]) dfs(u);

  }



  T build(int from,int to,int &neg_loop){

    for(int i=0;i<n;i++){

      fill(used.begin(),used.end(),0);

      dfs(i);

      reach[i]=used[to];

    }

    const T INF = numeric_limits<T>::max();

    vector<T> ds(n,INF);

    ds[from]=0;

    for(int j=0;j<n;j++){

      bool update=0;

      for(auto e:es){

        if(!reach[e.u]||!reach[e.v]||ds[e.u]==INF) continue;

        if(ds[e.v]>ds[e.u]+e.w){

          ds[e.v]=ds[e.u]+e.w;

          update=1;

        }

      }

      if(!update) break;

      if(j==n-1){

        neg_loop=1;

        return INF;

      }

    }

    neg_loop=0;

    return ds[to];

  }

};

//END CUT HERE

//INSERT ABOVE HERE



signed main(){

  int n,m,p;

  cin>>n>>m>>p;

  BellmanFord<int> G(n);

  for(int i=0;i<m;i++){

    int a,b,c;

    cin>>a>>b>>c;

    a--;b--;

    G.add_edge(a,b,p-c);

  }

  int neg_loop;

  int res=G.build(0,n-1,neg_loop);

  if(neg_loop){

    cout<<-1<<endl;

    return 0;

  }

  cout<<max(-res,0)<<endl;

  return 0;

}

/*

  verified on 2019/08/10

  https://atcoder.jp/contests/abc137/tasks/abc137_e

*/
// Slower C++ solution:
#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <queue>

#include <set>

#include <map>

#include <string.h>

#include <cmath>



using namespace std;

typedef long long i64;

typedef long double ld;

typedef pair<i64,i64> P;

#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))



int n;



i64 c[1010];

i64 w[1010];



i64 sum[1010];



int dp[1010][1010];



int main()

{

	cin >> n;

	rep(i,0,n - 1)

		cin >> c[i] >> w[i];



	rep(i,1,n)

	{

		sum[i] = sum[i - 1] + w[i - 1];

	}



	auto getsum = [&](int l,int r){

		return sum[r] - sum[l];

	};



	rep(i,0,1000) rep(j,0,1000) dp[i][j] = 1e9;



	rep(i,0,1000)

		dp[i][i + 1] = 1;

	

	rep(w,2,n)

	{

		rep(l,0,n - 1)

		{

			//[l,r)

			int r = l + w;

			if(r > n) continue;



			rep(mid,l + 1,r - 1)

			{

				dp[l][r] = min(dp[l][r] , dp[l][mid] + dp[mid][r]);

			}



			//left is mighty

			{



				i64 w_s = getsum(l + 1,r);

				if(c[l] >= w_s && dp[l + 1][r] == 1)

				{

					dp[l][r] = 1;

				}

			}

			{

				i64 w_s = getsum(l,r - 1);

				if(c[r - 1] >= w_s && dp[l][r - 1] == 1)

				{

					dp[l][r] = 1;

				}

			}

			/*

			rep(i,0,n)

			{

				if(l <= i && i < r)

					cout << "=";

				else

					cout << " ";

			}

			cout << dp[l][r] << endl;

			*/

		}



	}



	cout << dp[0][n] << endl;



}




// Faster C++ solution for the same problem (measured speedup: 5.129588048377911x):
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

#define all(x) x.begin(),x.end()



int N;



i64 dp[1010][1010];

vector<i64> c,w;



i64 ret[1010];



int main(){

  cin >> N;

  c.resize(N + 1);

  w.resize(N + 1);

  rep(i,1,N) cin >> c[i] >> w[i];

  rep(i,1,N) w[i] += w[i - 1];





  rep(i,1,N) dp[i][i] = 1;

  for(int d = 1;d <= N;d++){

    for(int l = 1;l + d <= N;l++){

      int r = l + d;

      if(dp[l][r - 1] == 1 && (w[r - 1] - w[l - 1]) <= c[r]){

        dp[l][r] = 1;

      }

      if(dp[l + 1][r] == 1 && (w[r] - w[l + 1 - 1]) <= c[l]){

        dp[l][r] = 1;

      }

    }

  }



  for(int i = 1;i <= N;i++) ret[i] = 1e9;

  for(int i = 1;i <= N;i++){

    for(int j = i;j <= N;j++){

      if(dp[i][j] == 1){

        ret[j] = min(ret[j] , ret[i - 1] + 1);

      }

    }

  }



  cout << ret[N] << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define REP(i,n,N) for(int i=n;i<N;i++)

#define p(S) cout<<(S)<<endl

using namespace std;

int dp[1001][1001];

int w[100010],c[100010];

int sumw[100010];

int main(){

	int n;

	cin>>n;

	REP(i,0,n) {

		cin>>c[i]>>w[i];

		if(i>0)	sumw[i]=sumw[i-1]+w[i];

		else sumw[i]=w[i];

	}

	REP(i,0,1001) REP(j,i,1001) dp[i][j]=j-i+1;

	REP(i,0,n-1)  if(c[i]>=w[i+1]||c[i+1]>=w[i]) dp[i][i+1]=1;





	for(int k=2;k<n;k++){

		for(int i=0;i+k<n;i++){

			if((dp[i+1][i+k]==1&&c[i]>=sumw[i+k]-sumw[i])||(dp[i][i+k-1]==1&&c[i+k]>=sumw[i+k-1]-(i?sumw[i-1]:0)))

				dp[i][i+k]=1;

			else dp[i][i+k]=min(dp[i+1][i+k],dp[i][i+k-1])+1;



			for(int j=i+1;j<i+k;j++)

				dp[i][i+k]=min(dp[i][i+k],dp[i][j]+dp[j+1][i+k]);

		}

	}

	p(dp[0][n-1]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.0692326816048863x):
#include <bits/stdc++.h>

#define REP(i,n,N) for(int i=n;i<N;i++)

#define p(S) cout<<(S)<<endl

using namespace std;

int dp[1001][1001];

int w[1001],c[1001];

int sumw[1001];

int main(){

	int n;

	cin>>n;

	cin>>c[0]>>w[0];

	sumw[0]=w[0];

	REP(i,1,n) {

		cin>>c[i]>>w[i];

		sumw[i]=sumw[i-1]+w[i];

	}

	REP(i,0,n) REP(j,i,n) dp[i][j]=j-i+1;

	REP(i,0,n-1)  if(c[i]>=w[i+1]||c[i+1]>=w[i]) dp[i][i+1]=1;



	for(int k=2;k<n;k++){

		for(int i=0;i+k<n;i++){

			if((dp[i+1][i+k]==1&&c[i]>=sumw[i+k]-sumw[i])||(dp[i][i+k-1]==1&&c[i+k]>=sumw[i+k-1]-(i?sumw[i-1]:0)))

				dp[i][i+k]=1;

			for(int j=i+1;j<i+k;j++)

				dp[i][i+k]=min(dp[i][i+k],dp[i][j]+dp[j+1][i+k]);

		}

	}

	p(dp[0][n-1]);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define REP(i,n,N) for(int i=n;i<N;i++)

#define p(S) cout<<(S)<<endl

using namespace std;

int dp[1001][1001];

int w[100010],c[100010];

int sumw[100010];

int main(){

	int n;

	cin>>n;

	REP(i,0,n) {

		cin>>c[i]>>w[i];

		if(i>0)	sumw[i]=sumw[i-1]+w[i];

		else sumw[i]=w[i];

	}

	REP(i,0,1001) REP(j,i,1001) dp[i][j]=j-i+1;

	REP(i,0,n-1)  if(c[i]>=w[i+1]||c[i+1]>=w[i]) dp[i][i+1]=1;





	for(int k=2;k<n;k++){

		for(int i=0;i+k<n;i++){

			if((dp[i+1][i+k]==1&&c[i]>=sumw[i+k]-sumw[i])||(dp[i][i+k-1]==1&&c[i+k]>=sumw[i+k-1]-(i?sumw[i-1]:0)))

				dp[i][i+k]=1;

			else dp[i][i+k]=min(dp[i+1][i+k],dp[i][i+k-1])+1;



			for(int j=i+1;j<i+k;j++)

				dp[i][i+k]=min(dp[i][i+k],dp[i][j]+dp[j+1][i+k]);

		}

	}

	p(dp[0][n-1]);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.0672380443308938x):
#include "bits/stdc++.h"

#define REP(i,n,N) for(int i=(n); i<(N); i++)

#define RREP(i,n,N) for(ll i=(N-1); i>=n; i--)

#define CK(n,a,b) ((a)<=(n)&&(n)<(b))

#define ALL(v) (v).begin(),(v).end()

#define p(s) cout<<(s)<<endl

#define p2(a,b) cout<<(a)<<" "<<(b)<<endl

#define v2(T) vector<vector<T>>

typedef long long ll;

using namespace std;

const ll mod=1e9+7;

const int inf=1e9;



int dp[1010][1010];

int N;

int C[1010], W[1010];

int sum[1010];

int main() {

    cin>>N;

    REP(i,0,N){

        cin>>C[i]>>W[i];

    }

    REP(i,0,N) REP(j,i,N) dp[i][j] = j-i+1;

    REP(i,0,N) sum[i+1] = sum[i] + W[i];

    REP(k,1,N){

        REP(L,0,N-k){

            int R = L + k;

            if(dp[L+1][R]==1 && sum[R+1]-sum[L+1] <= C[L]){

                dp[L][R] = min(dp[L][R], dp[L+1][R]);

            }

            if(dp[L][R-1]==1 && sum[R]-sum[L] <= C[R]){

                dp[L][R] = min(dp[L][R], dp[L][R-1]);

            }

            REP(i,L,R) {

                dp[L][R] = min(dp[L][R], dp[L][i] + dp[i+1][R]);

            }

        }

    }

    p(dp[0][N-1]);



    return 0;

}
// Slower C++ solution:
#include <iostream>



bool solve(int i, int m);

int n, q, A[2000], m[2000];



int main()

{

	using namespace std;

	cin >> n;

	for (int i = 0; i < n; i++)

	{

		cin >> A[i];

	}

	cin >> q;

	for (int i = 0; i < q; i++)

	{

		cin >> m[i];

	}

	for (int i = 0; i < q; i++)

	{

		if (solve(0, m[i]))

		{

			cout << "yes\n";

		}

		else

		{

			cout << "no\n";

		}

	}

	return 0;

}



bool solve(int i, int m)

{

	if (m == 0)

	{

		return true;

	}

	if (i >= n)

	{

		return false;

	}

	return solve(i + 1, m) || solve(i + 1, m - A[i]);

}


// Faster C++ solution for the same problem (measured speedup: 2.0329546066084823x):
#include <cstdio>

#include <cstring>



int n, A[50], dp[21][2001];



int solve(int i, int m)

{

  if (dp[i][m] != -1)

  {

    return dp[i][m];

  }



  if (m == 0)

    dp[i][m] = 1;

  else if (i >= n)

    dp[i][m] = 0;

  else if (solve(i + 1, m))

    dp[i][m] = 1;

  else if (solve(i + 1, m - A[i]))

    dp[i][m] = 1;

  else

    dp[i][m] = 0;



  return dp[i][m];

}



int main()

{

  scanf("%d", &n);

  for (int i = 0; i < n; i++)

  {

    scanf("%d", &A[i]);

  }

  int q, m;

  scanf("%d", &q);

  for (int i = 0; i < q; i++)

  {

    memset(dp, -1, sizeof(dp));

    scanf("%d", &m);

    if (solve(0, m) != 0) printf("yes\n");

    else printf("no\n");

  }

  return 0;

}
// Slower C++ solution:
#include<iostream>



using namespace std;



int A[20], N;



bool exhaustiveSearch(int m, int s, int n){

    if(n==N+1) return false;//it's over

    if(s==m) return true;



    if (exhaustiveSearch(m,s,n+1)) {

        return true;

    }else

    {

        return exhaustiveSearch(m,s+A[n],n+1);

    }

}



int main(){

    int i,q;

    cin >> N;

    for(i=0;i<N;i++) cin>>A[i];

    cin>>q;

    for(i=0;i<q;i++){

        int m;

        cin >> m;

        exhaustiveSearch(m,0,0)?cout<<"yes":cout<<"no";

        cout<<endl;

    }

}


// Faster C++ solution for the same problem (measured speedup: 5.178991027445498x):
#include<stdio.h>



int A[20], N;



bool exhaustiveSearch(int m, int s, int n){

    if(n==N+1) return false;//it's over

    if(s==m) return true;



    if (exhaustiveSearch(m,s,n+1)) {

        return true;

    }else

    {

        return exhaustiveSearch(m,s+A[n],n+1);

    }

}



int main(){

    int i,q;

    scanf("%d",&N);

    for(i=0;i<N;i++) scanf("%d",&A[i]);

    scanf("%d",&q);

    for(i=0;i<q;i++){

        int m;

        scanf("%d",&m);

        exhaustiveSearch(m,0,0)?printf("yes\n"):printf("no\n");

    }

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long int

#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)

#define REP(i,n) FOR(i,0,n)

#define REP1(i,n) FOR(i,1,n)

using namespace std;

 

int A[50], n, memo[50][500];

 

int solve (int i, int m) {

  

  if (m == 0) 

    memo[i][m] = 1;

  else if (i >= n) 

    memo[i][m] = 0;

  else if (solve(i + 1, m))

    memo[i][m] = 1;

  else if (solve(i + 1, m - A[i])) 

    memo[i][m] = 1;

  else 

    memo[i][m] = 0;



  return memo[i][m];

}

 

int main(){

  REP(i, 50) {

    REP(j, 500) {

      memo[i][j] = -1;

    }

  }

  int q, M;

  cin >> n;

  REP(i, n) {

    cin >> A[i];

  }

  cin >> q;

  REP(i, q) {

    cin >> M;

    if (solve(0, M)) cout << "yes" << endl;

    else cout << "no" << endl;

  }

 

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1094170874047204x):
#include<bits/stdc++.h>

#define ll long long int

#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)

#define REP(i,n) FOR(i,0,n)

#define REP1(i,n) FOR(i,1,n)

using namespace std;

 

int A[50], n;

 

int solve (int i, int m) {

  if (m == 0) return 1;

  if (i >= n) return 0;

  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);

  return res;

}

 

int main(){

  int q, M;

  cin >> n;

  REP(i, n) {

    cin >> A[i];

  }

  cin >> q;

  REP(i, q) {

    cin >> M;

    if (solve(0, M)) cout << "yes" << endl;

    else cout << "no" << endl;

  }

 

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define int long long



const int N = 16e3 + 10;

int x, y, _dp[2][2 * N + 100], *dp[2];

string s;

vector <int> vec[2];



void fill_dp(int indx) {

	for (int i = -N + 1; i < N; i++)

		dp[1][i] = 0;

	dp[1][0] = 1;

	

	for (int i = 0; i < vec[indx].size(); i++) {

		int now = (i & 1), prv = (now ^ 1), x = vec[indx][i];

		for (int j = -N + 1; j < N; j++) {

			dp[now][j] = 0;

			if (j - x > -N)

				dp[now][j] = dp[prv][j - x];

			if (j + x < N)

				dp[now][j] = max(dp[now][j], dp[prv][j + x]);

		}

	}

}



int32_t main() {

	ios::sync_with_stdio(0);

	cin.tie(0);

	

	dp[0] = _dp[0] + N + 50;

	dp[1] = _dp[1] + N + 50;

	

	cin >> s >> x >> y;

	while (s.size() && s.back() == 'T')

		s.pop_back();

	if (!s.size())

		return cout << (!x && !y? "Yes\n": "No\n"), 0;

	

	int tmp = 0, indx = 0;

	while (indx < s.size() && s[indx] == 'F')

		tmp++, indx++;

	

	int last = 0, num = 0;

	for (int i = indx; i < s.size(); i++) {

		if (s[i] == 'T')

			vec[num & 1].push_back(last), last = 0, num++;

		else

			last++;

	}

	vec[num & 1].push_back(last);

	

	fill_dp(0);

	if (!dp[((int)vec[0].size() & 1) ^ 1][x - tmp])

		return cout << "No\n", 0;

	fill_dp(1);

	cout << (dp[((int)vec[1].size() & 1) ^ 1][y]? "Yes\n": "No\n");

}

// Faster C++ solution for the same problem (measured speedup: 1.7364351408783316x):
#include <bits/stdc++.h>

using namespace std;



#define MAX_N 8003



bool can(vector <int> v ,int x){

    bitset <MAX_N> bs; bs[0] = 1;

    int tot = 0;

    for(int&i : v)

        bs |= (bs<<i) ,tot += i;

    return !((tot+x)&1) && (tot >= x && bs[(tot-x)/2]);

}



int main()

{

    string s;

    int x ,y;

    cin >> s; s += 'T';

    cin >> x >> y; y = abs(y);



    vector <int> units[2];

    int axis = 0 ,mvs = 0;

    for(int i=0; i<s.size(); i++){

        if(s[i] == 'T'){

            units[axis].push_back(mvs);

            axis ^= 1 ,mvs = 0;

        }

        else

            mvs++;

    }



    x = abs(x-units[0][0]);

    units[0].erase(units[0].begin());

    cout << (can(units[0] ,x) && can(units[1] ,y) ? "Yes" : "No") << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using pii = pair<int, int>;



string s;

int x, y;

int dpx[2][20010], dpy[2][20010];

vector<int> vx, vy;



int main() {

  cin.tie(0);

  ios_base::sync_with_stdio(false);

  cout << fixed << setprecision(10);

  

  cin >> s >> x >> y;

  int l = 0, r = 0, turn = 0;

  while (r < s.size() && s[r] == 'F') r++;

  dpx[0][10000+r-l] = 1;

  dpy[0][10000] = 1;

  l = r;

  while (l < s.size()) {

    while (l < s.size() && s[l] == 'T') l++, r++, turn ^= 1;

    while (r < s.size() && s[r] == 'F') r++;

    if (turn == 0) vx.emplace_back(r-l);

    else vy.emplace_back(r-l);

    l = r;

  }

  for (int i = 0; i < vx.size(); i++) {

    fill_n((int*)dpx[1], 20010, 0);

    for (int j = 0; j < 20010; j++) {

      if (j-vx[i] >= 0) dpx[1][j-vx[i]] |= dpx[0][j];

      if (j+vx[i] < 20010) dpx[1][j+vx[i]] |= dpx[0][j];

    }

    swap(dpx[0], dpx[1]);

  }

  for (int i = 0; i < vy.size(); i++) {

    fill_n((int*)dpy[1], 20010, 0);

    for (int j = 0; j < 20010; j++) {

      if (j-vy[i] >= 0) dpy[1][j-vy[i]] |= dpy[0][j];

      if (j+vy[i] < 20010) dpy[1][j+vy[i]] |= dpy[0][j];

    }

    swap(dpy[0], dpy[1]);

  }

  cout << (dpx[0][10000+x] && dpy[0][10000+y] ? "Yes" : "No") << endl;



  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.126478522401828x):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using pii = pair<int, int>;



string s;

int x, y;

int n;

vector<int> vx, vy;

int fx[2][16010], fy[2][16010];



int main() {

  cin.tie(0);

  ios_base::sync_with_stdio(false);

  cout << fixed << setprecision(10);

  

  cin >> s >> x >> y;

  n = s.size();

  int l, r;

  l = 0, r = 0;

  while (l < n && s[l] == 'F') l++, r++, x--;

  int turn = 0;

  while (l < n) {

    while (l < n && s[l] == 'T') l++, r++, turn ^= 1;

    while (r < n && s[r] == 'F') r++;

    if (r != l) {

      if (turn) vy.emplace_back(r-l);

      else vx.emplace_back(r-l);

    }

    l = r;

  }

  fx[0][8000] = 1;

  fy[0][8000] = 1;

  for (int i = 0; i < vx.size(); i++) {

    fill_n((int*)fx[1], 16010, 0);

    for (int j = 0; j < 16010; j++) {

      if (fx[0][j]) {

        fx[1][j-vx[i]] = 1;

        fx[1][j+vx[i]] = 1;

      }

    }

    swap(fx[0], fx[1]);

  }

  for (int i = 0; i < vy.size(); i++) {

    fill_n((int*)fy[1], 16010, 0);

    for (int j = 0; j < 16010; j++) {

      if (fy[0][j]) {

        fy[1][j-vy[i]] = 1;

        fy[1][j+vy[i]] = 1;

      }

    }

    swap(fy[0], fy[1]);

  }

  cout << (fx[0][x+8000] && fy[0][y+8000] ? "Yes" : "No") << endl;



  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ull = unsigned long long;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

using pli = pair<ll, int>;

using Graph = vector<vector<bool>>;

const int MOD = 1e9 + 7;



bool isreachable(int s, int t, queue<int> &cnt) {

    vector<bool> v(16003);

    v[s + 8000] = true;

    while (!cnt.empty()) {

        int i = cnt.front();

        cnt.pop();

        vector<bool> vtmp(16003);

        for (int j = 0; j <= 16000; ++j) {

            if (j - i >= 0)

                vtmp[j] = v[j - i];

            if (j + i <= 16000)

                vtmp[j] = vtmp[j] | v[j + i];

        }

        swap(v, vtmp);

    }

    return v[t + 8000];

}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);



    string s;

    int x, y;

    cin >> s >> x >> y;



    bool h = true;

    int cnt = 0;

    queue<int> hcnt, vcnt;

    for (int i = 0; i < s.length(); ++i) {

        if (s[i] == 'T') {

            (h ? hcnt : vcnt).push(cnt);

            h ^= 1;

            cnt = 0;

            continue;

        }

        cnt++;

    }

    if (cnt > 0)

        (h ? hcnt : vcnt).push(cnt);



    int ix = hcnt.front(), iy = 0;

    hcnt.pop();



    bool isok = isreachable(ix, x, hcnt) & isreachable(iy, y, vcnt);

    cout << (isok ? "Yes" : "No") << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1091068602896321x):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ull = unsigned long long;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

using pli = pair<ll, int>;

using Graph = vector<vector<bool>>;

const int MOD = 1e9 + 7;



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);



    string s;

    int x, y;

    cin >> s >> x >> y;

    if (s.back() != 'T')

        s.push_back('T');



    bool v = false, ini = false;

    int cnt = 0;

    static bool reachable[2][16003], tmp[2][16003];

    reachable[1][8000] = true;

    for (int i = 0; i < s.length(); ++i) {

        if (s[i] == 'T') {

            if (!ini) {

                reachable[v][8000 + cnt] = true;

                ini = true;

            } else {

                for (int j = 0; j <= 16000; ++j) {

                    if (!reachable[v][j])

                        continue;

                    if (j - cnt >= 0)

                        tmp[v][j - cnt] = true;

                    if (j + cnt <= 16000)

                        tmp[v][j + cnt] = true;

                    reachable[v][j] = false;

                }

                swap(reachable[v], tmp[v]);

            }

            v ^= 1;

            cnt = 0;

            continue;

        }

        cnt++;

    }



    cout << (reachable[0][8000 + x] & reachable[1][8000 + y] ? "Yes" : "No") << endl;

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ull = unsigned long long;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

using pli = pair<ll, int>;

using Graph = vector<vector<bool>>;

const int MOD = 1e9 + 7;



bool isreachable(int s, int t, queue<int> &cnt) {

    vector<bool> v(16003);

    v[s + 8000] = true;

    while (!cnt.empty()) {

        int i = cnt.front();

        cnt.pop();

        vector<bool> vtmp(16003);

        for (int j = 0; j <= 16000; ++j) {

            if (j - i >= 0)

                vtmp[j] = v[j - i];

            if (j + i <= 16000)

                vtmp[j] = vtmp[j] | v[j + i];

        }

        swap(v, vtmp);

    }

    return v[t + 8000];

}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);



    string s;

    int x, y;

    cin >> s >> x >> y;



    bool h = true;

    int cnt = 0;

    queue<int> hcnt, vcnt;

    for (int i = 0; i < s.length(); ++i) {

        if (s[i] == 'T') {

            (h ? hcnt : vcnt).push(cnt);

            h ^= 1;

            cnt = 0;

            continue;

        }

        cnt++;

    }

    if (cnt > 0)

        (h ? hcnt : vcnt).push(cnt);



    int ix = hcnt.front(), iy = 0;

    hcnt.pop();



    bool isok = isreachable(ix, x, hcnt) & isreachable(iy, y, vcnt);

    cout << (isok ? "Yes" : "No") << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1959286885141747x):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ull = unsigned long long;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

using pli = pair<ll, int>;

using Graph = vector<vector<bool>>;

const int MOD = 1e9 + 7;



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);



    string s;

    int x, y;

    cin >> s >> x >> y;

    if (s.back() != 'T')

        s.push_back('T');



    bool v = false, ini = false;

    int cnt = 0;

    vector<bitset<16000>> dp(2);

    dp[1][8000] = true;

    for (int i = 0; i < s.length(); ++i) {

        if (s[i] == 'T') {

            if (!ini) {

                dp[v][8000 + cnt] = true;

                ini = true;

            } else

                dp[v] = (dp[v] >> cnt) | (dp[v] << cnt);

            v ^= 1;

            cnt = 0;

            continue;

        }

        cnt++;

    }



    cout << (dp[0][8000 + x] & dp[1][8000 + y] ? "Yes" : "No") << endl;

    return 0;

}