Premium problem98. Expected Inversions

Medium Locked

Shuffle n distinct elements uniformly. Return the expected number of inversions, meaning pairs that appear in the wrong relative order.

Every one of the (n2)\binom{n}{2} pairs is inverted with probability exactly 1/21/2, by symmetry:

E=12(n2)=n(n−1)4E = \frac{1}{2}\binom{n}{2} = \frac{n(n-1)}{4}

Input

10

Output

22.5

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)