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

Solution (Python):
import numpy as np

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

for i in range(N-1):
    x = (X[i] - X[i+1:]) ** 2
    total = np.sum(x, axis=1) ** 0.5

    for t in total:
        if t.is_integer():
            ans += 1
print(ans)

Solution (Python):
import math

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

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

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
        n = math.sqrt(d)
        if is_integer_num(n):
            ans += 1

print(ans)

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

def main():
    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(i+1, n):
            tmp = 0
            for k in range(d):
                tmp += (x[i][k] - x[j][k])** 2
            if (tmp ** 0.5).is_integer():
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        dist = dist**(1/2)
        if dist.is_integer():
            ans += 1

print(ans)

Solution (Python):
import numpy as np

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

xs = []

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

xs = np.array(xs)

count = 0

for i, xi in enumerate(xs):
    for j in range(i+1, N):
        
        
        xj = xs[j]
        tmp = xi - xj
        tmp2 = tmp ** 2
        d = np.sqrt(np.sum(tmp2))
        if d - int(d) == 0:
            count += 1

print(count)

Solution (Python):
from math import sqrt
N, D = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for s1 in S:
    for s2 in S:
        c = 0
        for x1, x2 in zip(s1, s2):
            c += (x1-x2)**2
        if int(sqrt(c))**2 == c:
            ans += 1
print((ans-N)//2)

Solution (Python):
import math


def is_distance_int(D, y, z):
    sum_diff_squre = 0
    for i in range(D):
        sum_diff_squre += (y[i] - z[i]) * (y[i] - z[i])
    distance = int(math.sqrt(sum_diff_squre))

    if distance * distance == sum_diff_squre:
        return True
    else:
        return False


if __name__ == '__main__':
    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(0, i):
            
            if is_distance_int(D, X[i], X[j]):
                answer += 1

    print(answer)

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

ans = 0
for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        dis = 0
        for k in range(d):
            dis += (x[i][k]-x[j][k])**2
        dis_r = int(dis**0.5)
        if dis == dis_r**2:
            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 in range(N-1):
    for j in range(i+1, N):
        dist = 0
        for d in range(D):
            dist += abs(X[i][d]-X[j][d])**2
        if dist ** 0.5 == int(dist ** 0.5):
            ans += 1
print(ans)

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

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for j in range(N):
    for i in range(j):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d]) ** 2
        if math.sqrt(dist) % 1 == 0:
            cnt += 1
print(cnt)

Solution (Python):
import math
N, D = map(int, input().split())
X = [[int(_) for _ in input().split()] for _ in range(N)]
ans = 0
for i in range(N - 1):
    x1 = X[i]
    for j in range(i + 1, N):
        x2 = X[j]
        work = 0
        for x, y in zip(x1, x2):
            work += (x - y) ** 2

        
        if math.sqrt(work).is_integer():
            ans += 1

print(ans)

Solution (Python):
from sys import stdin


def main():
    N, D = [int(x) for x in stdin.readline().rstrip().split()]
    Xs = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
    count = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            sum_ = sum([(a - b) ** 2 for a, b in zip(Xs[i], Xs[j])])
            ans = sum_ ** (1 / 2)
            if int(ans) == ans:
                count += 1
    print(count)


if __name__ == "__main__":
    main()

Solution (Python):
from math import sqrt

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

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

count = 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
        droot = sqrt(float(dist))
        if droot.is_integer():
            count += 1

print(count)

Solution (Python):
import itertools
import math

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

def calc_dist(Y, Z):
    return math.sqrt(sum((y - z) ** 2 for y, z in zip(Y, Z)))

print sum([calc_dist(Y, Z).is_integer() for Y, Z in itertools.combinations(X, 2)])

