@anon80320319 I had to spend a lot of time on debugging your code. And, finally found the bug. The problem is with this statement:
result = (result*(fact[x[i]]*binaryExp((fact[c[i]]*fact[x[i]-c[i]])%mod,mod-2))%mod)%mod;
Let’s make it look a little simpler,
Let, a = fact[x[i]]
b = (fact[c[i]]*fact[x[i]-c[i]])%mod
c = binaryExp(b, mod-1)
Now, put these symbols in your statement
result = (result * (a * c) % mod)% mod;
Now you can guess the error.
result * (a * c) % mod has same execution sequence as (result * a * c) % mod, and each of result, a & c can have values upto 998244353, hence, this will result in long long limit overflow.
The correct statement should be of the following form:
result = (result * ( (a * c) % mod ) )% mod;
Just, replace the statement, with the following one, and your code will be accepted.
result = (result*((fact[x[i]]*binaryExp((fact[c[i]]*fact[x[i]-c[i]])%mod,mod-2))%mod))%mod;
You see, the problem was just because of a pair of parentheses, and it was quite tough to spot the error, so I would suggest, rather than writing a large expression in a single statement, you should always evaluate it by dividing into simpler forms. This will make your code more readable and easy to debug.