Solution (source code)

= Solution

A <stationary distribution> is a nonnegative row vector $\pi=(\pi_i)_{i\in S}$ with total mass one that is preserved by one transition:
$$
\boxed{\pi_i\geq0,\quad\sum_{i\in S}\pi_i=1,\quad\pi_j=\sum_{i\in S}\pi_iP_{ij}\quad(j\in S).}
$$
In matrix notation, $\pi P=\pi$. If the initial state has distribution $\pi$, so does the state at each later time.