Problem:
 Score : 200 points    Problem Statement There are N points in a D -dimensional space.  The coordinates of the i -th point are (X_{i1}, X_{i2}, ..., X_{iD}) .  The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2} .  How many pairs (i, j)  (i < j) are there such that the distance between the i -th point and the j -th point is an integer?      Constraints  All values in input are integers.  2 \leq N \leq 10  1 \leq D \leq 10  -20 \leq X_{ij} \leq 20  No two given points have the same coordinates. That is, if i \neq j , there exists k such that X_{ik} \neq X_{jk} .         Input Input is given from Standard Input in the following format:  N  D  X_{11}  X_{12}  ...  X_{1D}  X_{21}  X_{22}  ...  X_{2D}  \vdots  X_{N1}  X_{N2}  ...  X_{ND}       Output Print the number of pairs (i, j)  (i < j) such that the distance between the i -th point and the j -th point is an integer.        Sample Input 1 3 2
1 2
5 5
-2 8      Sample Output 1 1  The number of pairs with an integer distance is one, as follows:   The distance between the first point and the second point is \sqrt{|1-5|^2 + |2-5|^2} = 5 , which is an integer.  The distance between the second point and the third point is \sqrt{|5-(-2)|^2 + |5-8|^2} = \sqrt{58} , which is not an integer.  The distance between the third point and the first point is \sqrt{|-2-1|^2+|8-2|^2} = 3\sqrt{5} , which is not an integer.        Sample Input 2 3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3      Sample Output 2 2       Sample Input 3 5 1
1
2
3
4
5      Sample Output 3 10

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)



def solve():
    N, D = map(int, input().split())
    x_list = []
    for i in range(N):
        x_list.append(list(map(int, input().split())))

    def dist(x, y):
        d = 0
        for xi, yi in zip(x, y):
            d += (xi-yi)**2
        return d

    import math
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            d = math.sqrt(dist(x_list[i], x_list[j]))

            if d - int(d) == 0:
                cnt += 1

    print(cnt)
solve()

Solution (Python):
import math

def issq(x):
    sx = int(math.sqrt(x))
    return any([
        (sx - 1)**2 == x,
        sx**2 == x,
        (sx + 1)**2 == x,
    ])


def dist2(x, y):
    return sum((v - w)**2 for v, w in zip(x, y))


N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append(list(map(int, input().split())))

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        if issq(dist2(X[i], X[j])):
            ans += 1

print(ans)

Solution (Python):
N,D=map(int,input().split())
X=[]
for n in range(N):
    X.append(list(map(int,input().split())))
count=0
for i in range(N):
    for j in range(i+1,N):
        distance=sum([(X[i][d]-X[j][d])**2 for d in range(D)])**0.5
        if distance==int(distance):
            count+=1
print(count)

Solution (Python):
import math

N, D = map(int, input().split())

l = []
cnt = 0
for _ in range(N):
    if len(l) == 0:
        l.append([int(x) for x in input().split()])
    else:
        new_point = [int(x) for x in input().split()]
        for known_point in l:
            sum_val = 0
            for i in range(D):
                sum_val += (new_point[i] - known_point[i]) ** 2

            root = math.sqrt(sum_val)
            if root == int(root):
                cnt += 1

        l.append(new_point)

print(cnt)

Solution (Python):
import math
n,d=[int(i) for i in input().split()]
x=[[int(i) for i in input().split()] for j in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1,n):
        sum=0
        for k in range(d):
            sum+=abs(x[i][k]-x[j][k])**2
        if math.sqrt(sum)==int(math.sqrt(sum)):
            cnt+=1
print(cnt)

Solution (Python):
import sys, itertools
N,D = map(int, input().strip().split(' '))

def dis(x,y):
  return (sum((a-b)**2 for a,b in zip(x,y)))**0.5

X = [list(map(int, line.strip().split(' '))) for line in sys.stdin]

c = 0
for i,j in itertools.combinations(range(N),2):
  if dis(X[i], X[j]).is_integer():
    c += 1
