Mixture Spoj problem

How this formula is generated.

(A1,A2…Ak)(Ak+1,…An)
=f(i,k)+f(k+1,j)+cum sum of (i,k)*cum sum of(k+1,j)