For every integer $n\geq 0$ we define
$a_n=\sum_{k=0}^{n} 3^{k}(n-k)$.
Find the generating function of the sequence $(a_n)_{n=0}^\infty$ and write down the answer without series.
Attempt: $G(x)=\sum_{n=0}^{\infty} (\sum_{k=0}^{n} 3^{k}(n-k))x^n=\sum_{n=0}^{\infty} (n\sum_{k=0}^{n} 3^{k}-\sum_{k=0}^{n}k3^k)x^n=\sum_{n=0}^{\infty}(\frac{1}{2}n(3^{n+1}-1)-\sum_{k=0}^{n}k3^{k})=...?$
where I took into account that $1+3+...+3^n=\frac{1}{2}(3^{n+1}-1)$. How to continue?
WolframAlpha returns: $\sum_{n=0}^{\infty} (\sum_{k=0}^{n} 3^{k}(n-k))x^n$=$-\frac{x}{(x-1)^2 (3x-1)}$. How do I get to this?
We can directly see that $a_n$ is the convolution of the sequences $b_n = 3^n$ and $c_n = n$. Therefore, the generating function for $a_n$ is the product of the generating functions for $b_n$ and $c_n$, which are $\frac{1}{1-3x}$ and $\frac{x}{(1-x)^2}$, respectively.