human
Give me a code to sum of squares of distances between all pairs from given points and the other steps required given the following:
Sum of squares of distances between all pairs from given points | Function to find the sum of squares of distance between all distinct pairs.
Stores final answer.
Traverse the array.
Adding the effect of this point for all the previous x - points.
Temporarily add the square of x - coordinate.
Add the effect of this point for all the previous y - points.
Print the desired answer.
Driver Code"
Solution in Python:
assistant
#Here is code to sum of squares of distances between all pairs from given points and the other steps required.
 def findSquareSum ( Coordinates , N ) :
	xq , yq = 0 , 0
	xs , ys = 0 , 0
	res = 0
	for i in range ( N ) :
		a = Coordinates [ i ] [ 0 ]
		b = Coordinates [ i ] [ 1 ]
		res += xq
		res -= 2 * xs * a
		res += i * ( a * a )
		xq += a * a
		xs += a
		res += yq
		res -= 2 * ys * b
		res += i * b * b
		yq += b * b
		ys += b
	print ( res )
if __name__ == ' _ _ main _ _ ' :
	arr = [ [ 1 , 1 ] , [ - 1 , - 1 ] , [ 1 , - 1 ] , [ - 1 , 1 ] ]
	N = len ( arr )
	findSquareSum ( arr , N )