There is also a combinatorical way to find the solutiopn of you question. Check wich values takes the tupel $(j,k,i)$ in the most inner loop? Each tuple $(j,k,i)$ with $1 \le k \le N$ exactly once.
So
- each tuple $(j,k,i)$ with $1 \le j
- each tuple $(j,j,i)$ with $1 \le j
- each tuple $(j,i,i)$ with $1 \le j
- each tuple $(j,j)$ with $1 \le j \le N$
The first number is $\binom{N}{3}$, the second and the third is $\binom{N}{2}$, the fourth is $\binom{N}{1}$. $(\binom{N}{3} + \binom{N}{2} ) + (\binom{N}{2}+ \binom{N}{1})=\binom{N+1}{3}+\binom{N+1}{2}=\binom{N+2}{3}=\frac{n(n+1)(n+2)}{6}=\binom{n+2}{3}$
Edit
This result can be proved in a direct way:
Take the $n+2$ element set $M=\{\text{"j=k"},1,...,N,\text{"i=k"}\}$. The set contains of the $N$ numbers $1,...,N$ and the two strings $\text{"j=k"}$ and $\text{"i=k"}$. A three element subset $S$ of $M$ can be of exactly one of the following types:
- $S=\{j,k,i\} , 1 \le j \lt k \lt i \le N$
- $S=\{\text{"j=k"},k,i\}, 1 \le k \lt i \le N$
- $S=\{j,k,\text{"i=k"}\}, 1 \le j \lt k \le N$
- $S=\{\text{"j=k"},k,\text{"i=k"}, 1 \le k \le N$
The sets of these four list items correspond to the tuples of the corresponding items of the former list. But this four types of sets contain all the three element subsets of the set M and the number of three element subsets of $M$ is $\binom{n+2}{3}$.