How many instances of number $k$ in sums that add up to number $n$? Task in Combinatorics course:

$1 \leq k < n$. Prove that the number $k$ can be found $(n-k+3)2^{n-k-2}$ times in sums that add up to $n$.

Example: $n=4, k=2$.
$1+1+2$
$1+2+1$
$2+1+1$
$2+2$
These are the sums that add up to $4$ and the number $2$ can be found $5$ times.
Thus far, I have tried making sense of that formula. $n-k$ is the number or countables left if we have one $k$. $2^{n-1}$ is how many sums that add up to $n$ there are in total so in the second half of the formula it could be $2^{n-1}2^{k-1}$ that would add up to $2^{n-k-2}$. But none of that comes together. Why would there be a $+3$ in the first half.

We have the marked generating function
$$Q(z,u) = \sum_{q=1}^n
\left(z+\cdots+z^{k-1} + u z^k + z^{k+1} + \cdots\right)^q.$$
The term $u^p z^m$ represents a composition that sums to $m$ and
contains $p$ instances of the number $k.$ Hence we differentiate with
respect to $u$ and set $u=1$ to get the count. Differentiation yields
$$\sum_{q=1}^n
q \left(z+\cdots+z^{k-1} + u z^k + z^{k+1} + \cdots\right)^{q-1}
z^k.$$
Set $u=1$ to get
$$[z^n] z^k \sum_{q=1}^n q \frac{z^{q-1}}{(1-z)^{q-1}}.$$
Note that with $k\ge 1$ we may extend $q$ beyond $n$ without getting  any
additional contributions to the coefficient extractor. This yields
$$[z^n] z^k \sum_{q\ge 1} q \frac{z^{q-1}}{(1-z)^{q-1}}
= [z^{n-k}] \frac{1}{(1-z/(1-z))^2}
\\ = [z^{n-k}] (1-z)^2 \frac{1}{(1-2z)^2}
\\ = [z^{n-k}] \frac{1}{(1-2z)^2}
- 2 [z^{n-k-1}] \frac{1}{(1-2z)^2}
+ [z^{n-k-2}] \frac{1}{(1-2z)^2}
\\ = (n-k+1) 2^{n-k} - 2(n-k) 2^{n-k-1} + (n-k-1) 2^{n-k-2}
\\ = (4n-4k+4-4n+4k+n-k-1) 2^{n-k-2}
= (n - k + 3) 2^{n-k-2}.$$
This is with $n-k\ge 2.$ We get for $k=n-1$
$$(n-k+1) 2^{n-k} - 2(n-k) 2^{n-k-1}
= 2\times 2 - 2 = 2$$
which is true because the compositions are $(1,n-1)$ and $(n-1,1).$ We
get for $k=n$
$$(n-k+1) 2^{n-k} = 1$$
which is also true because there is just one composition $(n).$