Solution (Python):
def main():
    n,d = map(int,input().split(' '))
    x=[]
    for i in range(n):
        x.append(list(map(int,input().split(' '))))
    res = 0
    dis = 0
    for i in range(n):
        for j in range(i,n):
            if i !=j:
                for k in range(d):
                    dis += (x[i][k]-x[j][k])**2
                if dis**0.5%1 ==0:
                    res += 1
                dis = 0
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
import math

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

ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue

        x_i = X[i]
        x_j = X[j]

        cache = float(0)
        for d in range(D):
            cache += (x_i[d] - x_j[d]) ** 2

        cache = math.sqrt(cache)

        if cache.is_integer():
            ans += 1

print(ans)

Solution (Python):
import numpy as np

N, D = [int(x) for x in input().split()]

X = np.zeros((N, D))
for i in range(N):
	t = [int(x) for x in input().split()]
	X[i,:] = np.array(t)

counter = 0
for i in range(N-1):
	for j in range(i+1, N):
		if np.sqrt(np.sum((X[i,:]-X[j,:])**2))%1 == 0:
			counter += 1
print(counter)

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())


N, D = mi()

Xs = [list(mi()) for _ in range(N)]

nijouset = {x*x for x in range(200)}

ans = 0
for i in range(N):
  j = i + 1
  while (j < N):
    tmpsum = 0
    for a, b in zip(Xs[i], Xs[j]):
      tmpsum += (a-b) * (a-b)
    if tmpsum in nijouset:
      ans += 1
    j += 1

print(ans)

Solution (Python):
import math
def isInteger(p1, p2):
    s = sum([(p1[i] - p2[i]) ** 2 for i in range(len(p1))])
    num = math.sqrt(s)
    return num - int(num) == 0
N, D = map(int, input().split())

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if isInteger(points[i], points[j]): cnt += 1
print(cnt)

Solution (Python):



import sys  
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools



sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe


def local_input():
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)


def solve():
    n,d = map(int,input().split())
    lst = [0]*n
    for i in range(n):
        lst[i] = list(map(int,input().split()))
    ans = 0
    for i in range(n-1):
        for j in range(i+1,n):
            sum = 0
            for k in range(d):
                sum += (lst[j][k]-lst[i][k])**2
            if round(math.sqrt(sum))**2 == sum:
                ans +=1
    print(ans) 
    return 0

if __name__ == "__main__":
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

Solution (Python):
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
cn = 0
for i in range(n):
    for k in range(i+1,n):
        a = 0
        for j in range(d):
            a += (x[i][j] - x[k][j])**2
        b = a**0.5
        c = round(b)
        if -0.0001 < b-c < 0.0001:
            cn += 1
print(cn)

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

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

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

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if dist(l[i],l[j])%1 == 0:
            ans += 1
            

print(ans)

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

X = []

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


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

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

def dist(x,y):
    res = 0
    for i,j in zip(x,y):
        res += (i - j)**2
    if int(math.sqrt(res)) == math.sqrt(res):
        return 1
    else:
        return 0

ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += dist(l[i],l[j])

print(ans)

Solution (Python):
import math

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

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

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        v = 0
        for d in range(D):
            v += abs(point[i][d] - point[j][d]) ** 2
        v = math.sqrt(v)
        if v.is_integer():
            ans += 1

print(ans)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

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

import itertools
import math

ans = 0

nums = range(n)
for a,b in itertools.combinations(nums, 2):
    c = 0
    for j in range(d):
        c += (xx[a][j]-xx[b][j])**2
    ans = ans+1 if round(math.sqrt(c))**2 == c else ans

print(ans)

Solution (Python):
N,D = map(int,input().split())
cood_list = [[int(i) for i in input().split()] for i in range(N)]
ans=0
dis_sum=0
for i in range(N):
    for j in range(i+1,N):
        for l in range(D):
            dis_sum += (cood_list[i][l]-cood_list[j][l])**2
        dis_sum = float(dis_sum)
        if dis_sum**(1/2)%1 == 0:
            ans +=1
        dis_sum=0
print(ans)

