Balloon Fight

Problem is here:CodeChef: Practical coding for everyone
Can Anyone tell me which previous problem is similar to this problem as well as how to derive formula for it?

The question is same as that of two queens problem(easiest sub problem of the n queen problem)ie placing 2 queens on a chess board such that they dont attack each other.

Here is the link for n queen’s problem :N Queen Problem | Backtracking-3 - GeeksforGeeks

So you can apply a similar approach in this question. Instead of that i used PNC and got the formula for this question as number_of_ways=i.j.(j+i-2)+2.i.(i-1).(3.j-i-1)/3 (. means product)

Here is the link to my code: CodeChef: Practical coding for everyone

The approach of n queen will become very time consuming!could you give me the link to study the above formulae as i am not able to understand how it is derive?