stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

using namespace std;

int main()

{

	int n,i;

	cin>>n;

	long long ans=1;

	long long a[n];

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

		cin>>a[i];

		if(a[i]==0){

			cout<<0;

			return 0;

		}

	}

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

		if(1000000000000000000/ans<a[i]){

			cout<<-1;

			return 0;

		}

		ans*=a[i];

	}

	cout<<ans;

}

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



int main (){

	

	int n;	// zero mengecek kalo perkaliannya dengan 0

	long long int a, max = 1e18, hasil = 1, flag = 0, zero = 0; 

	

	scanf("%d",&n);

	

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

		scanf("%lld",&a);

		flag =(a > max) ? 1 : flag; // penanda kalo ada 0

		hasil *= a;

		a != 0 ? max /= a : zero = 1;

	}



	if(zero == 1){

		printf("0\n");

	}else if (flag == 1){

		printf("-1\n");

	}else{

		printf("%lld\n",hasil);

	}

return 0;

}
// Slower C++ solution:
#pragma GCC optimize("O3")

#pragma G++ optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define ld long double

#define ull unsigned ll

#define mst(a, b) memset((a), (b), sizeof(a))

#define mp(a, b) make_pair(a, b)

#define pi acos(-1)

#define pii pair<int, int>

#define pll pair<ll, ll>

#define pdd pair<double, double>

#define vi vector<int>

#define vl vector<ll>

#define pb push_back

#define lson l, mid, rt << 1

#define rson mid + 1, r, rt << 1 | 1

const int INF = 0x3f3f3f3f;

const double eps = 1e-8;

const int maxn = 1e3 + 7;

const int maxm = 1e5 + 7;

const int mod = 1e9 + 7;

#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

ll a[maxm];

__int128_t ans;

int main()

{

    IO;

    int n;

    cin>>n;

    ans=1;

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

    {

        cin>>a[i];

        if (a[i]==0)

        {

            cout<<0<<endl;

            return 0;

        }

    }

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

    {

        ans*=a[i];

        if (ans>(ll)1000000000000000000)

        {

            cout<<-1<<endl;

            return 0;

        }

    }

    cout<<(ll)ans<<endl;

    return 0;

}

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



int main (){

	

	int n;	// zero mengecek kalo perkaliannya dengan 0

	long long int a, max = 1e18, hasil = 1, flag = 0, zero = 0; 

	

	scanf("%d",&n);

	

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

		scanf("%lld",&a);

		flag =(a > max) ? 1 : flag; // penanda kalo ada 0

		hasil *= a;

		a != 0 ? max /= a : zero = 1;

	}



	if(zero == 1){

		printf("0\n");

	}else if (flag == 1){

		printf("-1\n");

	}else{

		printf("%lld\n",hasil);

	}

return 0;

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

using namespace std;

int main()

{

    int n;

    cin >> n;

    long long a[n+1];

    int z = 0;

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

    {

        cin >> a[i];

    }

    sort(a, a+n);

    if(a[0] == 0)

        cout << "0" << endl;

    else

    {

        long long ans = 1;

        long long z = 1000000000000000000/n;



        int flag = 0;

        for(int i = n - 1; i >= 0; i--)

        {

            if(a[i] > z)

            {

                flag = 1;

                break;

            }

            ans *= a[i];

            z = 1000000000000000000/ans;

        }

        if(flag == 1 || ans > 1000000000000000000)

            cout << "-1" << endl;

        else

            cout << ans << endl;

    }

}


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



int main (){

	

	int n;	// zero mengecek kalo perkaliannya dengan 0

	long long int a, max = 1e18, hasil = 1, flag = 0, zero = 0; 

	

	scanf("%d",&n);

	

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

		scanf("%lld",&a);

		flag =(a > max) ? 1 : flag; // penanda kalo ada 0

		hasil *= a;

		a != 0 ? max /= a : zero = 1;

	}



	if(zero == 1){

		printf("0\n");

	}else if (flag == 1){

		printf("-1\n");

	}else{

		printf("%lld\n",hasil);

	}

return 0;

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

using namespace std;

long long a [100010];

int main (){

int n;

scanf("%d",&n);

for(int i=0;i<n;i++) scanf("%lld",&a[i]);

int zero =0;



for(int i=0;i<n;i++)if(a[i]==0) zero ++;

if(zero >0){

// a[i] contains 0

printf("0\n");

return 0;

}

long long prod =1;

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

if(a[i ] <=1000000000000000000/ prod ){

// This condition is equivalent to prod*a[i] <=10ˆ18

prod *=a[i];

}else{

printf("-1\n");

return 0;

}

}