print(c)

Solution (Python):
import math
N, D = (int(i) for i in input().split())
e = [[int(i) for i in input().split()] for i in range(N)]
count = 0
for i in range(N):
    for j in range(i+1, N):
        total = 0
        for k in range(D):
            total += (e[i][k]-e[j][k])**2
        if math.sqrt(total).is_integer():
            count +=1

print(count)

Solution (Python):
import numpy as np
N,D=list(map(int,input().split()))
plot=np.array([list(map(int,input().split())) for _ in range(N)])
total=0
for i in range(N):
    for j in range(i+1,N):
        tmp=(plot[i]-plot[j])**2
        ans=np.sqrt(tmp.sum())
        if ans==int(ans):
            total+=1   
print(total)

Solution (Python):
n,d=map(int,input().split())

x=[list(map(int,input().split())) for i in range(n)]


ans=0
for i in range(n):
    for j in range(1+i,n):
        dist=0
        for k in range(d):
            dist+=(x[i][k]-x[j][k])**2
        dist=pow(dist,1/2)
        if dist%1==0:
            ans+=1

print(ans)

Solution (Python):
n, d = map(int, input().split())
s = []
for _ in range(n):
    s.append([int(i) for i in input().split()])
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        y = (sum([(s[i][k] - s[j][k]) ** 2 for k in range(d)]))
        if (y ** 0.5) % 1 == 0:
            ans += 1
print(ans)

Solution (Python):
N, D = map(int, input().split())

def is_square(N):
    for i in range(1000):
        if i * i == N:
            return True
    return False

def dist(X1, X2):
    ans = 0
    for i in range(len(X1)):
        ans += (X1[i] - X2[i]) ** 2
    return ans

X = [[] for j in range(N)]
for i in range(N):
    X[i] = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if is_square(dist(X[i], X[j])):
            ans += 1
            
print(ans)

Solution (Python):
N,D = map(int,input().split())
d = {}
for i in range(40*4):
    d[i**2] = 0

def dist(y,z):
    res = 0
    for i in range(D):
        res += (y[i]-z[i])**2
    return res
ans = 0
X = [list(map(int,input().split())) for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        d2 = dist(X[i],X[j])
        if d2 in d:
            ans += 1

print(ans)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n, d = li()
x = [list(li()) for _ in range(n)]

SQUARE = set([i * i for i in range(10000)])
ans = 0

for i in range(n):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k])**2

        if dist in SQUARE:
            ans += 1

print(ans)

Solution (Python):

import sys
import math
import copy
sys.setrecursionlimit(4100000)

n,d = [int(i) for i in input().split()]
x = [[int(i) for i in input().split()] for i in range(n)]
counter = 0
for i in range(n):
    for k in range(i+1,n):
        current = 0

        for a in range(d):
            current += abs(x[i][a] - x[k][a])**2
        current = math.sqrt(current)
        if current.is_integer():
            counter += 1
print(counter)

Solution (Python):
from math import sqrt

n,d = map(int, input().split())
points = []
for i in range(n):
    points.append(list(map(int, input().split())))

count = 0

for j in range(1, n):
    for i in range(j):
        ds = 0
        for k in range(d):
            ds += (points[i][k] - points[j][k])**2
        if sqrt(ds) == int(sqrt(ds)):
            count += 1

print(count)

Solution (Python):
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
m=0
for i in range(n):
    for j in range(i+1,n):
        if i==j:continue
        c=0
        for k in range(d):
            c+=(x[i][k]-x[j][k])**2
        c=c**0.5
        if c.is_integer():
            m+=1
print(m)

Solution (Python):










import sys
import os
from io import IOBase, BytesIO


def dis(A, B):
    l = len(A)
    ans = 0
    for i in range(l):
        ans += (A[i] - B[i])**2
    return ans


def main():
    n, d = get_ints()
    arr = [0] * n
    for i in range(n):
        arr[i] = get_array()
    from math import floor, sqrt
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            dist = dis(arr[i], arr[j])
            x = floor(sqrt(dist))
            if x**2 == dist:
                ans += 1
    print(ans)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


