<s>[INST] Produce formula Let $a_{i,j}$ any positive integers wher $1\leq i,j \leq 3$.
I want to write closed form for following summation:
$$a_{1,3}(a_{2,1}+a_{2, 2}+a_{2,3})(a_{3,1}+a_{3, 2}+a_{3,3})+a_{2,3}(a_{1,1}+a_{1, 2})(a_{3,1}+a_{3, 2}+a_{3,3})+a_{3,3}(a_{1,1}+a_{1, 2})(a_{2,1}+a_{2, 2})$$
$\textbf{My attempt:}$
\begin{equation*}
\sum_{j=1}^3 a_{j,3}\left[\prod_{\substack{i=1 \\ i\neq j}}^3\left(\sum_{\substack{k=1 \\ k<j}}^{3 \ \ \ \text{or} \ \ 3-1} a_{i,k} \right) \right]
\end{equation*}
We will take $3-1$ when $k<j$.

Actually, I want to generalize this. My attempt so complicated to me.
If we consider all of $a_{i,j}$ as a matrix:
\begin{pmatrix}
a_{1,1} & a_{1,2} & a_{1,3} \\
a_{2,1} & a_{2,2} & a_{2,3} \\
a_{3,1} & a_{3,2} & a_{3,3} \\
\end{pmatrix}
 then are there any computer program to make formula?

$$a_{1,3}(a_{2,1}+a_{2, 2}+ a_{2,3})(a_{3,1}+a_{3, 2}+a_{3,3})\cdots (a_{r,1}+a_{r,2}+a_{r,3})+a_{2,3}(a_{1,1}+a_{1, 2})(a_{3,1}+a_{3, 2}+a_{3,3})+\cdots (a_{r,1}+a_{r,2}+a_{r,3})+a_{3,3}(a_{1,1}+a_{1, 2})(a_{2,1}+a_{2, 2})(a_{4,1}+a_{4,2}+a_{4,3}+\cdots (a_{r,1}+a_{r,2}+a_{r,3}) \\ \vdots \\
+a_{r,3}(a_{1,1}+a_{1,2})(a_{2,1}+a_{2,2})\cdots (a_{r-1,1}+a_{r-1,2})
$$
 [/INST] $$a_{1,3}(a_{2,1}+a_{2, 2}+a_{2,3})(a_{3,1}+a_{3, 2}+a_{3,3})+a_{2,3}(a_{1,1}+a_{1, 2})(a_{3,1}+a_{3, 2}+a_{3,3})+a_{3,3}(a_{1,1}+a_{1, 2})(a_{2,1}+a_{2, 2})$$
$$=(a_{1,1}+a_{1,2}+a_{1,3})(a_{2,1}+a_{2,2}+a_{2,3})(a_{3,1}+a_{3,2}+a_{3,3})-(a_{1,1}+a_{1,2})(a_{2,1}+a_{2,2})(a_{3,1}+a_{3,2})$$
$$=\prod_{i=1}^3\sum_{j=1}^3a_{i,j}-\prod_{i=1}^3\sum_{j=1}^2a_{i,j}.$$
More generally,
$$\sum_{i=1}^ra_{i,m}\left(\prod_{h=1}^{i-1}\sum_{j=1}^{m-1}a_{h,j}\right)\left(\prod_{h=i+1}^r\sum_{j=1}^ma_{h,j}\right)=\prod_{i=1}^r\sum_{j=1}^ma_{i,j}-\prod_{i=1}^r\sum_{j=1}^{m-1}a_{i,j}$$
$$=\sum_{m\in\{j_1,j_2,\dots,j_r\}}a_{1,j_1}a_{2,j_2}\cdots a_{r,j_r}.$$
</s>