printf("%lld\n",prod );

}


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



int main (){

	

	int n;	// zero mengecek kalo perkaliannya dengan 0

	long long int a, max = 1e18, hasil = 1, flag = 0, zero = 0; 

	

	scanf("%d",&n);

	

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

		scanf("%lld",&a);

		flag =(a > max) ? 1 : flag; // penanda kalo ada 0

		hasil *= a;

		a != 0 ? max /= a : zero = 1;

	}



	if(zero == 1){

		printf("0\n");

	}else if (flag == 1){

		printf("-1\n");

	}else{

		printf("%lld\n",hasil);

	}

return 0;

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

using namespace std;

int main ()

{

    int n,Count=0;

    long long int a [100010];

    cin>>n;

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

    {

        cin>>a[i];

        if(a[i]==0){Count++;}

    }

    if(Count>0){cout<<0<<endl;return 0;}

    long long int sum=1;

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

    {

        if(a[i]<=1000000000000000000/sum )

        {

            sum=sum*a[i];

        }

        else

        {

           cout<<-1<<endl;

            return 0;

        }

    }

   cout<<sum<<endl;

}


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



int main (){

	

	int n;	// zero mengecek kalo perkaliannya dengan 0

	long long int a, max = 1e18, hasil = 1, flag = 0, zero = 0; 

	

	scanf("%d",&n);

	

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

		scanf("%lld",&a);

		flag =(a > max) ? 1 : flag; // penanda kalo ada 0

		hasil *= a;

		a != 0 ? max /= a : zero = 1;

	}



	if(zero == 1){

		printf("0\n");

	}else if (flag == 1){

		printf("-1\n");

	}else{

		printf("%lld\n",hasil);

	}

return 0;

}
// Slower C++ solution:
//sppsfver - 05.08.2020

#include <bits/stdc++.h>

using namespace std;



using ll = long long;

using pll = pair <ll, ll>;



ll n, a, ans = 1;

bool flag, zero;



int main() {

	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);



    cin >> n;

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

        cin >> a;

        if (a == 0) return cout << 0 << endl, 0;

        a <= (ll)(1e18)/ans ? ans *= a : flag = 1;

    }

    cout << (flag ? -1 : ans) << endl;

	return 0;

}


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



int main (){

	

	int n;	// zero mengecek kalo perkaliannya dengan 0

	long long int a, max = 1e18, hasil = 1, flag = 0, zero = 0; 

	

	scanf("%d",&n);

	

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

		scanf("%lld",&a);

		flag =(a > max) ? 1 : flag; // penanda kalo ada 0

		hasil *= a;

		a != 0 ? max /= a : zero = 1;

	}



	if(zero == 1){

		printf("0\n");

	}else if (flag == 1){

		printf("-1\n");

	}else{

		printf("%lld\n",hasil);

	}

return 0;

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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

using namespace std;

#define PI  3.14159265358979323846

#define lp(i,n) for(int i = 0; i <n;i++)

#define rlp(i,n) for(int i = int(n);i >= 0;i--)

#define range1(i,a,b,c) for(int i = int(a);i <= int(b);i+=int(c))

#define range(i,a,b) for(int i = int(a);i <= int(b);i++)

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

#define pb push_back

#define MP make_pair

#define fr first

#define sc second

#define sz(v) ((int)((v).size()))

#define sfi1(v) scanf("%d",&v)

#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)

#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)

#define sfll1(v) scanf("%I64d",&v);

#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)

#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)

typedef long long ll;

typedef unsigned long long ull;

typedef vector<int> vi;

typedef vector<pair<int, int> > vii;

typedef pair<int, int> pii;

template<class T> using ordered_set=tree<T,

null_type,

less<T>,

rb_tree_tag,

tree_order_statistics_node_update>;

const ll MOD = 1e9 + 7;

const int OO = (int)1e6;

const int N = (int)1e7;

int dx[] = {0,0,-1,1};

int dy[] = {1,-1,0,0};

