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=[]
ans=0
for i in range(n):
    x.append(list(map(int,input().split())))

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

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

ans = 0
for i,Y in enumerate(X[:-1]):
	for j,Z in enumerate(X[i+1:]):
		res = 0
		for y,z in zip(Y,Z):
			res += (y-z)**2
		if res**0.5%1 == 0:
			ans += 1
print(ans)

Solution (Python):
import math

n, d = [int(elem) for elem in input().split()]
xs = []
for i in range(0, n):
    x = [int(elem) for elem in input().split()]
    xs.append(x)

def kyori(ys, zs):
    result = 0
    for y, z in zip(ys, zs):
        result += (y - z) ** 2
    return math.sqrt(result)
    
cnt = 0
for i in range(0, n):
    for j in range(i+1, n):
        res = kyori(xs[i], xs[j])
        if res == int(res):
            cnt += 1
print(cnt)

Solution (Python):
import numpy as np

n,d = map(int,input().split())
dl =[0]*n
for i in range(n):
    dl[i] = list(map(int,input().split()))

cnt = 0
for i in range(len(dl)):
    for j in range(len(dl)):
        if i ==j:
            break
        if np.linalg.norm(np.array(dl[i])-np.array(dl[j])).is_integer():
            cnt +=1
            
print(cnt)

Solution (Python):
n,d = map(int, input().split(' '))
dot = [list(map(int, input().split(' '))) for i in range(n)]
def dist(Y, Z):
  temp = 0
  for y,z in zip(Y,Z):
    temp += abs(y-z)**2
  return temp**0.5

ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    ret = dist(dot[i], dot[j])
    if int(ret) == ret:
      ans += 1
print(ans)

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

ans = 0  
for i in range(n):
  for j in range(i+1,n):
    dij = sum([(x[i][_] - x[j][_])**2 for _ in range(d)])**(1/2)
    if dij % 1 == 0:
      ans +=1
      
print(ans)

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
from operator import itemgetter, mul
from copy import deepcopy,copy
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

def main():
    n,d=MAP()
    x = [LIST() for _ in range(n)]
    comb=combinations(range(n),2)
    ct=0
    for r in comb:
        
        dis=0
        for i in range(d):
            dis+=(x[r[0]][i]-x[r[1]][i])**2

        if int(sqrt(dis)) == sqrt(dis):
            ct+=1

    print(ct)






if  __name__=='__main__':
    main()

Solution (Python):
import math
n,d =  map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
count = 0
for xi in range(len(x)):
  for xj in range(xi+1,len(x)):
    dists = [(x[xi][k]-x[xj][k])**2 for k in range(d)]          
    dist = math.sqrt(sum(dists))
    
    if dist.is_integer():
      count+=1
print(count)

Solution (Python):
N,D = map(int,input().split())
X_list = []
for i in range(N):
    X_list.append(list(map(int,input().split())))
def try_square_root_naive(n):
    m = int(n**.5)
    return True if abs(m*m - n) < 1e-6 else None
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        L = 0
        for d in range(D):
            L += (X_list[i][d]-X_list[j][d])**2
        if try_square_root_naive(L):
            cnt += 1
print(cnt)

Solution (Python):
from math import sqrt
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
def distance(x1, x2):
    ans = 0
    for d1, d2 in zip(x1, x2):
        ans += (d1 - d2) ** 2
    return float(sqrt(ans)).is_integer()

res = 0

for i in range(n):
    for j in range(n):
        if j == i:
            continue
        if distance(x[i], x[j]):
            res += 1