Solution (Python):
import math
N, D = (int(_) for _ 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 :
            comb = [(x - y) * (x - y) for (x, y) in zip(x[i], x[j])]
            d = int(math.sqrt(sum(comb)))
            if d * d == sum(comb):
                cnt +=1

print(cnt)

Solution (Python):
import math

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

X = []

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

count = 0
count2 = 0
for i in range(N):
    for j in range(N):
        buff = 0
        flag = False
        for d in range(D):
            if i != j:
                count2 += 1
                flag = True
                buff += abs(X[i][d]-X[j][d])**2
        if math.sqrt(buff) % 1 == 0 and flag:
            
            count += 1



print(count//2)

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

cnt = 0
for i in range(N-1):
  for j in range(i+1,N):
    if sum([int((X[i][d]-X[j][d])**2) for d in range(D)]) in heihousu:
      cnt+=1
print(cnt)

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

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        d2 = sum((y - z) ** 2 for y, z in zip(x[i], x[j]))
        if d2 ** 0.5 % 1 == 0:
            ans += 1
print(ans)

Solution (Python):
import numpy

N, D = map(int, input().split())
points = []
for i in range(N):
	temp = numpy.array([int(x) for x in input().split()])
	points.append(temp)

count = 0
for i in range(N-1):
	for j in range(1, N):
		d = numpy.sqrt(numpy.sum((points[i] - points[j])**2))
		if(d.is_integer() and i<j):
			count+=1

print(count)

Solution (Python):
import math
N, D = 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):
        sum = 0
        for k in range(D):
            sum = sum + (X[i][k]-X[j][k])*(X[i][k]-X[j][k])
        dist = math.sqrt(sum)
        if dist.is_integer():
            ans=ans+1
print(ans)

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 = []
for i in range(n):
    x.append(list(map(int, input().split())))
a = 0
for i in range(n):
    for k in range(i+1, n):
        tmp = 0
        for x1, x2 in zip(x[i], x[k]):
            tmp += (x1 - x2) ** 2
        a += is_integer_num(math.sqrt(tmp))

print(a)

Solution (Python):
import numpy as np

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

ps = []
for i in range(n):
    p = np.array(list(map(int, input().split())))
    ps.append(p)

count = 0
for i, pi in enumerate(ps):
    for pj in ps[i+1:]:
        d = np.sum((pi-pj)**2)
        sq = np.sqrt(d)
        if sq%1 < 1e-6:
            count += 1
print(count)

Solution (Python):
from itertools import combinations
def dist2(a, b):
    return sum([(i - j)**2 for i, j in zip(a, b)])


def check(num):
    return sum([True if i**2 == num else False for i in range(1, 202)]) > 0


n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
print(sum([check(dist2(i, j)) for i, j in combinations(x, 2)]))

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




num_l = list(itertools.combinations(num, 2))

for num in num_l:
        
        left = num[0]
        right = num[1]
        wa = 0
        for i in range(D):
                wa += (X[left][i] - X[right][i]) ** 2
        dist = math.sqrt(wa)
        if dist-int(dist) == 0:
                ans += 1

print(ans)

Solution (Python):
import sys
from fractions import gcd
from collections import Counter
from itertools import combinations
from math import sqrt
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def calc(a, b):
    return sqrt(sum([(i -j)*(i-j) for i, j in zip(a,b)]))

def main():
    n, d = LI()
    xs = []
    ds = []
    ans = 0
    for i in range(n):
        xs.append(LI())
    for a, b in combinations(range(n), 2):
        ds.append(calc(xs[a], xs[b]))
    for i in ds:
        if i == i // 1:
            ans += 1
    print(ans)







if __name__ == "__main__":
    main()

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

ans_sum = 0
for i in range(N):
    for j in range(N):
        temp = 0
        for d in range(D):
            temp += (abs(X[i][d] - X[j][d]))**2
        ans = temp**(1/2)
        if ans.is_integer():
            ans_sum += 1

print((ans_sum - N)//2)

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

Solution (Python):
import numpy as np


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7  
N = 10 ** 4
g1 = [1, 1]  
g2 = [1, 1]  
inverse = [0, 1]  

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


def dist(x, y):
    ans = 0
    for i in range(len(x)):
        ans += (x[i] - y[i]) * (x[i] - y[i])
    return np.sqrt(ans)


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(i + 1, n):
        d = dist(arr[i], arr[j])
        if abs(d - int(d)) < 0.00001:
            ans += 1

print(ans)

Solution (Python):
import numpy as np
import math

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

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

for i in range(n):
    hoge = np.array([int(x) for x in input().split()])
    points[i, :] = hoge

total = 0


for i in range(n):
    for j in range(i+1, n):
        foo = (points[i, :] - points[j, :]) ** 2
        foo_sum = foo.sum()
        if int(foo_sum) == int(math.sqrt(foo_sum)) ** 2:
            total += 1

print(total)

Solution (Python):

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


count = 0

for i in range(n-1):
    for j in range(i+1,n):
        ans = np.sqrt(np.sum(np.square(X[i]-X[j])))
        
        
        
        if ans.is_integer():
            count += 1
print(count)

Solution (Python):
import numpy as np

N,D = map(int, input().split())
A = np.zeros((N,D))

for i in range(N):
    A[i] = np.array(input().split(), dtype=np.int64)
    
ans = 0
    
for i in range(N):
    for j in range(N):
        B = A[i]
        C = A[j]
        k = np.linalg.norm(C - B, ord=2)
        if k.is_integer() == True:
            ans += 1
            
ans = ans - N
ans = int(ans / 2)
print(ans)

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

ans = 0

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

print(ans)

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):
        tmp = 0
        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())