void init(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

int a[N];

void _run(){

   int n;

   scanf("%d",&n);

   ll sum =0;

   lp(i,n){

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

       sum+=a[i];

   }

   ll total = 0;

   lp(i,n){

        sum-=a[i];

       total=total%MOD+(sum%MOD*a[i]%MOD)%MOD;

      

   }

   cout<<total<<endl;

}

int main() {

	#   ifdef LOCAL_PROJECT

        freopen("in.txt", "r", stdin);

    #   endif

    int t=1;

    // scanf("%d",&t);

    while(t--)_run();

    

    return 0;

}

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

#define M 1000000007

typedef long long LL;



int read()

{

	char c;

	while((c = getchar()) < 48 || c > 57);

	int x = c - 48;

	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;

	return x;

}



int main()

{		

	int n, s, i, x;

	LL ss = 0;

	

	n = read();

	s = read();

	for(i = 1; i < n; i++){

		x = read();

		ss += (LL)x * (LL)s % M;

		s += x;

		if(s >= M) s -= M;

	}

	printf("%lld\n", ss % M);

				

	return 0;

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

using namespace std;

long L,A,B,M;

long power(long a,long b){return b?power(a*a%M,b/2)*(b%2?a:1)%M:1;}

long ten[99];

long n;

long sum(long k)

{

	long ret=0,p=1;

	for(int i=61;i--;)

	{

		if(k>>i&1)

		{

			(ret+=ten[i]*p)%=M;

			p=p*power(power(10,n),1LL<<i)%M;

		}

	}

	return ret;

}

long iten[99];

long isum(long k)

{

	long ret=0,p=1,g=0;

	for(int i=61;i--;)

	{

		if(k>>i&1)

		{

			(ret+=(iten[i]+ten[i]*g)%M*p)%=M;

			p=p*power(power(10,n),1LL<<i)%M;

			g=(g+(1LL<<i))%M;

		}

	}

	return ret;

}

long cnt[18],SUM[18];

main()

{

	cin>>L>>A>>B>>M;

	long pre=0,tmpten=1;

	long ans=0;

	for(n=0;n<18;n++)

	{

		long l=pre,r=L;

		tmpten*=10;

		while(r-l>1)

		{

			long m=(l+r)/2;

			if(A+B*m<tmpten)l=m;

			else r=m;

		}

		long k=l-pre;

		if(k<0||l>=L||A+B*l>=tmpten)

		{

			cnt[n]=1;

			continue;

		}

		pre=l+1;

		n++;

		ten[0]=1;

		for(int i=1;i<61;i++)ten[i]=(power(power(10,n),(1LL<<i-1))+1)%M*ten[i-1]%M;

		iten[0]=0;

		for(int i=1;i<61;i++)

		{

			iten[i]=((power(power(10,n),(1LL<<i-1))+1)%M*iten[i-1]+(1LL<<i-1)%M*ten[i-1]%M*power(power(10,n),(1LL<<i-1)))%M;

		}

		cnt[n-1]=power(power(10,n),k+1);

		SUM[n-1]=(((A+B*l)%M*sum(k+1)%M-B%M*isum(k+1))%M+M)%M;

		n--;

	}

	long p=1;

	for(int i=18;i--;)

	{

		ans=(ans+SUM[i]*p)%M;

		p=p*cnt[i]%M;

	}

	cout<<ans<<endl;

}


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

using namespace std;

long L,A,B,M;

long power(long a,long b){return b?power(a*a%M,b/2)*(b%2?a:1)%M:1;}

long ten[99],sten[99],iten[99];

long n;

long sum(long k)

{

	long ret=0,p=1;

	for(int i=61;i--;)

	{

		if(k>>i&1)

		{

			(ret+=sten[i]*p)%=M;

			p=p*ten[i]%M;

		}

	}

	return ret;

}

long isum(long k)

{

	long ret=0,p=1,g=0;

	for(int i=61;i--;)

	{

		if(k>>i&1)

		{

			(ret+=(iten[i]+sten[i]*g)%M*p)%=M;

			p=p*ten[i]%M;

			g=(g+(1LL<<i))%M;

		}

	}

	return ret;

}

long cnt[18],SUM[18];

main()

{

	cin>>L>>A>>B>>M;

	long pre=0,tmpten=1;

	long ans=0;

	for(n=1;n<=18;n++)

	{

		cnt[n-1]=1;

		long l=pre,r=L;

		tmpten*=10;

		while(r-l>1)

		{

			long m=(l+r)/2;

			if(A+B*m<tmpten)l=m;

			else r=m;

		}

		long k=l-pre;

		if(k<0||l>=L||A+B*l>=tmpten)

		{

			continue;

		}

		pre=l+1;

		ten[0]=tmpten%M;

		sten[0]=1;

		iten[0]=0;

		if(k+1&1)cnt[n-1]=tmpten%M;

		for(int i=1;i<61;i++)

		{

			ten[i]=ten[i-1]*ten[i-1]%M;

			sten[i]=(ten[i-1]+1)%M*sten[i-1]%M;

			iten[i]=((ten[i-1]+1)%M*iten[i-1]+(1LL<<i-1)%M*sten[i-1]%M*ten[i-1])%M;

			if(k+1>>i&1)cnt[n-1]=cnt[n-1]*ten[i]%M;

		}

		SUM[n-1]=(((A+B*l)%M*sum(k+1)%M-B%M*isum(k+1))%M+M)%M;

	}

	long p=1;

	for(int i=18;i--;)

	{

		ans=(ans+SUM[i]*p)%M;

		p=p*cnt[i]%M;

	}

	cout<<ans<<endl;

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

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    string s;

    cin >> s;



    s.push_back('T');

    int n = s.size();



    int x, y;

    cin >> x >> y;



    vector<int> a[2];

    int c = 0, d = 0, f = 0;

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

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

            c++;

        } else {

            if (f == 0) {

                x -= c;

                f = 1;

            } else {

                a[d].push_back(c);

            }

            c = 0;

            d ^= 1;

        }

    }



    int b = 0;

    for (int d = 0; d < 2; d++) {

        vector<int> dp(20000), h(20000);

        dp[10000] = 1;



        int m = a[d].size();

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

            int a1 = a[d][i];

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

                h[j] = 0;

            }

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

                if (dp[j]) {

                    h[j - a1] = 1;

                    h[j + a1] = 1;

                }

            }

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

                dp[j] = h[j];

            }

        }



        int z = d == 0 ? x : y;

        if (dp[z + 10000]) b++;

    }



    cout << (b == 2 ? "Yes" : "No") << endl;



    return 0;

}

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

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    string s;

    cin >> s;



    s.push_back('T');

    int n = s.size();



    int x, y;

    cin >> x >> y;



    vector<int> a[2];

    int c = 0, d = 0, f = 0;

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

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

            c++;

        } else {

            if (f == 0) {

                x -= c;

                f = 1;

            } else {

                a[d].push_back(c);

            }

            c = 0;

            d ^= 1;

        }

    }



    int b = 0;

    for (int d = 0; d < 2; d++) {

        vector<int> dp(8000);

        dp[0] = 1;



        int m = a[d].size();

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

            int a1 = a[d][i];

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

                if (dp[j] & 1) {

                    dp[abs(j - a1)] |= 2;

                    dp[j + a1] |= 2;

                }

            }

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

                dp[j] >>= 1;

            }

        }



        if (dp[abs(d == 0 ? x : y)]) b++;

    }



    cout << (b == 2 ? "Yes" : "No") << endl;



    return 0;

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

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    string s;

    cin >> s;



    s.push_back('T');

    int n = s.size();



    int x, y;

    cin >> x >> y;



    vector<int> a[2];

    int c = 0, d = 0, f = 0;

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

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

            c++;

        } else {

            if (f == 0) {

                x -= c;

                f = 1;

            } else {

                a[d].push_back(c);

            }

            c = 0;

            d ^= 1;

        }

    }



    int b = 0;

    for (int d = 0; d < 2; d++) {

        vector<int> dp(20000), h(20000);

        dp[10000] = 1;



        int m = a[d].size();

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

            int a1 = a[d][i];

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

                h[j] = 0;

            }

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

                if (dp[j]) {

                    h[j - a1] = 1;

                    h[j + a1] = 1;

                }

            }

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

                dp[j] = h[j];

            }

        }



        int z = d == 0 ? x : y;

        if (dp[z + 10000]) b++;

    }



    cout << (b == 2 ? "Yes" : "No") << endl;



    return 0;

}

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