print(res // 2)

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

flg = 0
for i in range(N):
    for j in range(i, N):
        if i==j:
            continue
        d = 0
        for k in range(D):
            d += pow((X[i][k] - X[j][k]), 2)
        if pow(d, 0.5).is_integer():
            flg += 1
print(flg)

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

N, D = [int(x) for x in stdin.readline().rstrip().split()]

X = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

cnt = 0

for i in range(N):
    for j in range(i+1, N):
        dist = 0.0
        for k in range(D):
            dist += abs(X[i][k] - X[j][k]) * abs(X[i][k] - X[j][k])
        dist = math.sqrt(dist)

        if dist.is_integer():
            cnt += 1

print(cnt)

Solution (Python):

import time
import re
import math
import fractions

def main():
    N,D=map(int,input().split())
    points=[]
    for a in range(N):
        points.append(list(map(int,input().split())))
        count=0
    for a in range(N):
        for b in range(a+1,N):
            if getD(points[a],points[b])%1==0:
                count+=1
    print(count)
def getD(xarr,yarr):
    d=0
    for a in range(len(xarr)):
        d+=(xarr[a]-yarr[a])**2
    return math.sqrt(d)
start=time.time()
main()

Solution (Python):
n, d = map(int, input().split())
X = []
for _ in range(n):
    l = list(map(int, input().split()))
    X.append(l)
mat = [[0 for _ in range(n)] for _ in range(n)]
import numpy as np
def f(a,b):
    return sum([(i-j)**2 for i, j in zip(a, b)])
for i in range(n):
    for j in range(i+1, n):
        mat[i][j] = np.sqrt(f(X[i], X[j]))
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if mat[i][j].is_integer():
            ans +=1
print(ans)

Solution (Python):
n,d=map(int,input().split())
L=[]
ans=0
for _ in range(n):L.append(list(map(int,input().split())))
for i in range(n):
    for j in range(n):
        if i==j:pass
        else:
            p=0
            for k in range(d):p+=(L[i][k]-L[j][k])**2
            if p**0.5==int(p**0.5):ans+=1
print(ans//2)

Solution (Python):
import numpy as np
import math

n,d=list(map(int, input().split()))
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
xn =np.asarray(x)
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        t = xn[i,:] - xn[j,:]
        t2 = np.square(t)
        t3 = np.sum(t2)
        if (np.sqrt(t3)).is_integer():
            cnt += 1
            
print(cnt)

Solution (Python):

import math

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

space = []
count = 0

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

for i in range(N):
    for j in range(i+1, N):
        if i != j:
            num = 0
            for k in range(D):
                num += (space[i][k] - space[j][k])**2
            num = math.sqrt(num)
            if int(num) - num == 0:
                count += 1

print(count)

Solution (Python):
import numpy as np
n, d = map(int, input().split())

x = np.zeros((n,d))

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

count = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        d = np.linalg.norm(x[i,:]-x[j,:])
        if d == int(d):
            count += 1

print(count)

Solution (Python):
from sys import exit
import math

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

Xs = []

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

count = 0

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

print(count)

Solution (Python):

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(N-i-1):
        J=i+j+1
        dist = 0
        for k in range(D):
            dist+=(X[i][k]-X[J][k])**2
        flag = 0
        for d in range(dist):
            if (dist/(d+1)) == d+1:
                flag = 1
        if flag == 1:
            count+=1
print(count)

Solution (Python):
def dst(Xi, Xj):
  S = 0
  for i in range(len(Xi)):
    S += (Xi[i] - Xj[i]) ** 2
  return S

def isz(X):
  c = 0
  while c ** 2 < X:
    c += 1
  if c ** 2 == X:
    return True
  else:
    return False


N, D = map(int, input().split())
X = []
s = 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, N):
    if i != j and isz(dst(X[i], X[j])):
      s += 1
print(s)

Solution (Python):

n, d = list(map(int, input().split()))
x = []
for i in range(n):
    _x = list(map(int, input().split()))
    x.append(_x)
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
        _r = dist**0.5
        if int(_r) == _r:
            ans += 1
print(ans)

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

def distance(x,y,d):
    inner=0
    for i in range(d):
        inner+=(x[i]-y[i])**2
    return math.sqrt(inner)

ans=0
for i in ls:
    for j in ls:
        if distance(i,j,d).is_integer() and distance(i,j,d)!=0:
            ans+=1

print(int(ans/2))

Solution (Python):
import math

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):
        norm = 0
        for k in range(D):
            norm += (X[i][k] - X[j][k]) ** 2
        norm = math.sqrt(norm)

        if norm == int(norm):
            count += 1