if __name__ == "__main__":
    main()

Solution (Python):
import math
n, d = [int(i) for i in input().split()]
x = []
for i in range(n):
    x.append([int(_) for _ in input().split()])
cnt = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        a = math.sqrt(sum([(x[i][k] - x[j][k]) ** 2 for k in range(d)]))
        if a == int(a):
            cnt += 1
print(cnt//2)

Solution (Python):
from math import sqrt
inpl = lambda: list(map(int,input().split()))
N, D = inpl()
X = [ inpl() for _ in range(N) ]
ans = 0
for i in range(N):
    for j in range(i+1,N):
        dist = sqrt(sum( (X[i][d]-X[j][d])**2 for d in range(D)))
        if dist == int(dist):
            ans += 1
print(ans)

Solution (Python):
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

count = 0
for i in range(N-1):
  for j in range(i+1, N):
    f = 0
    for k in range(D):
      f += (X[i][k] - X[j][k])**2
    if math.sqrt(f).is_integer():
      count += 1

print(count)

Solution (Python):
import math
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(1,n):
    for j in range(i):
        dis=0
        for k in range(d):
            dis+=(x[i][k]-x[j][k])**2
        dis=math.sqrt(dis)
        if dis-int(dis)==0:
            ans+=1
print(ans)

Solution (Python):
n,d=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n):
    for j in range(i+1,n):
        x=0
        for z in range(d):
            x+=(l[i][z]-l[j][z])**2
        if x**0.5%1==0:
            ans+=1
print(ans)

Solution (Python):
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]

def dif(X,Y):
    return sum([(x-y)**2 for x,y in zip(X,Y)])

def judge(n):
    for i in range(1,n+1):
        if i**2 == n:
            return True
    return False

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if judge(dif(X[i],X[j])):
            cnt += 1

print(cnt)

Solution (Python):
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

def calc(x, y):
    cnt = sum((x[i] - y[i]) ** 2 for i in range(D))
    return cnt ** 0.5 == int(cnt ** 0.5)

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        ans += 1 if calc(X[i], X[j]) else 0
print(ans)

Solution (Python):
import math
[n,d] = [int(i) for i in input().split()]
x = []
tmp = 0
cnt = 0
for i in range(n):
    x.append([int(i) for i in input().split()])

for i in range(n):
    
    for j in range(i+1,n):
        for k in range(d):
            tmp += (x[i][k]-x[j][k])**2
        tmp = math.sqrt(tmp)
        if tmp - math.floor(tmp) == 0:
            cnt += 1
        tmp = 0
print(cnt)

Solution (Python):

from collections import defaultdict, deque
import math
from math import factorial
import re

def dist(x, y):
    d = 0
    for xi, yi in zip(x, y):
        d += (xi - yi) ** 2
    return math.sqrt(d)

def main():
    N, D = map(int, input().split())
    X = []
    for _ in range(N):
        x = list(map(int, input().split()))
        X.append(x)

    num = 0
    for i in range(N):
        for j in range(i+1, N):
            d = dist(X[i], X[j])
            if d.is_integer():
                num += 1
    print(num)

if __name__ == '__main__':
    main()

Solution (Python):
N, D = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(N)]


def dist(i, j):
    sum = 0
    for i0, j0 in zip(i, j):
        sum += (i0-j0)**2
    return sum**0.5


ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if dist(X[i], X[j]) == int(dist(X[i], X[j])):
            ans += 1

print(ans)

Solution (Python):
import sys
import math
input = sys.stdin.readline

N, D = map(int, input().split())
x = [list(map(int, input().split())) for i in range(N)]

count = 0
for i in range(N):
    for j in range(i+1, N):
        tmp = 0
        for d in range(D):
            tmp += abs(x[i][d] - x[j][d])**2
        t = 1
        while t*t <= tmp:
            if t*t == tmp:
                count += 1
            t += 1

print(count)

