Solution (source code)

= Solution
{c}

Both stopped variables are integrable, since $|X_S|,|X_T|\leq\sum_{j=0}^N|X_j|$. Also $X_S$ is $\mathcal F_S$-measurable: intersecting $\{X_S\in B\}$ with $\{S\leq n\}$ gives the finite union $\bigcup_{j\leq\min(n,N)}\{S=j,X_j\in B\}$ in $\mathcal F_n$ for each Borel $B$.

The increment identity is
$$
X_T-X_S=\sum_{k=0}^{N-1}(X_{k+1}-X_k)1_{\{S\leq k<T\}}.
$$
For $A\in\mathcal F_S$, the event $A\cap\{S\leq k\}\cap\{T>k\}$ belongs to $\mathcal F_k$. The <martingale> increment has conditional mean zero given that sigma-algebra. Multiplying by its indicator and using the <tower property> gives zero expectation for each summand. Therefore
$$
\mathbb E[1_A(X_T-X_S)]=0\qquad(A\in\mathcal F_S).
$$
Together with measurability and integrability, this is the defining property of <conditional expectation>, proving the bounded <optional sampling theorem>
$$
\boxed{\mathbb E(X_T\mid\mathcal F_S)=X_S\quad\text{almost surely}.}
$$