print(count)

Solution (Python):
import itertools, math

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

for p_1, p_2 in itertools.combinations(points, 2):
    dist = 0
    for i in range(d):
        dist += (p_1[i] - p_2[i]) ** 2
    if math.sqrt(dist).is_integer():
        count += 1
        
print(count)

Solution (Python):
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())
input = [list(map(int, input().split())) for i in range(n)]
count = 0

for i in range(n):
    for j in range(i+1, n):
        ans = 0
        for k in range(d):
            ans += (input[i][k] - input[j][k])**2
        ans = ans**(1/2)
        if is_integer_num(ans):
            count += 1
print(count)

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

import itertools
cnt = 0

for x, y in list(itertools.combinations(X, 2)):
    dist = 0
    for i in range(D):
        dist += (x[i]-y[i])**2
    if (dist**0.5)%1==0:
        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())))
score = 0
for i in range(n):
  for j in range(n):
    tmp = 0
    for dd in range(d):
      tmp += ( x[i][dd] - x[j][dd] ) ** 2
    sq = math.floor(tmp ** (1/2))
    if tmp == sq ** 2:
      score += 1
print((score-n)//2)

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

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

seisuuninaru = {i**2 for i in range(128)}

cnt = 0
for i in range(N):
    for j in range(i):
        kyori = 0
        for k in range(len(points[i])):
            kyori += (points[i][k] - points[j][k]) ** 2
        if kyori in seisuuninaru:
            cnt += 1

print(cnt)

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

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

count = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        if dist**(0.5)%1 == 0:
            count += 1

print(count)

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

def squares(a,b):
    return (a-b)**2

count = 0
for i in range(n):
    for j in range(i+1,n):
        total = 0
        for x in range(d):
            total = total + squares(x_list[i][x],x_list[j][x])
        if ((total)**(1/2)).is_integer():
            count = count +1

print(count)

Solution (Python):
import numpy as np

words = lambda t : list(map(t, input().split()))
n,d = words(int)

a = []
for i in range(n):
    k = words(int)
    a.append(k)

def dist(x,y):
    ttl = 0
    for x1,y1 in zip(x,y):
        ttl += (abs(x1 - y1))**2
    return np.sqrt(ttl)

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ds = dist(a[i], a[j])
        
        if ds == round(ds):
            ans += 1

print(ans)

Solution (Python):
import math
        
def func(A, B):
    tmp = 0
    for a, b in zip(A,B):
        tmp += (a- b)**2
        
    return math.sqrt(tmp)
N, D = list(map(int, input().split(" ")))

X = []
cnt = 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):
        ans = func(X[i], X[j])
        if ans % 1 == 0:
            cnt += 1
            
print(cnt)

Solution (Python):
import math
n, m = map(int, input().split())
temp = []
a = []
for i in range(n):
    temp = []
    temp = input().split()
    a.append(temp)
ans = 0
for i in range(n):
    for j in range(i+1, n):
        res = 0
        for k in range(m):
            res += abs(int(a[j][k]) - int(a[i][k]))*abs(int(a[j][k]) - int(a[i][k]))
        res2 = math.sqrt(res)
        if int(res2) == res2:
            ans += 1
print(ans)

Solution (Python):
import numpy as np

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

X = np.array(X)

cnt = 0
for i in range(N):
    for j in range(i,N):
        if i != j:
            distance = np.sqrt(np.power(X[i]-X[j], 2).sum())
            if distance.is_integer():
                cnt += 1

print(cnt)

Solution (Python):
import math

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

