[step:Show the remainder $r$ vanishes on $S = S_1 \times \cdots \times S_n$]
Let $(x_1, \ldots, x_n) \in S_1 \times \cdots \times S_n$. For each $i$, since $x_i \in S_i$, the factor $(X_i - x_i)$ appears in the product $g_i(X_i) = \prod_{s \in S_i}(X_i - s)$, so $g_i(x_i) = 0$. Evaluating the decomposition at $(x_1, \ldots, x_n)$:
\begin{align*}
f(x_1, \ldots, x_n) = \sum_{i=1}^{n} h_i(x_1, \ldots, x_n)\, g_i(x_i) + r(x_1, \ldots, x_n).
\end{align*}
The left-hand side is zero (since $f$ vanishes on $S$ by hypothesis), and each term $h_i(x_1, \ldots, x_n) \cdot g_i(x_i) = h_i(x_1, \ldots, x_n) \cdot 0 = 0$. Therefore $r(x_1, \ldots, x_n) = 0$.
Since $(x_1, \ldots, x_n) \in S$ was arbitrary, $r$ vanishes identically on $S$.
[/step]