stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

ll wq[100003];

int main()

{

    int g,t;

    ll re=1,lm=1e18;

    scanf("%d",&t);

    for(g=0;g<t;g++)

        scanf("%lld",&wq[g]);

    for(g=0;g<t;g++)if(!wq[g]){

        printf("0\n");

        return 0;

    }

    for(g=0;g<t;g++){

        if(wq[g]<=(lm/re))

            re*=wq[g];

        else{

            printf("-1\n");

            return 0;

        }

    }

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

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

int main (){

    long long int N;

    long long int total=1;

    

    scanf("%lld",&N);

    long long int A[N]; 

    

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

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

    }

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

        if(A[j] == 0){  

            printf("0"); 

            return 0;

        }

    }

    for(int k=0;k<N;k++){

        if(A[k]<=1000000000000000000/total){

            total = total*A[k];

            

        } else {

            printf("-1");

            return 0;

        }

    }

    printf("%lld", total);

    

    

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define c 1000000000000000000

#define ll long long int

int main()

{

    ll n,i,count=1,flag=0;

    cin>>n;

    ll a[n+1];

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

    {

        cin>>a[i];

        if(a[i]==0)

            flag=1;

    }

    ll sum=a[0];

    if(flag==0) {

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

            if (a[i] <= c / sum) {

                sum=sum*a[i];

                count++;

            } else

            {

                cout<<"-1"<<endl;

                break;

            }

        }

        if(count==n)

            cout<<sum<<endl;

    }

    else

        cout<<"0"<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

int main (){

    long long int N;

    long long int total=1;

    

    scanf("%lld",&N);

    long long int A[N]; 

    

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

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

    }

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

        if(A[j] == 0){  

            printf("0"); 

            return 0;

        }

    }

    for(int k=0;k<N;k++){

        if(A[k]<=1000000000000000000/total){

            total = total*A[k];

            

        } else {

            printf("-1");

            return 0;

        }

    }

    printf("%lld", total);

    

    

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//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 <= 1000000000000000000/ans ? ans *= a : flag = 1;

    }

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

	return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



int main() {

  int n;

  scanf("%d", &n);

  long long int arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;

  

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

    scanf("%lld", &arr[i]);

    flag = (arr[i] > max) ? 1 : flag;

    prod *= arr[i];

    (arr[i]) ? max /= arr[i] : zero = 1;

  }



  (zero) ? printf("0") : ((flag) ? printf("-1") : printf("%lld\n", prod));

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



long long eps = 1000000000000000000;

long long a[100050];



int main()

{

	int n;

	cin>>n;

	int flag = 0;

	long long ans = 1;

	

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

		cin>>a[i];

	}

	

	sort(a,a+n);

	

	if(a[0] == 0) cout<<0<<endl;

	else{

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

			if(a[i] > eps/ans){

				cout<<-1<<endl;

				return 0;

			}

			else ans *= a[i];

		}

		cout<<ans<<endl;

	}

	

	return 0;

} 

// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 100001

typedef long long LL;



LL a[N];



LL read()

{

	char c;

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

	LL x = c - 48;

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

	return x;

}



int main()

{		

	int n, i;

	LL m = 1000000000000000000, ans = 1;

		

	scanf("%d", &n);

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

		if(!(a[i] = read())) ans = 0;

	}

	if(!ans) puts("0");

	else{

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

			m /= a[i];

			if(!m){

				ans = -1;

				break;

			}

			ans *= a[i];

		}

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

	}

		

			

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 100001

typedef long long LL;



LL a[N];



LL read()

{

	char c;

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

	LL x = c - 48;

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

	return x;

}



int main()

{		

	int n, i;

	LL m = 1000000000000000000, ans = 1;

		

	scanf("%d", &n);

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

		if(!(a[i] = read())) ans = 0;

	}

	if(!ans) puts("0");

	else{

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

			m /= a[i];

			if(!m){

				ans = -1;

				break;

			}

			ans *= a[i];

		}

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

	}

		

			

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 100001

