Is it possible for (Q-P) to be less than zero.?

what happen if Q is less than P then ans will become negative…

if u think Q never less than P than u r wrong because u r taking mod so it can happen so to avoid thid possibility be add mod in Q than subtract P from this…than take mode print ans u will get AC…

#prasadram126 …u r using int data type it is not enough to store big value like 10^9 so use long int or long long int …u will get AC for first subtask but u will TLE for remaining to get full point u have to use merge sort…here i have modified ur solution u can access from here http://www.codechef.com/viewsolution/7071300…

may be Q less than P in that case ans will become negative which not right…

if u think how it is possible …because we are taking mod in whole process it may become less than p think if Q= mod+1 at any stage because u take mod at every stage it will become 1 and P may be 2 than ans will become negative…hope u understood…

Hi All,

I think the explanation is not correct. when he says no.of subsets having element a1 is 2^(N-1) as this number of subset contains a subset which contains only {a1}. That is has no effect on the answer as it evaluates to 0.

But the code works because he is doing the same mistake again while calculating Q.So it cancels out.

Conclusion,you can say he purposely did it to make the code looks short and clear .I was expecting the explanation to be in the editorial.

Thank You