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.

Fix $k$ and let $a_n$ be the number of $k$s that appear among all ($2^{n-1}$) ordered partitions of $n$.  Then $a_n=0$ for $n<k$, $a_k=1$, and conditioning on the first part $i$ yields recurrence relation
$$a_n = \sum_{i=1}^n ([i=k]2^{n-i-1} + a_{n-i}) = 2^{n-k-1} + \sum_{i=1}^{n-k} a_{n-i} \quad \text{for $n > k$}.$$
Let $A(z) = \sum_{n=0}^\infty a_n z^n$ be the ordinary generating function.  Then
\begin{align}
A(z) 
&= \sum_{n=0}^{k-1} 0 z^n + 1z^k + \sum_{n=k+1}^\infty \left(2^{n-k-1} + \sum_{i=1}^{n-k} a_{n-i}\right) z^n \\
&= z^k + \sum_{n=k+1}^\infty 2^{n-k-1} z^n + \sum_{i=1}^\infty z^i \sum_{n=i+k}^\infty a_{n-i} z^{n-i} \\
&= z^k + \frac{z^{k+1}}{1-2z} + \sum_{i=1}^\infty z^i A(z) \\
&= z^k + \frac{z^{k+1}}{1-2z} + \frac{zA(z)}{1-z}.
\end{align}
So
\begin{align}
A(z) 
&= \frac{z^k(1-z)^2}{(1-2z)^2} \\
&= z^k \left(\frac{1}{4}+\frac{1/2}{1-2z}+\frac{1/4}{(1-2z)^2}\right) \\
&= z^k \left(\frac{1}{4}+\frac{1}{2}\sum_{n=0}^\infty(2z)^n+\frac{1}{4}\sum_{n=0}^\infty\binom{n+1}{1}(2z)^n\right) \\
&= z^k \left(1+\frac{1}{2}\sum_{n=1}^\infty(2z)^n+\frac{1}{4}\sum_{n=1}^\infty(n+1)(2z)^n\right) \\
&= z^k +\sum_{n=k+1}^\infty \left(2^{n-k-1}+(n-k+1)2^{n-k-2}\right)z^n \\
&= z^k +\sum_{n=k+1}^\infty (n-k+3)2^{n-k-2}z^n,
\end{align}
which immediately implies that
$a_n = (n-k+3)2^{n-k-2}$ for $n>k$.