XList = list()

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

answer = 0

for i, x1 in enumerate(XList):
    for j, x2 in enumerate(XList):
        if i >= j:
            continue
        sumple = 0
        for d in range(D):
            sumple += (x1[d] - x2[d]) ** 2
        if abs((sumple ** 0.5 )- (sumple ** 0.5)//1) < 10**(-7):
            answer += 1

print(answer)

Solution (Python):
import math
[N,D] = list(map(int,input().split()))
X = []
for i in range(N):
    tmp = list(map(int,input().split()))
    X.append(tmp)
ans = 0
for i in range(N):
    for j in range(i,N):
        c = 0
        for k in range(D):
            c += (X[i][k] - X[j][k])**2
        if (int(c**(0.5)))**2 == c:
            ans+= 1
print(ans-N)

Solution (Python):
import numpy as np
import numpy.linalg as la
import math


def BC133_B():
    n, d = map(int, input().split())
    l = []
    for i in range(n):
        l.append(np.array(list(map(int, input().split()))))
    a = 0
    for i in range(n):
        for j in range(i):
            d = la.norm(l[i] - l[j])
            if int(d + 0.5)**2 == d**2: a += 1
    print(a)


BC133_B()

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

def dis(xa, xb):
  dis_ = 0
  for a, b in zip(xa, xb):
    dis_ += (a - b) ** 2
  dis_ = dis_ ** 0.5
  return dis_

cnt = 0
for i in range(n):
  for j in range(i+1, n):
    d = dis(x[i], x[j])
    if d % 1.0 == 0:
      cnt += 1
print(cnt)

Solution (Python):
import numpy as np
[n,d] = [int(i) for i in input().split()]
points = []
for i in range(n):
	coordinates = [int(i) for i in input().split()]
	points.append(coordinates)

def distance(a,b):
	total = 0
	for i in range(len(a)):
		total += (a[i] - b[i])**2	
	return np.sqrt(total)

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

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

for i in range(n):
    for j in range(n):
        distance=0
        for k in range(d):
            distance=distance+(x[i][k]-x[j][k])**2
        root_distance=int(distance**(1/2))
        if abs(distance-root_distance*root_distance)<10**(-6):
            ans=ans+1
print((ans-n)//2)

Solution (Python):
n,d=map(int,input().split())
x=[]
for i in range(n):
	p=list(map(int,input().split()))
	x.append(p)
heihoukon=[]
for i in range(200):
	heihoukon.append(i**2)
ans=0
for a in range(n):
	for b in range(n):
		cnt=0
		for c in range(d):
			cnt+=(x[a-1][c]-x[b-1][c])**2
		if cnt in heihoukon and a!=b:
			ans+=1
print(ans//2)

Solution (Python):
N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append([int(x) for x in input().split()])
count = 0
for i in range(N-1):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += (X[i][k] - X[j][k])**2
        if float.is_integer(dist ** (1/2)):
            count += 1
print(count)

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

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

import math
def calc_distance(arr1, arr2):
    total = 0
    for x, y in zip(arr1, arr2):
        total += (x - y) ** 2
    return math.sqrt(total)

ans = 0
for i in range(len(point_list)):
    for j in range(i + 1, len(point_list)):
        ans += calc_distance(point_list[i], point_list[j]).is_integer()
        
print(ans)

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

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

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        tmp = 0
        for x, y in zip(coord[i], coord[j]):
            tmp += (x - y) ** 2
        if (tmp ** 0.5).is_integer():
            ans += 1
print(ans)

Solution (Python):
from collections import defaultdict

def main():
    num, d = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]
    ans = 0
    for i in range(num):
        for j in range(i + 1, num):
            a = data[i]
            b = data[j]
            kari = 0
            for k in range(d):
                kari += (a[k] - b[k]) ** 2
            kari_s = int(kari ** 0.5)
            if kari == kari_s ** 2:
                ans += 1
    print(ans)






if __name__ == '__main__':
    main()

Solution (Python):
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  
  sys.stderr.write(_s+"\n")

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

A=[]

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


def calc(X,Y):
	a = 0
	for k in range(D):
		a += (X[k]-Y[k])**2
	
	a = a**(1/2)
	return (a == int(a))
	

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

print(ans)

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

def calcdistance(point1,point2):
    total = 0
    for i in range(len(point1)):
        total += (point1[i]-point2[i])**2
    return total**(0.5)
    
points = []
for i 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
        else:
            distance = calcdistance(points[i],points[j])
            if distance.is_integer():
                ans += 1
print(ans)

Solution (Python):
n,d=map(int,input().split())
data = []
ans = 0
for i in range(n):
    lista=[int(l) for l in input().split()]
    data.append(lista)
    for j in range(i):
        dist = 0
        for _ in range(d):
            dist += (data[i][_]-data[j][_])**2
        dist = dist**(1/2)
        if dist == int(dist):
            ans+=1
print(ans)

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

ok = {}
for i in range(401):
    ok[i**2] = True

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

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

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

def isSqrt(n):
    m = 0
    while m * m <= n:
        if m * m == n:
            return True
        m += 1
    return False

ret = 0
for p1 in range(n - 1):
    for p2 in range(p1 + 1, n):
        dist = 0
        for i in range(dimen):
            dist += abs(a[p1][i] - a[p2][i]) ** 2
        if isSqrt(dist):
            ret += 1
print(ret)

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

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

ans = 0

for i in range(N):
  for j in range(i+1, N):
    dst = 0
    for d in range(D):
      dst += (x[i][d] - x[j][d])**2
    dst = dst ** 0.5
    if int(dst) == dst:
      ans += 1

print(ans)

Solution (Python):
from itertools import combinations
import math

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

seq = combinations(xs, 2)
count = 0
for xs in seq:
    sum = 0
    for a, b in zip(xs[0], xs[1]):
        sum += abs(a - b)**2

    sum2 = int(math.sqrt(sum))**2
    if sum == sum2:
        count += 1

print(count)

Solution (Python):
def main():
    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):
            v = 0
            for a, b in zip(X[i], X[j]):
                v += abs((a - b) ** 2)
            if int(v ** 0.5) == v ** 0.5:
                ans += 1
    print(ans)


main()

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

l = []

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

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

print(ans)