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):
N, D= map(int, input().split())


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

count=0

for i in range(len(X)-1):
    for j in range(i+1, len(X)):
        tmp=0
        for k in range(D):
            tmp+=(X[i][k]-X[j][k])**2
        tmp=tmp**0.5
        if tmp.is_integer():
            count+=1
print(count)

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

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

print(cnt)

Solution (Python):


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

for i in range(N):
    X.append(list(map(int, input().split())))

count = 0
for i in range(N):
    x_i = X[i]
    for j in range(i+1, N):
        x_j = X[j]
        dist = 0
        for d in range(D):
            dist += (x_i[d] - x_j[d])*(x_i[d] - x_j[d])

        dist = dist**0.5
        if dist - int(dist) == 0:
            count += 1

print(count)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline






















def main():

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

	Xs = []
	for i in range(N):
		tmp = input().split(" ")
		tmp = [int(s) for s in tmp]
		Xs.append(tmp)

	ans = 0
	for i, val in enumerate(Xs):
		for ii in range(i+1, len(Xs)):

			vol = Xs[ii]

			to = 0
			for j in range(D):
				tmp = (abs(vol[j] - val[j]))**2
				to += tmp

			to = to ** (1/2)
			
			if to.is_integer():
				ans += 1

	print(ans)




if __name__ == "__main__":
	main()

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        yy = 0
        for y in ((X[i][k] - X[j][k])**2 for k in range(D)):
            yy += y
        yyy = math.sqrt(yy)
        if yyy == int(yyy):
            cnt+=1
print(cnt)

Solution (Python):
import math

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

cnt = 0

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

print(cnt)

Solution (Python):

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

X=[]

for i in range(N):
    X.append(list(map(float,input().split())))

num=0
for i in range(N):
    for j in range(i+1,N):
        dis = 0
        for d in range(D):
            dis += (X[i][d]-X[j][d])**2
        dis = dis**0.5
        dis2 = float(round(dis))

        if abs(dis-dis2) < 0.0000000001:
            num+=1
print(num)

Solution (Python):
import math

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

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

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

Solution (Python):
import numpy as np

N, D = map(int, input().split())
l = []
ans = 0
for i in range(N):
  l.append([int(x) for x in input().split()])
for i in range(N-1):
  for j in range(i+1, N):
    d = 0
    for k in range(D):
      d += (l[i][k] - l[j][k]) ** 2
    d = np.sqrt(d)
    if d % 1 == 0:
      ans += 1
print(ans)

Solution (Python):
import math

def dist(a,b):
	if len(a)!=len(b):
		return -1
	else:
		tmp=0
		for i in range(len(a)):
			tmp+=(a[i]-b[i])**2
		return math.sqrt(tmp)

n,d=map(int,input().split())
x=[[] for i in range(n)]
for i in range(n):
	x[i]=list(map(int,input().split()))
ans=0
for i in range(n):
	for j in range(n):
		if i>=j:
			pass
		else:
			tmp=dist(x[i],x[j])
			if tmp.is_integer()==True:
				ans+=1
print(ans)

Solution (Python):
N, D = map(int, input().split())
pos = [0]*N
for p in range(N):
    pos[p] = [int(x) for x in input().split()]
ans = 0

for i in range(N):
    for j in range(i):
        dis = 0.0
        for k in range(D):
            dis += ((pos[i][k] - pos[j][k]) ** 2)
        if (dis)**0.5 % 1 == 0:
            ans += 1

print(ans)

Solution (Python):
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def dist(a, b):
    sum = 0
    for i in range(len(a)):
        sum += (a[i]-b[i])**2
    return sum**(1/2)


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

    for i in range(n):
        x[i] = list(map(int, input().split()))
    count = 0
    for i in range(n-1):
        for j in range(i+1, n):
            dis = dist(x[i], x[j])
            
            if dis == math.floor(dis):
                count += 1

    print(count)


if __name__ == '__main__':
    main()

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(N)[i+1::]:
        result = 0
        for k in range(D):
            result += (X[i][k] - X[j][k])**2
        result = result**0.5
        if result == int(result):
            ans += 1

print(ans)

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


def bisearch(f, n):
    l = 0
    r = n
    fl = f(l)
    fr = f(r)
    while l <= r:
        m = (l + r) // 2
        fm = f(m)
        if fm == n:
            return m
        elif fm > n:
            r = m - 1
            fr = f(r)
        else:
            l = m + 1
            fl = f(l)