#include <vector>

#include <string>

#include <algorithm>

#include <array>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



void dfs(vector<array<int8_t, 8000>>& dp, const vector<int>& a, int i, int z) {

    if (dp[i][z]) return; else dp[i][z] = 1;

    if (--i >= 0) {

        dfs(dp, a, i, abs(z - a[i]));

        dfs(dp, a, i, z + a[i]);

    }

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    string s;

    cin >> s;



    s.push_back('T');

    int n = s.size();



    int x, y;

    cin >> x >> y;



    vector<int> a[2];

    int c = 0, d = 0, f = 0;

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

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

            c++;

        } else {

            if (f == 0) {

                x -= c;

                f = 1;

            } else {

                a[d].push_back(c);

            }

            c = 0;

            d ^= 1;

        }

    }



    int b = 0;

    for (int d = 0; d < 2; d++) {

        int m = a[d].size();

        vector<array<int8_t, 8000>> dp(m + 1);

        dfs(dp, a[d], m, 0);



        if (dp[0][abs(d == 0 ? x : y)]) b++;

    }



    cout << (b == 2 ? "Yes" : "No") << endl;



    return 0;

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

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    string s;

    cin >> s;



    s.push_back('T');

    int n = s.size();



    int x, y;

    cin >> x >> y;



    vector<int> a[2];

    int c = 0, d = 0, f = 0;

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

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

            c++;

        } else {

            if (f == 0) {

                x -= c;

                f = 1;

            } else {

                a[d].push_back(c);

            }

            c = 0;

            d ^= 1;

        }

    }



    int b = 0;

    for (int d = 0; d < 2; d++) {

        vector<int> dp(20000), h(20000);

        dp[10000] = 1;



        int m = a[d].size();

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

            int a1 = a[d][i];

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

                h[j] = 0;

            }

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

                if (dp[j]) {

                    h[j - a1] = 1;

                    h[j + a1] = 1;

                }

            }

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

                dp[j] = h[j];

            }

        }



        int z = d == 0 ? x : y;

        if (dp[z + 10000]) b++;

    }



    cout << (b == 2 ? "Yes" : "No") << endl;



    return 0;

}

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

