You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.


-----Input-----

The first line of the input contains integer n (1 ≤ n ≤ 2000) — the number of points.

Each of the next n lines contains two integers (x_{i}, y_{i}) (0 ≤ x_{i}, y_{i} ≤ 10^9) — the coordinates of the i-th point.


-----Output-----

Print the only integer c — the number of parallelograms with the vertices at the given points.


-----Example-----
Input
4
0 1
1 0
1 1
2 0

Output
1

Difficulty: interview

Starter code:

Solutions:
n = int(input())
points = [0] * n
D = {}
for i in range(n):
    points[i] = tuple(int(x) for x in input().split())

for i in range(n):
    for j in range(i+1, n):
        x1, y1 = points[i]
        x2, y2 = points[j]
        u, v = x2 - x1, y2 - y1
        if u < 0 or u == 0 and v < 0:
            u, v = -u, -v
        if (u, v) in D:
            D[(u, v)] += 1
        else:
            D[(u, v)] = 1

S = sum(D[i] * (D[i] - 1) // 2 for i in D)
print(S // 2)
                


from collections import defaultdict
def mp():  return list(map(int,input().split()))
def lt():  return list(map(int,input().split()))
def pt(x):  print(x)
def ip():  return input()
def it():  return int(input())
def sl(x):  return [t for t in x]
def spl(x): return x.split()
def aj(liste, item): liste.append(item)
def bin(x):  return "{0:b}".format(x)

n = it()
P = []
for i in range(n):
    a,b = mp()
    P.append([a,b])
Mid = defaultdict(int)
result = 0
for i in range(n-1):
    for j in range(i+1,n):
        x,y = P[i][0]+P[j][0],P[i][1]+P[j][1]
        result += Mid[(x,y)]
        Mid[(x,y)] += 1
print(result)
        
        


from collections import defaultdict
    
n=int(input())
C=[]
cnt=0
D=defaultdict(int)

for i in range(n) :
    C.append([int(i) for i in input().split()])

for i0 in range(n) :
    x0=C[i0][0]
    y0=C[i0][1]
    for Dots in C[i0+1:] :
        x=Dots[0]-x0
        y=Dots[1]-y0
        if x<0 :
            x,y=-x,-y
        elif x==0 :
            if y<0 :
                y=-y
        cnt+=D[(x,y)]
        D[(x,y)]+=1

print(int(cnt/2))

from collections import defaultdict
    
n=int(input())
C=[]
cnt=0
D=defaultdict(int)

for i in range(n) :
    C.append([int(i) for i in input().split()])

for i0 in range(n) :
    x0=C[i0][0]
    y0=C[i0][1]
    for Dots in C[i0+1:] :
        x=Dots[0]-x0
        y=Dots[1]-y0
        if x<0 :
            x,y=-x,-y
        elif x==0 :
            if y<0 :
                y=-y
        cnt+=D[x,y]
        D[x,y]+=1

print(int(cnt/2))



n = int(input())

x = []
y = []


for i in range(n):
    x.append(0)
    y.append(0)
    x[i], y[i] = list(map(int, input().split()))
    
    
from collections import defaultdict
dict = defaultdict(int)

for i in range(n):
    for j in range(i + 1, n):
        tx = x[i] - x[j]
        ty = y[i] - y[j]
        
        if tx > 0 or tx == 0 and ty > 0:
            tx = -tx
            ty = -ty
        
        dict[(tx, ty)] += 1
        
        


ans = 0
#print(dict)
for i in list(dict.values()):
    ans += i * (i - 1) // 2
    
print(ans // 2)






    
    






from collections import Counter


def read_ints():
    return [int(x) for x in input().split()]

def main():
    n, = read_ints()
    points = []
    for i in range(0, n):
        x, y = read_ints()
        points.append((x, y))

    c = Counter()
    for i in range(0, n):
        for j in range(i + 1, n):
            x1, y1 = points[i];
            x2, y2 = points[j]
            c[(x1 + x2, y1 + y2)] += 1
    res = 0
    for k, v in c.items():
        res += v * (v - 1)
    res //= 2
    print(res)


main()

from collections import *
ans=0
d=Counter()
n=int(input())
p=[tuple(map(int,input().split())) for i in range(n)]
for i in range(n):
  for j in range(i+1,n):
    if p[i]<p[j]: x1,y1=p[i]; x2,y2=p[j]
    else:x1,y1=p[j]; x2,y2=p[i]
    x,y=x2-x1,y2-y1
    ans+=d[(x,y)]    
    d[(x,y)]+=1
print(ans//2)

def main():
    from collections import Counter
    n, cnt = int(input()), Counter()
    l = sorted((tuple(map(int, input().split())) for _ in range(n)), reverse=True)
    for i in range(1, n):
        x, y = l[i]
        for j in range(i):
            u, v = l[j]
            cnt[u - x, v - y] += 1
    print(sum(i * (i - 1) for i in list(cnt.values())) // 4)


def __starting_point():
    main()

__starting_point()

def main():
    from collections import Counter
    n, cnt, l = int(input()), Counter(), []
    for x, y in sorted((tuple(map(int, input().split())) for _ in range(n)), reverse=True):
        for u, v in l:
            cnt[u - x, v - y] += 1
        l.append((x, y))
    print(sum(i * (i - 1) for i in list(cnt.values())) // 4)


def __starting_point():
    main()

__starting_point()

def middle(a, b):
    return (b[0] + a[0])/2, (b[1] + a[1])/2


def solve(n, points):
    middles = dict()
    solutions = 0
    for i in range(n-1):
        for j in range(i+1, n):

            s = middle(points[i], points[j])
            solutions += middles.setdefault(s, 0)
            middles[s] += 1

    return solutions


def __starting_point():
    n = int(input())
    points = list()
    for _ in range(n):
        points.append(tuple(map(int, input().split())))

    print(solve(n, points))









__starting_point()

from collections import Counter

def main() :
    n = int(input())
    x = []
    y = []
    a = Counter()

    for i in range(n) :
        x.append(0)
        y.append(0)
        x[i], y[i] = list(map(int, input().split()))
        
    for i in range(n) :
        for j in range(i + 1, n) :
            a[(x[i] + x[j], y[i] + y[j])] += 1

    ans = 0
    for q, p in list(a.items()) :
        ans += p * (p - 1)
    ans //= 2

    print(ans)

main()


n=int(input())
def inp(n):
    coor=[[int(i) for i in input().split()] for j in range(n)]
    
    return coor

coor=inp(n)


def newlist(a):
    d={}
    s=len(a)
    for i in range(1,s):
        for j in range(i):
            if (a[i][0]+a[j][0],a[i][1]+a[j][1]) in d:
                d[a[i][0]+a[j][0],a[i][1]+a[j][1]]+=1
            else:
                d[a[i][0]+a[j][0],a[i][1]+a[j][1]]=1
    return d
def newd(d):
    sum2=0
    for l in d:
        sum2+=d[l]*(d[l]-1)/2        
    return int(sum2)


    

     
print(newd(newlist(coor)))


            



read = lambda: list(map(int, input().split()))
n = int(input())
p = [tuple(read()) for i in range(n)]
from collections import Counter
cnt = Counter()
for i in range(n):
    for j in range(i + 1, n):
        cnt[p[i][0] + p[j][0], p[i][1] + p[j][1]] += 1
ans = sum(i * (i - 1) // 2 for i in list(cnt.values()))
print(ans)


def main():
    read = lambda: list(map(int, input().split()))
    n = int(input())
    p = [tuple(read()) for i in range(n)]
    from collections import Counter
    cnt = Counter()
    for i in range(n):
        x, y = p[i][0], p[i][1]
        for j in range(i + 1, n):
            cnt[x + p[j][0], y + p[j][1]] += 1
    ans = sum(i * (i - 1) // 2 for i in list(cnt.values()))
    print(ans)
main()


p, d = [], {}
for i in range(int(input())):
    x, y = list(map(int, input().split()))
    for a, b in p:
        u, v = a - x, b - y
        q = (u / v if v else int(2e9), u * u + v * v)
        d[q] = d.get(q, 0) + 1
    p.append((x, y))
print(sum(k * k - k for k in list(d.values())) // 4)


p, d = [], {}
s = 0
for i in range(int(input())):
    x, y = map(int, input().split())
    for a, b in p:
        q = (a + x, b + y)
        if q not in d: d[q] = 0
        s += d[q]
        d[q] += 1
    p.append((x, y))
print(s)

import math
n=int(input())

dots=[]

for i in range (n) :
	temp=list(map(int,input().split()))
	dots.append(temp)


lines={}

for i in range(n) :
	for j in range (i+1,n) :

		dx=dots[i][0]-dots[j][0]
		dy=dots[i][1]-dots[j][1]
		if dx<0 :
			dx=-dx
			dy=-dy
		if dx==0 and dy<0 :
			dy=-dy
		if (dx,dy) in lines :
			lines[(dx,dy)]+=1
		else :
			lines[(dx,dy)]=1

ans=0
for x in lines :
	t=lines[x]
	ans+=t*(t-1)/2
ans/=2
print(int(ans))

p, d = [], {}
s = 0
for i in range(int(input())):
    x, y = list(map(int, input().split()))
    for a, b in p:
        q = (a + x, b + y)
        if q not in d: d[q] = 0
        s += d[q]
        d[q] += 1
    p.append((x, y))
print(s)


from sys import stdin, stdout

n = int(stdin.readline())
points = []

for i in range(n):
    x, y = map(int, stdin.readline().split())
    points.append((x, y))

points.sort()
pair = {}

for i in range(n):
    for j in range(i + 1, n):
        if (points[j][0] - points[i][0], points[j][1] - points[i][1]) not in pair:
            pair[(points[j][0] - points[i][0], points[j][1] - points[i][1])] = 1
        else:
            pair[(points[j][0] - points[i][0], points[j][1] - points[i][1])] += 1

ans = 0
for v in pair:
    ans += pair[v] * (pair[v] - 1) // 2

stdout.write(str(ans // 2))

n = int(input())
m = list(tuple(map(int,input().split())) for _ in range(n))
mid = {}
pall = 0
for i in range(n):
    for j in range(i+1,n):
        if ((m[i][0]+m[j][0])/2, (m[i][1]+m[j][1])/2) in mid:
            pall += mid[((m[i][0]+m[j][0])/2, (m[i][1]+m[j][1])/2)]
            mid[((m[i][0]+m[j][0])/2, (m[i][1]+m[j][1])/2)] += 1
        else:
            mid[((m[i][0]+m[j][0])/2, (m[i][1]+m[j][1])/2)] = 1
print(pall)

n = int(input())
m = list(tuple(map(int,input().split())) for _ in range(n))
mid = {}
pall = 0
for i in range(n):
    for j in range(i+1,n):
        if ((m[i][0]+m[j][0])/2, (m[i][1]+m[j][1])/2) in mid:
            pall += mid[((m[i][0]+m[j][0])/2, (m[i][1]+m[j][1])/2)]
            mid[((m[i][0]+m[j][0])/2, (m[i][1]+m[j][1])/2)] += 1
        else:
            mid[((m[i][0]+m[j][0])/2, (m[i][1]+m[j][1])/2)] = 1
print(pall)

n = int(input())
points = []
cnt = {}
for i in range(n):
    x,y = list(map(int, input().split()))
    for a,b in points:
        u, v = x - a, y - b
        q = (u / v if v else int(2e9), u * u + v * v)
        cnt[q] = cnt.get(q,0) + 1
    points.append((x,y))

print(sum(k * k - k for k in list(cnt.values())) // 4)


n=int(input())
l=[]
l1=[1]*(n**2)
ans=0
for i in range(n):
    x,y=input().split()
    x,y=[int(x),int(y)]
    l.append([x,y])

from collections import Counter
count=Counter()
for i in range(len(l)):
    
    for j in range(i+1,len(l)):
        
        count[l[i][0]+l[j][0],l[j][1]+l[i][1]]+=1
ans = sum(i * (i - 1) // 2 for i in list(count.values()))
print(ans)


n = int(input())
p = []
d = dict()
for i in range(n):
    p.append(list(map(int, input().strip().split())))
    
for i in range(n):
    for j in range(i+1,n):
        x = (p[i][0] + p[j][0]) /2.
        y = (p[i][1] + p[j][1]) /2.
        if (x, y) in d.keys():
            d[(x,y)] += 1
        else:
            d[(x,y)] = 1
c = 0
for k in d.keys():
    e = d[k]
    c += e * (e-1) // 2
print(c)