I have verified numerically the following identity, for several values of $m,n$:
$$\sum_{i_1, \ldots, i_m = 1}^n \prod_{k = 1}^{m - 1} (\delta_{i_k, i_{k + 1}} a_k + (1 - \delta_{i_k, i_{k + 1}}) b_k) = n \prod_{k = 1}^{m - 1} (a_k + (n - 1) b_k)$$
Here $m,n$ are positive integers and $a_k,b_k$ are given numbers.
But I have not been able to prove it. There is probably some trick to simplify the math that I am missing.
This is not homework. I just stumbled upon this during a very specific research problem.
The special cases $n=1$ or $m=1$ can be shown easily. We denote with $[n]=\{1,\ldots,n\}$. Let $m,n$ be integers $>1$.
Comment
In (1) we multiply out the product noting that each of the $m-1$ factors contributes either $a_k$ or $(n-1)b_k$. We order the terms, so that for $k\in S\subseteq[m-1]$ we have $j_k=j_{k+1}$ and for $k\in[m-1]\setminus S$ we have $j_k\ne j_{k+1}$.
In (2) we use $\displaystyle{\sum_{j_1=1}^n1}=n$.
In (3) we use $\displaystyle{\sum_{{j_1,\ldots,j_m=1}\atop{{j_k=j_{k+1},k\in S}\atop{j_k\ne j_{k+1}, k\in [m-1]\setminus S}}}^n1}=(n-1)^{m-1-|S|}$. Note that for $k\in S$, $1\leq j_k\leq n$ we have $\displaystyle{\sum_{{j_{k+1}=1}\atop{j_k=j_{k+1}}}^n1=1}$ and $\displaystyle{\sum_{{j_{k+1}=1}\atop{j_k\ne j_{k+1}}}^n1=n-1}$.
In (4) we reorder the product by letting the bound variable $q$ go from $1$ to $n$ and connect $a_k$ and $b_k$ with $S$ using the kronecker delta symbol.
In (5) we just reorder the summands by skipping the summation over $S$ and the conditions $j_k= j_{k+1}$, resp. $j_k\ne j_{k+1}$.