As part of solving this problem , I came up with the following expression:
$$\text{ans} = n\cdot n + (n-2)\cdot (n-2) + (n-4)\cdot (n-4) + \dots$$
So I am just running a loop to calculate the ans. However, since there is a pattern in the form of a series, I am wondering if a closed form exists for it? Please also show the steps to obtain so that I can learn, in general, how to approach such problems for finding closed forms.
EDIT: series goes till 2 if n is even, and till 1 if n is odd.
It is well known that the sum of terms that are a polynomial expression of degree $d$, evaluated at the integers, is a polynomial expression of degree $d+1$.
So if you consider four values of the sum, you can obtain the requested expression as the Lagrangian interpolation polynomial on these four points.
For even $n$,
$$(0,0),(2,4),(4,20),(6,56)\to\frac{n^3+3n^2+2n}6.$$
For odd $n$,
$$(1,1),(3,10),(5,35),(7,84)\to\frac{n^3+3n^2+2n}6.$$