Solution (Python):
n, d = map(int, input().split())
points = []
for _ in range(n):
    points.append(list(map(int, input().split())))

ans = 0
for i in range(n):
    for j in range(i, n):
        if i == j:
            continue
        dif = 0
        for k in range(d):
            dif += abs(points[i][k] - points[j][k]) ** 2
        if dif ** 0.5 == int(dif ** 0.5):
            ans += 1
print(ans)

Solution (Python):
import math

N, D = map(int, input().split())
X_list = [0] * N
for i in range(N):
    X_list[i] = list(map(int, input().split()))

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for d in range(D):
            dist += (X_list[i][d] - X_list[j][d]) ** 2
        dist = dist ** (1/2)
        if dist - math.floor(dist) == 0:
            ans += 1
print(ans)

Solution (Python):

import sys
import math

def distsq(Y,Z):
    res = 0
    for y,z in zip(Y,Z):
        res += (y-z)**2
    return res

def solve(N: int, D: int, X: "List[List[int]]"):
    res = 0
    for i in range(len(X)-1):
        for j in range(i+1,len(X)):
            d = distsq(X[i],X[j])
            d2 = math.floor(d**0.5)
            if d == d2**2:
                res += 1
    print(res)





def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    D = int(next(tokens))  
    X = [ [ int(next(tokens)) for _ in range(D) ] for _ in range(N) ]  
    solve(N, D, X)

if __name__ == '__main__':
    main()

Solution (Python):
import math

N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]

c = 0
for i in range(N):
    for j in range(i+1,N):
        dist = 0
        for d in range(D):
            dist += (X[i][d]-X[j][d])**2
        dist = math.sqrt(dist)
        if dist-int(dist) == 0:
            c += 1

print(c)

Solution (Python):
n,d=map(int,input().split())
ps=[list(map(int,input().split())) for _ in range(n)]
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        s=0
        for x1,x2 in zip(ps[i],ps[j]):
            s+=(x1-x2)**2
        s=s**0.5
        if s==int(s):
            cnt+=1
print(cnt)

Solution (Python):
import math
import itertools

n, d = map(int, input().split())
x_list = [list(map(int, input().split())) for _ in range(n)]
count = 0
for y, z in itertools.combinations(x_list, 2):
    s = 0
    for i in range(d):
        s += (y[i] - z[i]) ** 2
    for i in range(1, int(math.sqrt(s)) + 1):
        if s == i ** 2:
            count += 1
            break
print(count)

Solution (Python):
N, D = map(int, input().split())
XD = [list(map(int, input().split())) for _ in range(N)]

ans = 0


def dist(list1, list2):
    rep = 0
    for k in range(len(list1)):
        rep += (list1[k] - list2[k])**2
    return rep**(1 / 2)


for i in range(N):
    xd1 = XD[i]
    for j in range(i + 1, N):
        xd2 = XD[j]
        if dist(xd1, xd2) == int(dist(xd1, xd2)):
            ans += 1
print(ans)

Solution (Python):

N , D = map(int,input().split())
X = []
ans = 0

for i in range(N):

    x = list(map(int,input().split()))

    X.append(x)

for i in range(N):

    for j in range(i):

        summ = 0

        for k in range(D):

            summ += (X[i][k] - X[j][k]) ** 2

        now = 0
        while now ** 2 <= summ:

            if now ** 2 == summ:
                ans += 1

            now += 1

print (ans)

Solution (Python):
N, D= map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
def d(x, y):
    ans = 0
    for i in range(D):
        ans+=(x[i]-y[i])**2
    return ans
ans = 0
for i in range(N):
    for j in range(i+1, N):
        dis = d(X[i], X[j])
        if dis==int(dis**(1/2))**2 or dis == int(dis**(1/2)+1)**2:
            ans+=1
print(ans)

Solution (Python):
import math
N,D=[int(x) for x in input().split()]
XX=[]
for i in range(N):
    XX.append([int(x) for x in input().split()])