def is_distance_integer(lista, listb):
    sum_ = 0
    for a, b in zip(lista, listb):
        sum_ += (a - b)** 2
    return bisearch(lambda n: n*n, sum_)


sum_ = 0
for i in range(N - 1):
    for xn in xnds[i + 1:]:
        if is_distance_integer(xnds[i], xn):
            sum_ += 1
print(sum_)

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

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

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

Solution (Python):
import math

n, d = input().split()
n = int(n)
d = int(d)

points = []
counter = 0

for i in range(n):
    points.append(input().split())

for p in points:
    for i in range(d):
        p[i] = int(p[i])
        

for p in points:
    for q in points:
        if p == q:
            continue
        dist = 0
        for i in range(d):
            dist += (p[i] - q[i])**2
        
        dist = math.sqrt(dist)
        if dist.is_integer():
            counter += 1

print(int(counter/2))

Solution (Python):

import math
n, d = map(int, input().split())

x = list()
for _ in range(n):
    array = list(map(int, input().split()))
    x.append(array)

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
        dist_sqrt = math.sqrt(dist)
        if dist == math.floor(dist_sqrt) ** 2:
            ans += 1

print(ans)

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

l = [ list(map(int,input().split())) for i in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        sum = 0
        for k in range(d):
            sum += (l[j][k] - l[i][k])**2
        
        sum = sum**(1/2)
        if sum == int(sum):
            count += 1
        
print(count)

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

x_list=[]

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

ans=0
for i in range(n):
  for j in range(i+1,n):
    
    tmp=0
    for s in range(d):
      
      tmp+=(x_list[i][s]-x_list[j][s])**2
    kai=math.sqrt(tmp)
    if kai.is_integer():
      ans+=1
print(ans)

Solution (Python):

"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())


dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')


ABT = zip(A, B, totAB)
result = 0

sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)


(x >> i) & 1


dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

add = 1 
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)


li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    


org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)




    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


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



    
def main(): 
    res = 0
    for cb in itertools.combinations(range(N),2):
        i, j = cb
        r2= float(0.0)
        for d in range(D):
            r2 += (X[i][d] - X[j][d])**2.
        r = float(math.sqrt(r2))
        if r.is_integer():
            res +=1
    print(res)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Solution (Python):
import math
n,d=map(int,input().split())
x=[]

def distance(list1,list2):
    dis=0
    for i in range(len(list1)):
        dis=dis+(list1[i]-list2[i])*(list1[i]-list2[i])
    return dis
                                     

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

ans=0
for i in range(n):
    for j in range(n-i-1):
        a=distance(x[i],x[i+j+1])
        if a==int((math.sqrt(a)))*int((math.sqrt(a))):
            ans+=1
print(ans)

Solution (Python):
import sys
import math

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

if __name__ == "__main__":
    n, d = map(int, input().split())
    xl = [list(map(int, input().split())) for i in range(n)]

    count = 0
    for i in range(n):
        for j in range(i+1, n):
            sq = math.sqrt(sum([abs(xl[i][k] - xl[j][k])**2 for k in range(d)]))
            if sq == int(sq):
                count += 1

    print(count)

Solution (Python):
import numpy as np

n,d = list(map(int,input().split()))
dis = []
data = [None] * n
for i in range(n):
  data[i] = [[int(s) for s in input().split()]]
  

count = 0

for i in range(n):
  for j in range(i):
    if data[i] != data[j]:
      a = np.array(data[i])
      b = np.array(data[j])
      l = np.linalg.norm(b-a)
      
      if (l.is_integer()):
        count += 1
print(count)

Solution (Python):
import math
def dist(x,y):
    return math.sqrt(sum([(s-t)**2 for s,t in zip(x,y) ]) )

N,D = map(int, input().split() )
x=[]
for i in range(N):
    x.append(list(map(int, input().split() )))
count = 0
for i in range(N):
    xs = x[i+1:N]
    dists = [dist(x[i], y) for y in xs]
    count += sum([s - int(s) == 0 for s in dists ])
print(count)

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

ans = 0
for i in range(N):
    a = X[i]
    for b in X[i+1:]:
        u = a - b
        if np.linalg.norm(u).is_integer():
            ans += 1

print(ans)

Solution (Python):
import numpy

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

c = 0
for i in range(n-1):
    for j in range(i+1, n):
        if numpy.linalg.norm(x[i]-x[j]).is_integer():
            c+=1
print(c)

Solution (Python):
import numpy as np


