Given n 2-dimensional data objects or points in a cluster, we can define the centroid (x0,y0), radius R and diameter D of the cluster as follows.
where R is the average distance from member objects to the centroid, and D is the average pairwise distance within the cluster. Both R and D reflect the tightness of the cluster around the centroid.
Note: Take R=0 for n<1, and D=0 for n<2
Given p data objects or points, you are supposed to answer q queries. In the ith query, you consider only the points whose x-coordinate lies in [x1i,x2i] and y-coordinate lies in [y1i,y2i] as a single cluster. For each query you have to find the centroid, radius and diameter of the cluster. Since the values can be non-integer, you have to print the value of nx0+ny0+n2R2+n(n−1)D2
The first line contains two integers p and q denoting the number of data objects or points and the number of queries/clusters respectively.
Next p lines contains two-space separated integers denoting xi and yi. The coordinates of ith data point.
Next q line contains four space-separated integer denoting x1i,x2i,y1i,and y2i respectively.
Output q lines each containing a single integer. ith line denotes the value of nx0+ny0+n2R2+n(n−1)D2 of the ith cluster.
All the points inside yellow region(including blue) are in the cluster 1:
For cluster 1: data points are (2,4),(5,3),(5,5)
All the points inside blue region are in the cluster 2:
For cluster 2: data points are (5,3),(5,5)