count=0
for i,X in enumerate(XX):
    for j,Y in enumerate(XX):
        if i>=j:
            continue
        r=0
        for x,y in zip(X,Y):
            r+=(y-x)**2
        if math.sqrt(r)==int(math.sqrt(r)):
            count+=1

print(count)

Solution (Python):
N,D = map(int,input().split())
points = []
for i in range(N):
	x = list(map(int,input().split()))
	points.append(x)

ans = 0
for i in range(N-1):
	for j in range(i+1,N):
		dist = 0
		for d in range(D):
			dist += (points[i][d] - points[j][d]) ** 2
		for x in range(1,dist+1):
			if x*x > dist:
				break
			elif x*x == dist:
				ans += 1
				break
print(ans)

Solution (Python):
import math

N,D = [int(zz) for zz in input().split()]
X = [[int(zz) for zz in input().split()] for _ in range(N)]

ans = 0
for k in range(N-1):
    for i in range(k+1,N):
        tmp = 0
        for j in range(D):
            tmp += (X[k][j]-X[i][j])**2

        t = math.sqrt(tmp)
        if t == int(t):
            ans += 1

print(ans)

Solution (Python):
import math
n,d=map(int,input().split())
zahyou=[]
for i in range(n):
    point=[]
    for i in input().split():
        point.append(int(i))
    zahyou.append(point)

ans=0
for i1 in range(n-1):
    for i2 in range(i1+1,n):
        p1=zahyou[i1]
        p2=zahyou[i2]
        dist=0
        for i in range(d):
            tmp = (p1[i]-p2[i])**2
            dist+=tmp
        dist=math.sqrt(dist)
        if dist==int(dist):
            ans+=1

print(ans)

Solution (Python):
def solve():
  n,d = (int(i) for i in input().split())
  query = []
  judge = []
  for i in range(1,2001):
    judge.append((i**2))
  
  for i in range(n):
    x = list(int(i) for i in input().split())
    query.append(x)
  ans = 0
  for i in range(n):
    for j in range(n):
      if (i!=j):
        checker = 0
        for k in range(d):
         checker += (query[j][k]-query[i][k])**2
        if checker in judge:
          ans += 1
  print(ans//2)
solve()

Solution (Python):
import math
N, D = map(int, input().split())

lst = []
for _ in range(N):
    lst += [list(map(int, input().split()))]



def length(lst1, lst2):
    d = 0
    for i in range(D):
        d += (lst1[i] - lst2[i]) ** 2
    return math.sqrt(d)

count = 0
for i in range(N):
    for j in range(i+1, N):
        a = length(lst[i], lst[j])
        if a ** 2 == (int(a)) ** 2:
            count += 1

print (count)

Solution (Python):
import math

N, D = map(int, input().split())

X_list = []

for _ in range(N):
    X_list.append(list(map(int, input().split())))

res = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dist_sq = 0
        for k in range(D):
            dist_sq += (X_list[i][k] - X_list[j][k]) ** 2
        if int(math.sqrt(dist_sq)) ** 2 == dist_sq:
            res += 1

print(res)

Solution (Python):
n,d = map(int,input().split())

ls = [[int(x) for x in input().split()] for _ in range(n)]
import math
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        can = 0
        for k in range(d):
            can += (ls[i][k]-ls[j][k])**2
        if int(math.sqrt(can)) == math.sqrt(can):
            cnt +=1
        
print(cnt)

Solution (Python):
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L=[]
ans=0
for i in range(1,500):
  L.append(i**2)
for i in range(n):
  for j in range(i+1,n):
    ct=0
    for k in range(d):
      ct+=(l[i][k]-l[j][k])**2
    if ct in L:
      ans+=1
print(ans)

Solution (Python):
N, D = map(int, input().split())
arr = []
for i in range(N):
    arr.append(list(map(int, input().split())))

ans = 0
for i in range(N):
    for j in range(N):
        if i < j:
            dis = 0
            for k in range(D):
                dis += (arr[i][k]-arr[j][k])**2
            dis = pow(dis, 1/2)
            if abs(int(dis) - dis) < 0.1**10:
                ans += 1

print(ans)

Solution (Python):
N,D=map(int,input().split())
X=[[int(i) for i in input().split()] for i in range(N)]
num=0
for i in range(N):
    for j in range(i+1,N):
        a=0
        for k in range(D):
            a+=(X[i][k]-X[j][k])**2
        
        for x in range(201):
            if x**2==a:
                num+=1
                break
print(num)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, D = MAP()

X = [LIST() for _ in range(N)]
ans = 0
for i, j in combinations(X, 2):
	tmp = 0
	for k in range(D):
		tmp += (i[k]-j[k])**2
	if tmp**(1/2) == ceil(tmp**(1/2)):
		ans += 1
print(ans)

Solution (Python):
def dist(A, B):
	res = 0
	for i in range(D):
		res += (A[i] - B[i]) ** 2
	res = res ** 0.5
	return res


N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		if dist(X[i], X[j]).is_integer():
			ans += 1
print(ans)

Solution (Python):
n, d = map(int, input().split())
XN = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1, n):
        Y = XN[i]
        Z = XN[j]
        dis = 0
        for y, z in zip(Y, Z):
            dis += (y-z)**2
        if int(dis**.5) == dis**.5:
            ans += 1
