For a sequence {X1, X2, …, Xn}, we call (i,j) an "inversion pair" if Xi > Xj and i < j. Given a sequence, calculate the number of inversion pairs in this sequence.
There are multiple test cases. Each case begins with an integer n, followed by n integers from X1 to Xn. The input is terminated when n=0.
For each test case, print the number of inversion pairs in the given sequence. Note that you have to add '\n' at the end of each line.