
$$\halign{
\hfil$#$ & $= {#}\hfil$ \cr
{\cal B}  & \sum{x_iy_i} \cr
  & \sum{x_i(px_i+q)} \cr
  & \sum{px_i^2} + \sum{qx_i} \cr
  & p{\cal A} + q{\cal X} \cr
}$$