The constraints on N are upto 10^10 . So everytime you multiply by some factor of N you need to first take modulo . Specifically this line in your code lead to WA .

for(int i=0;i<=t;i++)
ans=(ans*(n+1+i))%M;

Have a look at the modified version of your solution.