You're given an integer n, answer the number of inversions in all the derangement permutations of length n. For example, if n = 3, there are two derangement premutations, 231 and 312, so the answer is 4.
There is such a sequence in OEIS. But I want to know how this is derived.
It's welcomed if you have other linear solution.