typedef long long LL;



LL a[N];



LL read()

{

	char c;

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

	LL x = c - 48;

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

	return x;

}



int main()

{		

	int n, i;

	LL m = 1000000000000000000, ans = 1;

		

	scanf("%d", &n);

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

		if(!(a[i] = read())) ans = 0;

	}

	if(!ans) puts("0");

	else{

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

			m /= a[i];

			if(!m){

				ans = -1;

				break;

			}

			ans *= a[i];

		}

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

	}

		

			

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

    }

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 100001

typedef long long LL;



LL a[N];



LL read()

{

	char c;

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

	LL x = c - 48;

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

	return x;

}



int main()

{		

	int n, i;

	LL m = 1000000000000000000, ans = 1;

		

	scanf("%d", &n);

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

		if(!(a[i] = read())) ans = 0;

	}

	if(!ans) puts("0");

	else{

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

			m /= a[i];

			if(!m){

				ans = -1;

				break;

			}

			ans *= a[i];

		}

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

	}

		

			

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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 );

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 100001

typedef long long LL;



LL a[N];



LL read()

{

	char c;

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

	LL x = c - 48;

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

	return x;

}



int main()

{		

	int n, i;

	LL m = 1000000000000000000, ans = 1;

		

	scanf("%d", &n);

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

		if(!(a[i] = read())) ans = 0;

	}

	if(!ans) puts("0");

	else{

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

			m /= a[i];

			if(!m){

				ans = -1;

				break;

			}

			ans *= a[i];

		}

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

	}

		

			

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 100001

typedef long long LL;



LL a[N];



LL read()

{

	char c;

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

	LL x = c - 48;

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

	return x;

}



int main()

{		

	int n, i;

	LL m = 1000000000000000000, ans = 1;

		

	scanf("%d", &n);

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

		if(!(a[i] = read())) ans = 0;

	}

	if(!ans) puts("0");

	else{

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

			m /= a[i];

			if(!m){

				ans = -1;

				break;

			}

			ans *= a[i];

		}

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

	}

		

			

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//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;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main () {

long long int t, sum =1;

scanf("%lld",&t);



long long int n[t];

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

    scanf("%lld",&n[i]);

}

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

  if (n[i] ==0 ){

    printf("0");

    return 0;

  }



}

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

  if(n[i] <=1000000000000000000 /sum){

    sum *= n[i];

  }

  else{

    printf("-1");

    return 0;

  }

}

printf("%lld",sum);

return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#define N 16005

using namespace std;



int x, y, c;

bool d, t[2][N], v[2][N];

string s;

int main()

{

	int i, j;

	cin >> s >> x >> y;

	v[1][8000] = 1;

	for (i = 0; s[i] == 'F'; i++);

	v[0][8000 + i] = 1;

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

		if (s[i] == 'F') c++;

		else {

			for (j = c; j < N - c; j++) {

				t[d][j - c] = max(t[d][j - c], v[d][j]);

				t[d][j + c] = max(t[d][j + c], v[d][j]);

			}

			for (j = 0; j < N; j++) v[d][j] = t[d][j], t[d][j] = 0;

			c = 0;

			d = !d;

		}

	}

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

    return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#include <bitset>

#define M 8005

using namespace std;



int x, y, z, c;

string s;

bitset<M * 2> bs[2];

int main() {

	int i;

	cin >> s >> x >> y;

	for (i = 0; s[i] == 'F'; i++);

	bs[0][i + M] = bs[1][M] = 1;

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

		if (s[i] == 'F') c++;

		else bs[z] = (bs[z] << c) | (bs[z] >> c), z = !z, c = 0;

	}

	cout << (bs[0][x + M] & bs[1][y + M] ? "Yes" : "No");

	return 0;

}

// Fastest known solution for this problem: