Doubt in Dreamoon and WiFi (Codeforces)

Yes That Solution on which i was asking my doubt took 15 ms But When i wrote a similar Solution it took 30 ms.

Can you explain me this line
int ans=ncr(q,(q+abs(val-vali))/2);

how is this giving us the favourable outcomes?

Iā€™m still missing why we used nCr since the ā€˜-ā€™ position mattered we should have used nPr right ?