cnt = 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]) * (x[i][k] - x[j][k])
		distsqrt = math.floor(math.sqrt(dist))
		if dist == distsqrt * distsqrt:
			cnt += 1

print(cnt)

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

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

ans = 0

for i in range(N):
    for j in range(i+1, N):
        distance = sum([(a-b)**2 for a, b in zip(zahyo[i], zahyo[j])])
        distance = distance ** (1/2)
        if distance == math.ceil(distance):
            ans += 1

print(ans)

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

print(cnt // 2)

Solution (Python):
import math

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

def dist(x, y):
    tmp = 0.0
    for i in range(d):
        tmp += (x[i] - y[i]) ** 2
    return math.sqrt(tmp)


count = 0
for i, elm in enumerate(points):
    for j in range(i+1, n):
        if dist(elm, points[j]).is_integer():
            count += 1

print(count)

Solution (Python):

import sys
input = sys.stdin.readline


sys.setrecursionlimit(10**6)


def kyori(l1, l2):
    goukei = 0
    for i in range(len(l1)):
        goukei += (l1[i] - l2[i]) ** 2
    return goukei**0.5


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 (kyori(x[i], x[j]).is_integer()):
            
            ans += 1
print(ans)

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

n=0
for i in range(N):
    for j in range(i+1, N):
        d2 = 0
        for k in range(D):
            diff = X[i][k]-X[j][k]
            d2 += diff * diff
        if int(d2**0.5)	* int(d2**0.5) == d2:
            n+=1

print(n)

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

import math

cnt = 0

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

Solution (Python):
N, D = [int(x) for x in input().split()]
x_list = [[int(x) for x in input().split()] for _ in range(N)]
sq = [n*n for n in range(1000)]
cnt = 0
for i, xi in enumerate(x_list):
    for xj in x_list[i+1:]:
        dist = sum([(y-z)*(y-z) for y, z in zip(xi, xj)])
        cnt += (dist in sq)
print(cnt)

Solution (Python):
from sys import stdin
N, D = [int(x) for x in stdin.readline().rstrip().split()]
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]

cnt = 0
for j in range(N):
    for k in range(j, N):
        dis = 0
        for d in range(D):
            dis += (X[j][d] - X[k][d]) ** 2
        if dis > 0 and (dis ** 0.5) % 1 == 0:
            cnt += 1

print(cnt)

Solution (Python):
N, D = [int(nd) for nd in input().split()]
X = []
for n in range(N):
  X.append([int(x) for x in input().split()])
  
ans = 0
for i in range(0, N-1):
  for j in range(i+1, N):
    d_ij = 0
    for d in range(D):
      d_ij += (X[i][d] - X[j][d]) ** 2
    d_ij = (d_ij) ** (1/2)
    if d_ij == int(d_ij):
      ans += 1
print(ans)

Solution (Python):
import math

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

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

print(ans)

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

dbl = []
for i in range(1,1000):
        dbl.append(i**2)

ans = 0
for idx,val in enumerate(X):
        for idx2, val2 in enumerate(X):
                if idx == idx2:
                        continue
                elif idx < idx2:
                        break
                tmp = 0
                for d in range(D):
                        tmp += abs(val[d] - val2[d]) ** 2
                if tmp in dbl:
                        ans += 1

print(ans)

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

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

Solution (Python):
import math

def get_distance(point_A, point_B) :
    s = 0
    for i in range(len(point_A)) :
        s += pow(abs(point_A[i] - point_B[i]),2)
    
    return math.sqrt(s)


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

count = 0
for i in range(N) :
    for k in range(i,N) :
        if (i == k) :
            continue
        
        d = get_distance(points[i], points[k])
        
        if (float.is_integer(d)) :
            count += 1
        
print(count)

Solution (Python):
N, D = map(int, input().split()) 
X = []
c = 0
for _ in range(N):
    Xi = list(map(int, input().split())) 
    for x in X:
        dis = 0
        for i in range(D):
            dis += (x[i] - Xi[i])**2
        for k in range(200):
            if dis == k**2:
                c += 1
    X.append(Xi)