print(ans)

Solution (Python):



import math

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def dist(a, b):
    d = 0
    for a1, b1 in zip(a, b):
        d += (a1-b1)**2
    d = math.sqrt(d)
    return (d-int(d)) < 0.00001

def main():
    n, d = rli()
    lp = []
    for _ in range(n):
        lx = rli()
        lp.append(lx)
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            if dist(lp[i], lp[j]):
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math
N,D = map(int,input().split())
X = []
for i in range(N):
    X.append(list(map(int,input().split())))
def check(x,y):
    s = 0
    for i in range(D):
        s += (x[i]-y[i])**2
    j = math.floor(math.sqrt(s))
    return j**2 == s
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if check(X[i],X[j]):
            ans += 1
print(ans)

Solution (Python):
def distance(A, B):
    d = 0
    for a, b in zip(A, B):
        d += (a - b) ** 2
    return d ** 0.5


n, d = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        d = distance(X[i], X[j])
        if d == round(d):
            ans += 1
print(ans)

Solution (Python):
from collections import deque
from itertools import accumulate
import sys
sys.setrecursionlimit(10**6)

mo=10**9+7

n,d=map(int,input().split())
y=[]
for i in range(n):
    x=[int(i) for i in input().split()]
    y.append(x)
    
def dist(x,y):
    a=0
    rt=False
    for i in range(len(x)):
        a+=(x[i]-y[i])**2
    if a==int(a**0.5)**2:
        rt=True
    return rt
    
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=1 if dist(y[i],y[j]) else 0


print(ans)

Solution (Python):
import numpy as np
N, D = map(int, input().split(" "))

X = [list(map(int, input().split(" "))) for _ in range(N)]

count = 0
for i in range(N):
    for j in range(i+1, N):
        x1 = X[i]
        x2 = X[j]
        dist = np.sqrt(sum([(x1[i] - x2[i]) ** 2 for i in range(D)]))
        if dist == int(dist):
            count += 1

print(count)

Solution (Python):
import math
def f(i,j):
    global N,D,X
    res = 0
    for x in range(D):
        res += (X[i][x]-X[j][x])**2
    return math.sqrt(res)
N,D = map(int,input().split())
X = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N):
    for j in range(N):
        if i<=j:
            break
        if f(i,j)%1==0:
            ans+=1
print(ans)

Solution (Python):
import math

N,D = map(int,input().split())
X = []
for i in range(N):
    X += [[int(x) for x in input().split()]]

ans = 0
for i in range(N):
    for j in range(i+1,N):
        temp = 0
        for k in range(D):
            temp += (X[i][k] - X[j][k])**2
        d = math.sqrt(temp)
        if d == int(d): ans += 1

print(ans)

