http://www.spoj.com/problems/MSE06H/

The solution of the problem is based on finding the number of crossing in a bipartite graph.
we can solve this problem by counting the number of inversion.