Given an integer $n$, one does $n$ random selections with repetition one after the other. For each selection there are two possibilities a success $X$ and a failure $O$. For each selection $i\le n$ the probability that it's a success is $p_i$ and the probability that it is a failure is $1-p_i$.
For a possible complete $n$ selections, if there are $m$ strings of $X$'s separated by strings of $O$'s, then the score for that set is $\displaystyle \sum ^m_{j=1} x_j^2 $ where $x_j$ is the length of the $j$-th $X$-string. If there are no $X$ string then the score is zero.
Example:
For $n=12$, a possible complete selection is $XOXXOOOXXXXO$, there are $3$ strings of $X$'s and the score is $1^2 +2^2+4^2 = 21$ while the probability is = $\displaystyle \prod^n_ip_i$
I am trying to find a general formula for both the score and its probability, I have done for the small cases where $n=1,2,3,4$ and I can't seem to find a general formula for it when $n$ gets really big, like $1000$ big.
My real goal is to calculate the expected value for any integer $n$ given the probabilities at each level of selections.