As you could see it only passes 2 cases. My idea was to calculate sum of binomial coefficents (nc0+nc1+nc2+…+ncr)->binom(n,r) and then calculate the answer by multiplying the different sums with each other for different frequencies and elements. I know the answer would require many optimizations to pass subtask3 but i’m more interested in why i’m not able to pass subtask 1 (since i could perform optimizations once my code is correct). I’m beginer at competitive coding so please help me as i know i am making some basic mistake.
The problem is in line no. 65.
Whenever you need (a-b)%M always use (a-b+M)%M because if a<b then you will get a negative remainder which will cause a WA.