Parallelogram Counting
InterviewTime limit1sMemory limit128 MB
Given n points, count how many 4-point subsets form a parallelogram by pairing points that share a midpoint.
- Level
Medium6 of 10
- Topics
- Hash map, Geometry, Combinatorics, Math
- Solved
- No attempts yet
Problem
You are given distinct points in the plane, each with integer coordinates. Count the number of parallelograms whose four vertices are all among these points.
Formally, count the -element subsets that can be labeled so that and . No four of the given points are collinear.
Input
The first line contains an integer (), the number of test cases. The test cases follow.
For each test case, the first line contains an integer (). Each of the next lines contains two space-separated integers and (), the coordinates of one point.
Output
Print lines. The -th line contains the number of parallelograms for the -th test case.