#include <vector>

#include <string>

#include <algorithm>

#include <bitset>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



void dfs(vector<bitset<8000>>& dp, const vector<int>& a, int i, int z) {

    if (dp[i][z]) return; else dp[i][z] = true;

    if (--i >= 0) {

        dfs(dp, a, i, abs(z - a[i]));

        dfs(dp, a, i, z + a[i]);

    }

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    string s;

    cin >> s;



    s.push_back('T');

    int n = s.size();



    int x, y;

    cin >> x >> y;



    vector<int> a[2];

    int c = 0, d = 0, f = 0;

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

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

            c++;

        } else {

            if (f == 0) {

                x -= c;

                f = 1;

            } else {

                a[d].push_back(c);

            }

            c = 0;

            d ^= 1;

        }

    }



    int b = 0;

    for (int d = 0; d < 2; d++) {

        int m = a[d].size();

        vector<bitset<8000>> dp(m + 1);

        dfs(dp, a[d], m, 0);



        if (dp[0][abs(d == 0 ? x : y)]) b++;

    }



    cout << (b == 2 ? "Yes" : "No") << endl;



    return 0;

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

#include <vector>

#include <string>

#include <algorithm>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    string s;

    cin >> s;



    s.push_back('T');

    int n = s.size();



    int x, y;

    cin >> x >> y;



    vector<int> a[2];

    int c = 0, d = 0, f = 0;

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

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

            c++;

        } else {

            if (f == 0) {

                x -= c;

                f = 1;

            } else {

                a[d].push_back(c);

            }

            c = 0;

            d ^= 1;

        }

    }



    int b = 0;

    for (int d = 0; d < 2; d++) {

        vector<int> dp(20000), h(20000);

        dp[10000] = 1;



        int m = a[d].size();

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

            int a1 = a[d][i];

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

                h[j] = 0;

            }

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

                if (dp[j]) {

                    h[j - a1] = 1;

                    h[j + a1] = 1;

                }

            }

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

                dp[j] = h[j];

            }

        }



        int z = d == 0 ? x : y;

        if (dp[z + 10000]) b++;

    }



    cout << (b == 2 ? "Yes" : "No") << endl;



    return 0;

}

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

#include <vector>

#include <string>

#include <algorithm>

#include <bitset>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    string s;

    cin >> s;



    s.push_back('T');

    int n = s.size();



    int x, y;

    cin >> x >> y;



    vector<int> a[2];

    int c = 0, d = 0, f = 0;

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

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

            c++;

        } else {

            if (f == 0) {

                x -= c;

                f = 1;

            } else {

                a[d].push_back(c);

            }

            c = 0;

            d ^= 1;

        }

    }



    int b = 0;

    for (int d = 0; d < 2; d++) {

        bitset<8000> bs;

        bs.set(0);



        int m = a[d].size();

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

            int a1 = a[d][j];

            bs = bs >> a1 | bs << a1;

        }



        int z = abs(d == 0 ? x : y);

        if (z < 8000 && bs[z]) b++;

    }



    cout << (b == 2 ? "Yes" : "No") << endl;



    return 0;

}