#include #include using namespace std; using namespace atcoder; constexpr int mod = 998244353; long long fac[1000005], finv[1000005], inv[1000005]; void COMinit() { fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1; for (int i = 2; i < 1000005; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } long long COM(int n, int k){ if (n == k) return 1; if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } long long modpow(long long a,long long b) { long long ans = 1; while(b) { if(b & 1) { (ans *= a) %= mod; } (a *= a) %= mod; b /= 2; } return ans; } int main() { string S; int A,B,C; cin >> S >> A >> B >> C; int a = 0,b = 0,c = 0; for(int i = 0; i < S.size(); i++) { if(S[i] == 'a') a++; if(S[i] == 'b') b++; if(S[i] == 'c') c++; } COMinit(); A -= a; B -= b; C -= c; vectortmp1(A+B+1); for(int i = 0; i <= A+B; i++) { tmp1[i] = COM(i+c-1,c-1)*COM(C+a+b+A+B-i,a+b+A+B-i)%mod; if(i) { tmp1[i] += tmp1[i-1]; if(tmp1[i] >= mod) tmp1[i] -= mod; } } vectortmp2(B+1),tmp3(A+1); for(int i = 0; i <= B; i++) { tmp2[i] = modpow(fac[i],mod-2)*COM(B-i+a-1,a-1)%mod; } for(int i = 0; i <= A; i++) { tmp3[i] = modpow(fac[i],mod-2)*COM(A-i+b-1,b-1)%mod; } vectortmp4 = convolution(tmp2,tmp3); for(int i = 0; i <= A+B; i++) { tmp4[i] *= fac[i]; tmp4[i] %= mod; } int ans = 0; for(int i = 0; i <= A+B; i++) { ans += 1ll*tmp1[i]*tmp4[i]%mod; if(ans >= mod) ans -= mod; } cout << ans << endl; }