# Explaining $\sum_{i=1}^n\sum_{j=1}^nCov(Y_i,B_j)=\sum_{i=1}^n\sum_{j=1,j\neq i}^nCov(Y_i,B_j)+\sum_{i=1}^nCov(Y_i,B_i)$

Sorry for the non-specific title, I was unsure of how to word this.

I can't wrap my head around this calculation where they split the summation $$\sum_{i=1}^n \sum_{j=1}^n \operatorname{Cov}(Y_i,B_j) = \sum_{i=1}^n\sum_{j=1, j\neq i}^n\operatorname{Cov}(Y_i,B_j)+ \sum_{i=1}^n \operatorname{Cov}(Y_i,B_i).$$

Can someone explain how this works?

Full calculation: enter image description here

Nevermind, I think I worked it out. It's because the summation after the + sign is summing over the i-th terms of Y and B which was excluded from the summation the first summation after the = sign, due to j != i

$$\sum_{i=1}^n \sum_{j=1}^n Cov(Yi,Bj) = \sum_{i=1}^n (\sum_{j=1, j!=i}^n Cov(Yi,Bj) + \sum_{j=i}^nCov(Yi,Bj)\space)$$ $$= \sum_{i=1}^n\sum_{j=1, j!=i}^n Cov(Yi,Bj) + \sum_{i=1}^n\sum_{j=i}^n Cov(Yi,Bj)$$ Second sum in the second term is only defined once at $$\space j=i$$. Therefore, we can substitute $$i$$ for $$j$$ and eliminate the second summation. $$= \sum_{i=1}^n\sum_{j=1, j!=i}^n Cov(Yi,Bj)+ \sum_{i=1}^n Cov(Yi,Bi)$$