Jiraiya and Rasengan Attacks Hackerearth

How to approach the question Jiraiya and Rasengan Attacks given on Hackerearth. I think we should compute the probability that each pair of numbers in the array will become an inversion. But I can’t think more than that.
Problem link