Solution (Python):
N, D = map(int, input().split(" "))
X = [list(map(int, input().split(" "))) for _ in range(N)]

count = 0
for i in range(N):
    for j in range(i+1, N):
        m = sum((y-z)**2 for y, z in zip(X[i], X[j]))**(1/2)
        
        if m % 1 == 0:
            count += 1

print(count)

Solution (Python):
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in [0]*N]
ans = 0
for i in range(N):
    for j in range(i+1,N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        if abs(int(dist**0.5)**2 - dist) < 1e-6:ans+=1
print(ans)

Solution (Python):
N,D = map(int,input().split())
X = list(list(map(int,input().split()))for i in range(N))

def leng(A,B):
    ans = 0
    for i in range(len(A)):
        ans += (A[i]-B[i])**2
    return ans**0.5
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if leng(X[i],X[j]) % 1 == 0:
            ans += 1
print(ans)

Solution (Python):


import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop
import math

def main():
    n, d = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(n)]
    

    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            diff = 0
            for d1, d2 in zip(x[i], x[j]):
                diff += (d1 - d2) ** 2
            
            diff = math.sqrt(diff)
            if diff == int(diff):
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n, dim = list(map(int, input().split()))

coodi = []
count = 0
for i in range(n):
	coodi.append( list(map(int, input().split())) )

for i in range(n):
	for j in range(i+1, n):
		dist = 0
		for d in range(dim):
			dist += ( coodi[i][d] - coodi[j][d] ) ** 2
		for k in range(0, 200):
			if k ** 2 == dist:
				count += 1
				break

print(count)

Solution (Python):
import math


N, D = list(map(int, input().split(" ")))
X = [list(map(int, input().split(" ")))
     for _ in range(N)]

res = 0
for i in range(N):
    for j in range(i + 1, N):
        d2 = sum((X[i][k] - X[j][k]) ** 2 for k in range(D))
        d = math.floor(math.sqrt(d2))
        if d * d == d2:
            res += 1
print(res)

Solution (Python):
import math

def sqdist(a,b):
	temp = 0
	for i in xrange(len(a)):
		temp += (a[i] - b[i])**2
	return temp

n,d = map(int,raw_input().split())
x = []
for i in xrange(n):
	x.append(map(int,raw_input().split()))

res = 0
for i in xrange(n-1):
	for j in xrange(i+1,n):
		dist = sqdist(x[i],x[j])
		if math.sqrt(dist) == math.floor(math.sqrt(dist)):
			res += 1
print res

Solution (Python):
n, d = map(int, input().split())
points = [[]] * n
for i in range(n):
  points[i] = list(map(int, input().split()))
 
def helper(a, b):
  s = 0
  for i in range(d):
    s += (a[i] - b[i]) ** 2
  a = int(0.5 + (s ** 0.5))
  if a * a == s:
    return 1
  return 0
 
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += helper(points[i], points[j])
print(ans)

Solution (Python):
N, D = map(int, input().split())
X = [[int(i) for i in input().split()] for _ in range(N)]

ret = 0
for i in range(N-1) :
    for j in range(i + 1, N) :
        d = 0
        for k in range(D) :
            d += (X[i][k] - X[j][k]) ** 2
        
        k = 1
        while k * k < d :
            k += 1
        if k * k == d :
            ret += 1
            
print(ret)

Solution (Python):
import numpy as np

N,D = list(map(int,input().split()))

X = []

for i in range(N):
    X.append(list(map(int,input().split())))
count=0
for i in range(N-1):
    for j in range(i+1,N):
        s = np.linalg.norm(np.array(X[i])-np.array(X[j]))
        if s==int(s):
            count+=1

print(count)

Solution (Python):
import math


def check(p1, p2, D):
    sq = 0
    for i in range(D):
        sq += (p1[i] - p2[i]) ** 2
    rt = int(math.sqrt(sq))
    return rt**2 == sq


def main():
    N, D = map(int, input().split())
    P = [tuple(map(int, input().split())) for _ in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if check(P[i], P[j], D):
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()