def main():
    N, D = map(int, input().split())
    X = [None] * N
    for n in range(N):
        X[n] = [int(x) for x in input().split()]

    X = np.array(X)
    dist = np.sum((X[:, None] - X[None, :]) ** 2, axis=-1) ** 0.5

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

main()

Solution (Python):
n,d = map(int,input().split())
xd = [[int(i) for i in input().split()] for i in range(n)]
cnt = 0
for i in range(n):
  for j in range(n):
    if i != j:
      temp = 0
      for k in range(d):
        temp += (xd[i][k]-xd[j][k])**2
      if float.is_integer(temp**0.5):
        cnt += 1
print(cnt // 2)

Solution (Python):
import math

n, d = map(int, input().split())

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

answer = 0
for i in range(n):
    for j in range(i+1, n):
        ans = 0
        for k in range(d):
            ans += (x[i][k] - x[j][k])**2
        ans = math.sqrt(ans)
        if ans.is_integer():
            answer += 1

print(answer)

Solution (Python):
n,d = map(int, input().split(" "))
count = 0
values = []

for _ in range(n):
    values.append([int(x) for x in list(input().split(" "))])


for i in range(n-1):
    for j in range(i+1,n):
        total = 0
        for k in range(d):
            total += (values[i][k] - values[j][k])**2
        distance = total**(1/2)
        if distance%1 == 0:
            count += 1

print(count)

Solution (Python):
import math

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

def dist_int(p0, p1):
    dd = 0
    for i in range(D):
        x = p0[i] - p1[i]
        dd += x*x

    d = math.sqrt(dd)
    return math.ceil(d) == math.floor(d)

cnt = 0
for i in range(N):
    for j in range(N):
        if j >= i:
            continue
        p0 = P[i]
        p1 = P[j]
        if dist_int(p0,p1):
            cnt += 1

print(cnt)

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



def dist(x, y):
    d = 0
    for i in range(len(x)):
        d += (x[i]-y[i])**2

    return d

def check(x, y):
    d = dist(x, y)
    rt = int(d**0.5+1e-6)
    return rt*rt == d


n, d = map(int, input().split())
pts = [list(map(int, input().split())) for _ in range(n)]

res = 0
for i in range(n):
    for j in range(i+1, n):
        res += check(pts[i], pts[j])

print(res)

Solution (Python):
from math import sqrt
N, D = map(int, input().split())
xlist = [list(map(int, input().split())) for x in range(N)]

cnt = 0
for i in range(N):
	for j in range(i+1, N):
		il = xlist[i]
		jl = xlist[j]
		total = 0
		for n in range(D):
			total = total + (il[n]-jl[n])**2
		
		if sqrt(total).is_integer():
			cnt = cnt + 1

print(cnt)

Solution (Python):

import math


def read_input():
    n, d = map(int, input().split())

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

    return n, d, points


def check_good_distance(p1, p2):
    dist = 0
    for e1, e2 in zip(p1, p2):
        temp = abs(e2 - e1)
        dist += temp ** 2

    dist = math.sqrt(dist)

    if dist == int(dist):
        return True
    else:
        return False


def submit():
    n, d, points = read_input()

    count = 0
    for i, p1 in enumerate(points):
        for p2 in points[i+1:]:
            if check_good_distance(p1, p2):
                count += 1

    print(count)




if __name__ == '__main__':
    submit()

Solution (Python):
import math
N, D = map(int, input().split())
X = [0]*N
for x in range(N):
    X[x] = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    for j in range(N-i-1):
        j += i+1
        dis2 = 0
        for t in range(D):
            dis2 += (X[i][t]-X[j][t])**2
        dis = math.sqrt(dis2)
        if dis - math.floor(dis)==0.0:
            ans += 1

print(ans)

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

y = []
a = 1
while (a * a) < 16001:
    y.append(a * a)
    a += 1

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        val = 0
        for k in range(D):
            val += (x[i][k] - x[j][k]) ** 2
        if val in y:
            cnt += 1
print(cnt)

Solution (Python):

import math

n, d = map(int, input().split())

count = 0

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

for i in range(n-1):
    for j in range(i+1, n):
        point_i = points[i]
        point_j = points[j]
        a = ((point_i[k] - point_j[k]) ** 2 for k in range(d))
        distance = math.sqrt(sum(a)) 
        if int(distance) == distance:
            count += 1
print(count)

Solution (Python):
import math

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

point_list = []

for i in range(N):
    point_list.append(list(map(int, input().split())))

count = 0 

for j in range(N):
    for k in range(j+1,N):
        distance_pow = 0 
        for l in range(D):
            distance_pow += (point_list[j][l] - point_list[k][l]) ** 2
        distance = math.sqrt(distance_pow)
        
        if distance % 1 == 0:
            count += 1

print(count)

Solution (Python):
def main():
	import sys
	import numpy as np
	input = sys.stdin.readline
	N, D = list(map(int, input().split()))
	X = []
	for i in range(N):
		X.append(np.array(list(map(int, input().split()))))

	count = 0
	for i in range(N):
		for j in range(i+1, N):
			f = np.linalg.norm(X[i] - X[j])
			if f.is_integer():
				count += 1
	print(count)

if __name__ == '__main__':
    main()

Solution (Python):
N, D = [int(elem) for elem in input().split()]
coords = [[int(elem) for elem in input().split()] for _ in range(N)]
assert len(coords[0]) == D

def is_squared(num):
    i = 1
    while i * i <= num:
        if i * i == num:
            return True
        i += 1
    return False


num_pairs = 0
for i in range(N):
    c1 = coords[i]
    for j in range(i + 1, N):
        c2 = coords[j]
        sqaured_dist = sum((p1 - p2) ** 2 for p1, p2 in zip(c1, c2))
        if is_squared(sqaured_dist):
            num_pairs += 1
print(num_pairs)

Solution (Python):
import math
n,d=map(int,input().split())
x=[]
ans=0
for i in range(n):
    x.append(list(map(int,input().split())))
for i in range(n):
    for j in range(i):
        sum = 0
        for k in range(d):
            sum += (x[i][k]-x[j][k])*(x[i][k]-x[j][k])
        if math.sqrt(sum).is_integer():
            ans+=1
print("{}".format(ans))

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

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

cnt = 0

for i in range(n):
    for j in range(n):
        if i <= j:
            continue
        s = 0
        for k in range(d):
            s += (abs(li[i][k] - li[j][k]) ** 2)
        else:
            s = str(s**0.5)
            if s[-1] == "0" and s[-2] == ".":
                cnt += 1
        
print(cnt)

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

e=10**(-10)
count=0
for i in range(N-1):
    for j in range(i+1,N):
        
        tmp=0
        for d in range(D):
            tmp+=(X[i][d]-X[j][d])**2
        tmp=tmp**(1/2)

        if (tmp-tmp//1)<e:
            count+=1

print(count)

Solution (Python):
import math

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

  ans = 0
for i in range(1,n):
  for j in range(i):
    list1 = x_array[i]
    list2 = x_array[j]
    count = 0
    for k in range(len(list1)):
      count += (list1[k]-list2[k]) ** 2

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

print(ans)

Solution (Python):
maxd2 = 40**2*10
intd2 = set()
maxi = int(maxd2**(1/2))+10
for i in range(maxi):
    intd2.add(i**2)


n, d = list(map(int, input().split()))
x = []
for _ in range(n):
    xi = list(map(int, input().split()))
    x.append(xi)
    
cnt = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        distance = sum([(x[i][k]-x[j][k])**2 for k in range(d)])
        if distance in intd2:
            cnt += 1
            
print(cnt//2)

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

ans=0
for i in range(N):
	for j in range(i+1,N):
		t=0
		for x, y in zip(X[i],X[j]):
			t+=(x-y)**2	

		for h in range(1,10000):
			if t==h**2:
				ans+=1
				break

print ans

Solution (Python):
from math import sqrt

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

counter = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for it in range(D):
            dist += (points[i][it]-points[j][it])**2
        dist = sqrt(dist)

        if dist.is_integer() == True:
            counter += 1

print(counter)

Solution (Python):
from math import sqrt
from itertools import combinations
N, D = map(int, input().split())
X = [[] for _ in range(N)]
for i in range(N):
    X[i] = list(map(int, input().split()))

def dist(p1, p2):
    ret = 0
    for a,b in zip(p1, p2):
        ret += abs(a-b)**2
    ret = sqrt(ret)
    return ret-int(ret)==0
ans = 0
for i,j in combinations(list(range(N)), 2):
    ans += dist(X[i], X[j])
print(ans)

Solution (Python):

import numpy as np


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


N,D=acinput()
X=[]
for i in range(N):
        X.append(np.array(acinput()))


count=0
for i in range(N-1):
        for j in range(i+1,N):
                tmp=np.linalg.norm(X[i]-X[j])
                if tmp%1.0==0:
                        count+=1


print(count)

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

def diff(A,B,D):
    y = []
    for l in range(D):
        y.append((A[l] - B[l])**2)
    return math.sqrt(sum(y))

count = 0
for i in range(N):
    for j in range(i+1,N):
        y = diff(X[i], X[j], D)
        if y % 1 == 0:
            count += 1
print(count)

Solution (Python):
n, d = map(int, input().split())
points = []
ints = 0

for i in range(n):
    points.append(tuple(map(int, input().split())))

for i in range(n):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += pow(points[i][k]-points[j][k], 2)
        dist = pow(dist, 1/2)
        if dist.is_integer():
            ints += 1

print(ints)

Solution (Python):
n,m = (int(i) for i in input().split())  
d = [[int(i) for i in input().split()] for i in range(n)] 
count = 0
for i,v in enumerate(d):
  for j in range(i+1,len(d)):
    sum = 0
    
    for k in range(len(v)):
      sum += abs(d[i][k] - d[j][k])**2
    if pow(sum,1/2).is_integer():
      count += 1

print(count)

Solution (Python):
import math
import numpy as np

N, D = map(int, input().split())
xss = np.array([[int(s) for s in input().split()] for _ in range(N)])


cnt = 0
for i in range(N):
    for j in range(i):
        diff2 = ((xss[i] - xss[j])**2).sum()
        d = int(np.sqrt(diff2))
        if d * d == diff2: 
            cnt += 1

print(cnt)

Solution (Python):
from math import sqrt
n, d = map(int, input().split())
x=[]
for _ in range(n):
  x.append(list(map(int, input().split())))

cnt=0
for i in range(n):
  for j in range(i+1, n):
    tmp=0
    for yi, zi in zip(x[i], x[j]):
      tmp+=(yi-zi)**2
    tmp=sqrt(tmp)
    if tmp==int(tmp):
      cnt+=1

print(cnt)

Solution (Python):
import math

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

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

cnt = 0
tmp = 0

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

print(cnt)

Solution (Python):
n,d = [int(i) for i in input().split()]
a=[]
ctr=0
for i in range(n):
  c= [int(i) for i in input().split()]
  a.append(c)

for i in range(n-1):
  for j in range(i+1,n):
    ans=0
    for k in range(d):
     
      ans+=pow(a[i][k]-a[j][k],2)
    ans = pow(ans,0.5)
    if(ans - int(ans) < 0.000001):ctr+=1
print(ctr)

Solution (Python):
import math

N, D = map(int, input().split())
X = [[0]*D]*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):
        count = 0
        for k in range(D):
            count += (X[i][k] - X[j][k]) ** 2
        if math.sqrt(count).is_integer():
            ans += 1
            
print(ans)

Solution (Python):
import math
N,D = map(int, input().split())
n=N
e = [[int(i) for i in input().split()] for i in range(n)]
Num=0
for x in range(0,N):
    for y in range(x+1,N):
        S=0
        for z in range(0,D):
            S=S+(e[x][z]-e[y][z])**2
        A=math.sqrt(S)
        if A%1==0:
            Num=Num+1


print(Num)

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-1):
	for j in range(i+1,n):
		t=0
		for l in range(d):
			t+=(x[i][l]-x[j][l])**2
		if t**(1/2)%1==0:
			ans+=1
print(ans)

Solution (Python):

def dist(x1, tmpx):
    d2 = 0
    for k in range(len(x1)):
        d2 += (x1[k] - tmpx[k])**2
    d = d2 ** (1/2)
    return d

n,d = map(int, input().split())
x1 = []
x1.append(list(map(int,input().split())))
cnt = 0
for i in range(1,n):
    tmpx = list(map(int,input().split()))
    for j in range(0,i):
        d = dist(x1[j],tmpx)
        if d == int(d):
            cnt += 1
    x1.append(tmpx)
print(cnt)

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

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

cnt = 0
import itertools
for i in itertools.combinations(range(N), 2):
  dist = 0
  for j in range(D):
    dist += (X[i[0]][j] - X[i[1]][j]) ** 2
  if is_integer_num(dist ** (1/2)):
    cnt += 1
print(cnt)

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

X = []
ans = 0

for i in range(N):
    X.append(list(map(int, input().split())))

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
        f = f**(1/2)
        if f.is_integer():
            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)]

def isqrt(n):
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

cnt = 0
for i in range(n):
    for j in range(i+1, n):
        sum_ = 0
        for d in range(D):
            sum_ += pow((X[i][d] - X[j][d]), 2)
        a = isqrt(sum_)
        if a * a == sum_:
            cnt += 1
print(cnt)