

Image 1 contains the step which I am confused about. What happens to the middle term (-XiY(bar) -YiX(bar)). Picture 2 contains the question for context. I understand how to do the question once I understand this step.
Any help would be much appreciated. Thank you.
To prove the numerator is of the form given you can use this $$ \sum_{i=0}^{n}(X_i-\bar{X})(Y_i-\bar{Y})= \sum_{i=0}^nX_iY_i - X_i\bar{Y}-Y_i\bar{X}+\bar{X}\bar{Y} = \sum_{i=0}^nX_iY_i - \bar{Y}\sum_{i=0}^nX_i-\bar{X}\sum_{i=0}^nY_i+\sum_{i=0}^n\bar{X}\bar{Y} $$ now have $$ \bar{X} = \frac{\sum_{i=0}^n X_i}{n}\implies n\bar{X} = \sum_{i=0}^n X_i $$ similarly for $Y_i$ sum. Thus we get $$ \sum_{i=0}^{n}(X_i-\bar{X})(Y_i-\bar{Y})=\sum_{i=0}^nX_iY_i - \bar{Y}\left(n\bar{X}\right)-\bar{X}\left(n\bar{Y}\right)+n\bar{X}\bar{Y} = \sum_{i=0}^nX_iY_i - n\bar{X}\bar{Y} $$