You can put this solution on YOUR website! Expand (x-y)^2 = x^2 - 2xy + y^2
If we add the equations we get:
2x^2 + 2y^2 = p+q -> x^2 + y^2 = (p+q)/2
Now subtract the 1st equation from the 2nd:
-2xy = q-p
Now add these two results together:
x^2 - 2xy + y^2 = (p+q)/2 + (q-p) = (3q-p)/2