AtCoder problem 065

C++ solution:
#include <atcoder/all>

#include <iostream>

#include <vector>

using namespace std;



long long mod = 998244353;

long long fact[1 << 19], inv[1 << 19];



long long modpow(long long a, long long b, long long m) {

	long long p = 1, q = a;

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

		if ((b & (1LL << i)) != 0LL) {

			p *= q; p %= m;

		}

		q *= q; q %= m;

	}

	return p;

}



long long Div(long long a, long long b, long long m) {

	return (a * modpow(b, m - 2, m)) % m;

}



long long ncr(long long n, long long r) {

	if (n < r || r < 0) return 0;

	return (fact[n] * inv[r] % mod) * inv[n - r] % mod;

}



void init() {

	fact[0] = 1LL;

	for (int i = 1; i <= 500000; i++) fact[i] = (1LL * i * fact[i - 1]) % mod;

	for (int i = 0; i <= 500000; i++) inv[i] = Div(1, fact[i], mod);

}



long long R, G, B, K;

long long X, Y, Z;

long long ar[1 << 19], ag[1 << 19], ab[1 << 19];



int main() {

	init();



	// Step #1. “ü—Í

	cin >> R >> G >> B >> K;

	cin >> X >> Y >> Z;



	// Step #2. ‘O�ˆ—�

	long long R_left = K - Y, R_right = R;

	long long G_left = K - Z, G_right = G;

	long long B_left = K - X, B_right = B;

	for (int i = 0; i <= R; i++) ar[i] = ncr(R, i);

	for (int i = 0; i <= G; i++) ag[i] = ncr(G, i);

	for (int i = 0; i <= B; i++) ab[i] = ncr(B, i);



	// Step #3. FFT

	vector<long long> p1(R + 1, 0), p2(G + 1, 0), p3;

	for (int i = R_left; i <= R_right; i++) p1[i] = ar[i];

	for (int i = G_left; i <= G_right; i++) p2[i] = ag[i];

	p3 = atcoder::convolution(p1, p2);



	// Step #4. “š‚¦‚ğ‹�‚ß‚é

	long long Answer = 0;

	for (int i = B_left; i <= B_right; i++) {

		long long ret1 = 0, ret2 = ab[i];

		if (0 <= K - i && K - i <= (int)p3.size()) ret1 = p3[K - i];

		Answer += ret1 * ret2;

		Answer %= mod;

	}

	cout << Answer << endl;

	return 0;

}


Python solution: mod = 998244353
g = 3
ginv = 332748118
W = [pow(g, (mod-1)>>i, mod) for i in range(24)]
Winv = [pow(ginv, (mod-1)>>i, mod) for i in range(24)]

def fft(k,f):
    for l in range(k,0,-1):
        d = 1 << l - 1
        U = [1]
        for i in range(d):
            U.append(U[-1]*W[l]%mod)
        for i in range(1<<k - l):
            for j in range(d):
                s = i*2*d + j
                f[s],f[s+d] = (f[s]+f[s+d])%mod, U[j]*(f[s]-f[s+d])%mod

def fftinv(k,f):
    for l in range(1,k+1):
        d = 1 << l - 1
        for i in range(1<<k - l):
            u = 1
            for j in range(i*2*d, (i*2+1)*d):
                f[j+d] *= u
                f[j],f[j+d] = (f[j]+f[j+d])%mod, (f[j]-f[j+d])%mod
                u *= Winv[l] 
                u %= mod

def convolution(a,b):
    le = len(a)+len(b)-1
    k = le.bit_length()
    n = 1 << k
    a = a + [0]*(n-len(a))
    b = b + [0]*(n-len(b))
    fft(k,a)
    fft(k,b)
    for i in range(n):
        a[i] *= b[i]
        a[i] %= mod
    fftinv(k,a)
    
    ninv = pow(n,mod-2,mod)
    for i in range(le):
        a[i] *= ninv
        a[i] %= mod
    
    return a[:le]

r,g,b,k = map(int,input().split())
x,y,z = map(int,input().split())

fact = [1,1]
finv = [1,1]
inv = [0,1]
 
for i in range(2,max(r,g,b,k)+5):
    fact.append((fact[-1]*i)%mod)
    inv.append((inv[mod%i]*(mod-mod//i))%mod)
    finv.append((finv[-1]*inv[-1])%mod)
 
def nCr(n,r,mod):
    if r > n:
        return 0
    else: 
        return fact[n]*finv[r]%mod*finv[n-r]%mod
R = [0]*(k+1)
G = [0]*(k+1)

for i in range(k+1):
    if k-y <= i <= r:
        R[i] = nCr(r,i,mod)
    if k-z <= i <= g:
        G[i] = nCr(g,i,mod)

RG = convolution(R,G)
ans = 0
for i in range(k-x,min(b,k)+1):
    ans += nCr(b,i,mod)*RG[k-i]%mod
    ans %= mod
print(ans)