Let: $P_n(x) = 1(1+x)(1+x+x^2)+ \dots +(1+x+x^2+ \dots +x^n)$
I heard that the $k$-th coefficient of $P_n(x)$ is the number of permutations $\sigma \in S_n$ with $k$ inversions and I want to prove that, but I got stuck.
My work:
The $k$-th coefficient of $P_n(x)$ (which I will call $c_k$) is the number of ways in which we can choose a term of the form $x^a$ from each paranthesis such that their product is $k$. We will call the term we choose from the $i$-th paranthesis $x^{a_i}$. This means that: $$ c_k = |\{ (a_i)_{0\leq i\leq n} | a_i \leq i, a_i \in \mathbb{N}, \sum a_i = k\}|$$
Let $\sigma \in S_n$ such that $\sigma$ has $k$ inversions and $A_i = |\{ j | j < i, \sigma(j) > \sigma(i) \}|$. That means that: $$\sum A_i = k$$
So what I need to prove is that: $$c_k = \sum A_i$$ which I don't know how to do. Can you help me?