$S_1=n$ , if there was only $1$ for loop
$S_2=\sum_{1}^{n} n=\frac{n*(n+1)}{1*2}$ , if there were $2$ for loop
$S_3=\sum_{1}^{n}S_2=\frac{n*(n+1)*(n+2)}{1*2*3}$ , if there were $3$ for loop
similarly, $S_6=\sum_{1}^{n}S_5=\frac{n*(n+1)*(n+2)*(n+3)*(n+4)*(n+5)}{1*2*3*4*5*6}$ , if there were $6$ for loop
That's how i did it