A counting problem related to Parallelogram There are $n$ distinct points in the plane, given by their integer coordinates. Find the number of parallelograms whose vertices lie on these points. In other words, find the number of $4$-element subsets of these points that can be written as $\{A,B,C,D\}$ such that $AB∥CD$, and $BC∥AD$. No four points are in a straight line.

For example, $n=6$ and the $6$ points are $(0,0),(2,0),(4,0),(1,1),(3,1),(5,1)$ the number of parallelograms is $5$. I can find out the number of parallelograms manually if $n$ is small but how can I find out the number of parallelograms if $n$ is large? Is there any efficient method? If so,what is the method? Please explain it in details.
The following code maybe help you

//C++ code for counting the number of Parallelograms
#include &lt;map&gt;
#include &lt;iostream&gt;
#include &lt;utility&gt; //pair
using namespace std;

int N, x[2002], y[2002];
map &lt;pair&lt;int, int&gt;, int&gt; cnt;
long long ans = 0;

int main()
{
    cin &gt;&gt; N;
    for (int i = 1; i &lt;= N; i++)
        cin &gt;&gt; x[i] &gt;&gt; y[i];
    for (int i = 1; i &lt; N; i++)
    for (int j = i + 1; j &lt;= N; j++)
    {
        ans += cnt[make_pair(x[i] + x[j], y[i] + y[j])];
        cnt[make_pair(x[i] + x[j], y[i] + y[j])]++;
    }
    cout &lt;&lt; ans;
    return 0;
}
The following code maybe help you

//C++ code for counting the number of Parallelograms
#include &lt;map&gt;
#include &lt;iostream&gt;
#include &lt;utility&gt; //pair
using namespace std;

int N, x[2002], y[2002];
map &lt;pair&lt;int, int&gt;, int&gt; cnt;
long long ans = 0;

int main()
{
    cin &gt;&gt; N;
    for (int i = 1; i &lt;= N; i++)
        cin &gt;&gt; x[i] &gt;&gt; y[i];
    for (int i = 1; i &lt; N; i++)
    for (int j = i + 1; j &lt;= N; j++)
    {
        ans += cnt[make_pair(x[i] + x[j], y[i] + y[j])];
        cnt[make_pair(x[i] + x[j], y[i] + y[j])]++;
    }
    cout &lt;&lt; ans;
    return 0;
}