Professor Zhang draws n points on the plane, which are conveniently labeled by 1,2,...,n. The i-th point is at (xi,yi). Professor Zhang wants to know the number of best sets. As the value could be very large, print it modulo 109+7.
A set P (P contains the label of the points) is called best set if and only if there are at least one best pair in P. Two numbers u and v (u,v∈P,u≠v) are called best pair, if for every w∈P, f(u,v)≥g(u,v,w), where f(u,v)=(xu−xv)2+(yu−yv)2−−−−−−−−−−−−−−−−−−√ and g(u,v,w)=f(u,v)+f(v,w)+f(w,u)2.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤1000) -- then number of points.
Each of the following n lines contains two integers xi and yi (−109≤xi,yi≤109) -- coordinates of the i-th point.
The first line contains an integer n (1≤n≤1000) -- then number of points.
Each of the following n lines contains two integers xi and yi (−109≤xi,yi≤109) -- coordinates of the i-th point.
Output
For each test case, output an integer denoting the answer.
Sample Input
3
3
1 1
1 1
1 1
3
0 0
0 1
1 0
1
0 0
Sample Output
4
3
0
#include <stdio.h> #include <string.h> #include<iostream> #include<algorithm> #include<vector> #include<map> using namespace std; typedef long long LL; #define MAXM 1000000004 #define pi 1000000007 map<pair<int ,int> ,int>x; map<pair<int ,int> ,int >::iterator it; struct aa { long long x,y; } a[1001]; int cmp(aa t1,aa t2) { return t1.x==t2.x?t1.y<t2.y:t1.x<t2.x; } LL gcd(LL a,LL b) { return b==0?a:gcd(b,a%b); } LL qe(LL a, LL b) { LL ans = 1; a = a%pi; while (b > 0) { if (b % 2 == 1) ans = (ans*a) % pi; b = b / 2; a = (a*a) % pi; } return ans; } int main() { // init(); int t,i,j,k; LL ans=0; cin>>t; pair <int ,int>h; while(t--) { cin>>k; ans=0; for(i=1; i<=k; i++) scanf("%lld %lld",&a[i].x,&a[i].y); sort(a+1,a+1+k,cmp); for(i=1; i<k; i++) { LL sum=1; x.clear(); for(j=i+1; j<=k; j++) { LL x1,y1; x1=a[j].x-a[i].x; y1=a[j].y-a[i].y; if(x1==0&&y1==0) { sum++; continue; } else { LL se; se=gcd(x1,y1); x1/=se; y1/=se; h=make_pair(x1,y1); } x[h]++; } if(sum>1) { ans=(ans+qe(2,sum)-1-sum)%pi; } LL u=0; u=qe(2,sum)-1; // for(it=vis.begin(); it!=vis.end(); it++) for(it=x.begin(); it!=x.end(); it++) { LL v,w=0; v=it->second; v=qe(2,v); ans=(ans+(u)*(v-1))%pi; } while(i!=k&&a[i].x==a[i+1].x&&a[i].y==a[i+1].y) { i++; } } printf("%I64d ",ans); } }