print(c)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

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+1,N):
        dist = 0
        for I, J in zip(X[i], X[j]):
            dist += (I-J)**2
        dist = dist**0.5
        
        if dist.is_integer():
            cnt += 1

print(cnt)

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

answer = 0
for i in range(N):
  for j in range(i+1, N):
    dist = 0
    x_i = X[i]
    x_j = X[j]
    for d in range(D):
      dist += (x_i[d] - x_j[d])**2
    if (dist**0.5).is_integer():
      answer += 1

print(answer)

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

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

dis = []
ans = 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

        d = d ** (1/2)
        if (d == int(d)):
            ans += 1

print(ans)

Solution (Python):
def f(A, B):
    ret = 0
    for a, b in zip(A, B):
        ret += (a - b) ** 2
    return ret ** .5
def solve():
    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):
            t = f(X[i], X[j])
            if t - int(t) < 1e-5:
                ans += 1
    print(ans)
solve()

Solution (Python):
import sys
import math

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(N, D, inputs):
    points = list(map(lambda x: string_to_int(x), inputs))

    count = 0
    for i in range(0, len(points)-1):
        for j in range(i+1, len(points)):
            each_d_sum = 0

            for di in range(0, D):
                each_d_sum += (points[j][di] - points[i][di]) ** 2
            result = math.sqrt(each_d_sum)
            if result.is_integer():
                count += 1
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N, D] = string_to_int(input())

    ret = solve(N, D, inputs(N))
    print(ret)

