Solution (source code)

= Solution

The balance recurrence is
$$
\pi_i=\pi_{i+1}+\pi_0q_{i+1}.
$$
Working down from $N-1$ gives $\pi_i=\pi_0P(T_1>i)$. Since the sum of these tails is $E[T_1]$, the unique invariant law is
$$
\boxed{\pi_i=\frac{P(T_1>i)}{E[T_1]}=
\frac{\sum_{j=i+1}^Nq_j}{\sum_{j=1}^Njq_j}.}
$$