Solution (Python):
import math
n,d=map(int,input().split())
xl=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        fx=xl[i]
        tx=xl[j]
        t=0
        for k in range(d): 
            t+=(fx[k]-tx[k])**2
        ts=math.sqrt(t)
        if ts==float(ts//1):
            ans+=1
print(ans)

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

for i in range(N-1):
    for q in range(i+1,N):
        res_doubled = 0
        for a,b in zip(pos[i],pos[q]):
            res_doubled += (a-b)**2
        res = math.sqrt(res_doubled)
        if res==int(res):
            ans += 1
print(ans)

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

ls =[]

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

def calc(a,b):
  num = 0
  for i in range(len(a)):
    num += (a[i]-b[i])**2
  if num**0.5 == int(num**0.5):
    return 1
  return 0

count = 0
for i in range(n-1):
  for j in range(i+1,n): 
    count += calc(ls[i],ls[j])
print(count)

Solution (Python):
N,D=(int(x) for x in input().split())
X=[[0]*D for _ in range(N)]
for n in range(N):
    A=list(map(int,input().split()))
    for d in range(D):
        X[n][d]=A[d]
def kyori(x,y,d):
    c=0
    for dd in range(d):
        c=c+(x[dd]-y[dd])**2
    return(c**(1/2))
ans=0
for i in range(N):
    for j in range(i+1,N):
        kyo=kyori(X[i],X[j],D)
        if kyo.is_integer()==True:
            ans=ans+1
print(ans)

Solution (Python):



import numpy as np

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

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

x = np.array(x)

ans = 0

for i in range(len(x)):
    for j in x[i+1:]:
        if np.sqrt(sum((x[i]-j)**2))%1 == 0:
            ans +=1
    

print(ans)

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

Solution (Python):
from math import ceil, sqrt
n,d=map(int,input().split())
pw=[]
for i in range(n):
    inp=tuple(map(int,input().split()))
    pw.append(inp)

ans=0
for i in range(n-1):
    for j in range(i+1, n):
        dis=sqrt(sum([(a-b)**2 for a,b in zip(pw[i],pw[j])]))
        if ceil(dis)==int(dis):
            ans+=1
print(ans)

Solution (Python):
import sys
from operator import itemgetter
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n, d = na()
pl = []
for i in range(n):
    pl.append(na())

ct = 0
for i in range(n):
    for j in range(i+1, n):
        l = 0
        if i != j:
            
            for k in range(d):
                l += ((pl[i][k] - pl[j][k]) ** 2)
                
            if math.sqrt(l).is_integer():
                ct += 1
print(ct)

Solution (Python):
import functools as ft
import heapq
import itertools as it
import logging
import unittest
from collections import (
    OrderedDict,
    defaultdict,
    namedtuple,
    Counter,
)

import numpy as np

_ = [ft, it, np, heapq, namedtuple, Counter, defaultdict, OrderedDict]

debug = logging.getLogger(__name__).debug


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


def _main():
    n, d = input_ints()
    x = [input_ints() for _ in range(n)]
    x = np.array(x)
    print(sum(
        d == np.round(d)
        for i in range(n)
        for j in range(i)
        for d in [np.sqrt(np.sum((x[i] - x[j]) ** 2))]
    ))


class Test(unittest.TestCase):
    def setUp(self):
        import run
        self._test = run

    def test_main(self):
        self._test.test_files(self, _main)


if __name__ == '__main__':
    _main()

Solution (Python):

import sys
from math import sqrt

def solve(N: int, D: int, X: "List[List[int]]"):
    
    ans = 0
    for i in range(N-1):
        l = [.0]*N
        for j in range(i+1,N):
            t = sum([(X[j][k]-X[i][k]) ** 2 for k in range(D)])
            l[j] = sqrt(t)

        for j in range(1,N):
            if(l[j] != 0 and l[j].is_integer()):
                ans += 1

    print(ans) 
    return



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 sys,heapq,math
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
def ddprint(x):
  if DBG:
    print(x)

n,d = inm()
x = []
for i in range(n):
    x.append(inl())
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        q = sum([(x[i][k]-x[j][k])**2 for k in range(d)])
        if (int(math.sqrt(q)))**2 == q:
            ans += 1
print(ans)

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

cnt = 0
zizyou = [x**2 for x in range(128)]

for i in range(len(xs)-1):
    for j in range(i+1,len(xs)):
        s = 0
        for d in range(D):
            s += (xs[i][d]-xs[j][d])**2
        
        if s in zizyou:

            cnt+=1

print(cnt)

Solution (Python):
import math


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


def square_distance(point1, point2):
    distance = 0
    for x, y in zip(point1, point2):
        distance = distance + (x - y) ** 2
    return distance


def int_distance(point1, point2):
    return round(math.sqrt(square_distance(point1, point2)))


if __name__ == "__main__":
    [n, d] = li()
    x_list = [li() for _ in range(n)]

    count = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            if square_distance(x_list[i], x_list[j]) == int_distance(x_list[i], x_list[j]) ** 2:
                count = count + 1
    print(count)

Solution (Python):
import sys
import math
input = sys.stdin.readline
N, D = map(int, input().split())
A = [0]*N
for i in range(N):
    A[i] = list(map(int, input().split()))

counter = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += abs(A[i][k] - A[j][k])**2
        dist = math.sqrt(dist)
        if dist.is_integer():
            counter += 1
print(counter)

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

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        cnt=0
        for k in range(D):
            cnt+=(L[i][k]-L[j][k])**2
        if pow(cnt,0.5)==int(pow(cnt,0.5)):
            ans+=1
print(ans)

Solution (Python):
import math


def ok(y: list, z: list, D: int)->bool:
    d = 0
    for i in range(D):
        d += (y[i]-z[i]) ** 2

    s = int(math.sqrt(d))

    return s * s == d


def good_distance(N: int, D: int, X: list)->int:
    count = 0

    for i in range(N):
        y = X[i]
        for j in range(i+1, N):
            z = X[j]

            count += ok(y, z, D)

    return count


if __name__ == "__main__":
    N, D = map(int, input().split())
    X = [[int(s) for s in input().split()] for _ in range(N)]
    ans = good_distance(N, D, X)

    print(ans)