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

def LI():
  return [int(s) for s in input().split()]

def distance(x,y):
  total = 0
  for x_i,y_i in zip(x,y):
    total+=(x_i - y_i)**2    
  return math.sqrt(total)

X = []

N,D = LI()

for i in range(N):
  X.append(LI())
  
count = 0

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

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

ans = 0
for i in range(n):
  for j in range(i):
    d2 = 0
    for k in range(d):
      d2 += (ll[i][k] - ll[j][k])**2
    d1 = d2 ** 0.5
    if d1 == round(d1):
      ans += 1

print(ans)

Solution (Python):
import itertools
import math

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

cVec = list(itertools.combinations(vecList,2))
count = 0

for i in cVec:
  sqT = 0
  for j in range(d):
    sqT += (i[0][j]-i[1][j])**2
  sqT = math.sqrt(sqT)
  if sqT.is_integer():
    count += 1

print(count)

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

Solution (Python):
import math

def dist(x,y,d):
    ret = 0.0
    for i in range(d):
        ret += pow(x[i] - y[i], 2)
    return pow(ret, 0.5)

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

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

    ans = 0

    for i in range(n):
        for j in range(i+1,n):
            distance = dist(num_list[i],num_list[j],d)
            if math.ceil(distance) == math.floor(distance):
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

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-1):
    for j in range(i+1,N):
        dist =0
        ist = [x[i][k] - x[j][k] for k in range(D)]
        for n in ist:
            dist += n ** 2
        if math.sqrt(dist) == int(math.sqrt(dist)):
            cnt +=1
print(cnt)

Solution (Python):
import math

def GoodDist():
    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 - 1):
        for j in range(i + 1, N):
            dist = 0
            lst = [X[i][k] - X[j][k] for k in range(D)]
            for n in lst:
                dist += n ** 2
            if math.sqrt(dist) == int(math.sqrt(dist)):
                cnt += 1
    print(cnt)

GoodDist()

Solution (Python):
import numpy as np
N,D=map(int,input().split())
X=[]
for i in range(N):
  X.append(list(map(int,input().split())))
cnt=0
for k in range(N-1):
  for j in range(k+1,N):
    sum=0
    ans=0
    for l in range(D):
      sum+=(X[k][l]-X[j][l])**2
    ans=np.sqrt(sum)
    if ans.is_integer():
      cnt+=1
print(cnt)

Solution (Python):
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

















































def main():
    n, d = map(int, input().strip().split())
    ll = [[] for i in range(n)]
    for i in range(n):
        ll[i] = list(map(int, input().strip().split()))
    cnt = 0
    for i in range(n):
        for j in range(i+1, n):
            dist = 0
            for k in range(0, d):
                dist += (ll[i][k] - ll[j][k])**2
            
            dist_sqr = dist**(1/2)
            if dist_sqr.is_integer() is True:
                
                
                cnt += 1
    print(cnt)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
n,d=map(int,input().split())
xlis=[list(map(int,input().split())) for i in range(n)]
def dis(x,y):
	dlis=[]
	for i in range(d):
		t=(xlis[x][i]-xlis[y][i])**2
		dlis.append(t)
	return (sum(dlis))**(1/2)
counter=0
for i in range(n):
	for j in range(n):
		if i<j and int(dis(i,j))==dis(i,j):
			counter+=1
print(counter)

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(len(x)):
    for j in range(len(x)):
        ans_ = 0
        if i >= j:
            continue
        for k in range(D):
            ans_ += (x[i][k] - x[j][k])**2
        if math.sqrt(ans_).is_integer():
            ans += 1
print(ans)

Solution (Python):
def main():
    import numpy as np 
    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(i+1,N):
            tmp = 0
            for h in range(D):
                tmp += (X[i][h]-X[j][h])**2
            dist = np.sqrt(tmp)
            if dist%1 == 0:
                ans += 1
    
    print(ans)


if __name__=="__main__":
    main()

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

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

print(ans)

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

count = 0
for i in range(n):
   for j in range(i+1, n):
      d = (sum([(y-z)**2 for y, z in zip(x[i], x[j])]))**0.5
      if (d.is_integer()):
         count += 1

print(count)

Solution (Python):
from itertools import combinations

N, D = map(int, input().split())
X = []
for _ in range(N):
  x = [int(i) for i in input().split()]
  X.append(x)
  
count = 0
for i, j in combinations(X, 2):
  dist = sum([(i_ - j_)**2 for i_, j_ in zip(i, j)])**0.5
  if dist.is_integer():
    count += 1

print(count)

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

dis = 0
count = 0
for i in range(n-1):
  for j in range(i+1, n):
    val = [x-y for (x, y) in zip(x[i], x[j])]
    dis = math.sqrt(sum(map(lambda x:x**2, val)))
    if dis%1==0:
      count += 1
      
print(count)

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

def nasu(x, y):
  t = 0
  for i in range(D):
    t += (X[x][i] - X[y][i]) ** 2
  t **= (1 / 2)
  if t == int(t):
    return 1
  else:
    return 0


ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    ans += nasu(i, j)

print(ans)

Solution (Python):

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

def isInt(a, b):
  sum=0;
  for i in range(d):
    sum+=(a[i]-b[i])**2

  tmp=sum**(0.5) 
  if tmp==np.floor(tmp):
    return True
  else: False

cnt=0
for i in range(n):
  for j in range(i+1, n):
    if isInt(pos[i],pos[j]):
      cnt+=1
print(cnt)

Solution (Python):

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

def dist(a, b):
  sum=0;
  for i in range(d):
    sum+=(a[i]-b[i])**2
  return np.sqrt(sum) 

def isInt(d):
  if d-np.floor(d) == 0:
    return True
  else:
    return False

cnt=0
for i in range(n):
  for j in range(i+1, n):
    distance = dist(pos[i], pos[j])
    if isInt(distance):
      cnt+=1

print(cnt)

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

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

ans=0
for i in range(n):
  for j in range(i + 1, n):
    temp = 0
    for xi,xj in zip(pos[i], pos[j]):
      temp+=(xi-xj)**2
    if int(math.sqrt(temp)) ** 2 == temp:
      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(N):
    for j in range(i + 1, N):
        dist = math.sqrt(sum([(x - y) ** 2 for x, y in zip(X[i], X[j])]))
        if dist.is_integer():
            ans += 1

print(ans)

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

if __name__ == '__main__':
    main()

Solution (Python):
import math

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

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

Solution (Python):
import sys

input = sys.stdin.readline


class Solution:
    def main(self):
        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):
                d = 0
                for k in range(D):
                    d += (X[i][k] - X[j][k]) ** 2
                if (d ** 0.5).is_integer():
                    ans += 1

        print(ans)



if __name__ == '__main__':
    Solution().main()

Solution (Python):
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, D = map(int, readline().split())
X = [np.array(readline().split(), dtype=np.int64) for _ in range(N)]
ans = 0

for u, v in itertools.combinations(X, 2):
    d = ((u - v) * (u - v)).sum()
    dd = int(d ** .5)
    if d == dd * dd:
        ans += 1

print(ans)

Solution (Python):
import math

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

x=[]

for i in range(n):
    x.append([int(x) for x in input().split()])
    
count=0
buf=0

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

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

Solution (Python):
N, D = map(int, input().split())
XList = [i for _ in range(N) for i in map(int, input().split())]
couInt = 0
for i in range(N):
  for j in range(N):
    if i >= j:
      continue
    else:
      dist = 0.0
      for k in range(D):
        dist += (XList[i*D+k]-XList[j*D+k])**2
      if dist**0.5%1==0:
        couInt += 1
print(couInt)

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

rs = 0
for i in range(n):
    for ii in range(i+1, n):
        dis = 0
        for j in range(d):
            dis += (X[i][j]-X[ii][j])**2
        if dis**0.5 %1 == 0:
            rs += 1

print(rs)

Solution (Python):
N,D = [int(i) for i in input().split()]
lagd = []
for i in range(N):
    lagd.append([int(i) for i in input().split()])
lngs = D - 1
def kyoricac(daone,datwo,d):
    keka = []
    n = 0
    wa = 0
    while n <= d:
        wa = (daone[n] - datwo[n])**2
        keka += [wa]
        n += 1
    wa = sum(keka)
    kaesi = float(wa ** (1/2))
    return kaesi
ans = 0
fst = 1
for i in range(N):
    for n in range(fst,N):
        flag = float(kyoricac(lagd[i],lagd[n],lngs))
        if flag.is_integer() == True:
            ans += 1
    fst += 1
print(ans)

Solution (Python):
import itertools
import math

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

for i in range(N):
    x[i]=list(map(int,input().split()))
        
def calc_dd(a,b):
    dd=0
    for i in range(D):
        dd+=(x[a][i]-x[b][i])**2
    return dd

def judge(dd):
    rdd=int(math.sqrt(dd))
    if rdd*rdd==dd:
        return True
    return False

    
        
ans=0        
for c in itertools.combinations(range(N),2):
    if judge(calc_dd(c[0],c[1])):
        ans+=1
print(ans)

Solution (Python):
import math

N, D = [int(i) for i in input().split()]
X = []
for i in range(N):
    X.append([int(i) for i in input().split()])
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        distance = 0
        for d in range(D):
            distance += (X[i][d] - X[j][d]) ** 2
        if math.sqrt(distance).is_integer():
            ans += 1
print(ans)

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

X = []
for i in range(N):
  X.append(list(map(int,input().split())))
  
select = list(itertools.combinations(X,2))
ans = 0


for i ,j in select:
  i = np.array(i)
  j = np.array(j)
  u = i - j
  dist = np.linalg.norm(u)
  

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

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

Solution (Python):
def main():
    N, D = map(int, input().split(" "))
    X = []
    result = 0
    for n in range(N):
        X.append(list(map(int, input().split(" "))))
    for i in range(N):
        for j in range(i + 1, N):
            dist = 0
            for d in range(D):
                dist += (X[i][d] - X[j][d]) ** 2
            if float.is_integer(dist ** 0.5):
                result += 1
    print(result)


if __name__ == '__main__':
    main()

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

result=[]
result_hikaku=[]
for j in range(n-1):
    for k in range(j+1,n):
        cnt=0
        for l in range(d):
            cnt +=(int(x[j][l])-int(x[k][l]))**2
        result.append((cnt)**(1/2))
        result_hikaku.append(round((cnt)**(1/2)))

count=0
for m in range(len(result)):
    if result[m]==result_hikaku[m]:
        count+=1
print(count)

Solution (Python):
import sys
import math
import numpy as np
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, d = na()
x = [[] for _ in range(n)]
for i in range(n):
    x[i] = na()
x = np.array(x)
c = 0
for i in range(n):
    for j in range(i+1, n):
        s = (np.sum((x[i] - x[j])**2))**0.5
        if s.is_integer():
            c += 1
print(c)

Solution (Python):
import math
N, D = map(int, input().split())
X = [[int(x) for x in input().split()] for i in range(N)]
count = 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)
        if math.sqrt(sum)%1==0:
            count += 1
print(count)

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

import itertools
import math

count = 0
for u, v in itertools.combinations(X, 2):
  d = 0
  for i in range(D):
    d += abs(u[i] - v[i]) ** 2
  dd = round(math.sqrt(d))
  if d == dd ** 2:
    count += 1

print(count)

Solution (Python):
n,d=map(int,input().split())
l=[i**2 for i in range(130)]
set_l=set(l)
cnt=0
X=[list(map(int,input().split())) for i in range(n)]
from itertools import combinations
comb=list(combinations(range(0,n),2))
for pair in comb:
    v=0
    for j in range(d):
        v+=(X[pair[0]][j] - X[pair[1]][j])**2
    if v in set_l:
        cnt+=1
print(cnt)

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-1):
    for j in range(i+1,n):
        s = 0
        for k in range(d):
            s += (x[i][k] - x[j][k])**2
        if math.sqrt(s) % 1 == 0:
            cnt += 1
print(cnt)

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):
        s = 0
        for k in range(d):
            s += (x[i][k] - x[j][k])**2
        if math.sqrt(s) % 1 == 0:
            cnt += 1
print(cnt)

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


def calc_distance(p_a, p_b):
    i = 0
    for a, b in zip(p_a, p_b):
        i += (a - b) ** 2
    return math.sqrt(i)


ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if calc_distance(points[i], points[j]).is_integer():
            ans += 1
print(ans)

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

    if float.is_integer(math.sqrt(ans)) == True:
      count += 1
print(count)

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

Solution (Python):
N, D = map(int,input().split())
dots = []
for i in range(N):
    dots.append(list(map(int,input().split())))
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        tmp = 0
        for k in range(D):
            tmp+=(dots[i][k]-dots[j][k])**2
        if (tmp**0.5).is_integer():
            cnt+=1

print(cnt)

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

Solution (Python):
import math
N, D = list(map(int, input().split()))
X = [None] * N
pair = 0

def count(l,r):
    s = 0
    for i in range(D):
        s += abs(l[i]-r[i])**2
    return math.sqrt(s)


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

for i in range(N-1):
    for j in range(i+1,N):
        
        if count(X[i], X[j]).is_integer():
            pair += 1

print(pair)

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

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

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

print(count)

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):
        s = 0
        for k in range(d):
            s += (x[i][k] - x[j][k])**2
        if math.sqrt(s) % 1 == 0:
            cnt += 1
print(cnt)

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

ans=0
s=0
for i in range(N):
  for j in range(i+1,N):
    s=0
    for d in range(D):
      s+=(l[i][d]-l[j][d])**2
    if s**(1/2)%1==0:
      ans+=1
print(ans)

Solution (Python):
import math
n,d = map(int,input().split())
list_x = [[int(i) for i in input().split()] for _ in range(n)]
count = 0
for i in range(n):
    for j in range(i+1,n):
        sum_ = 0
        for k in range(d):
            sum_ += (list_x[i][k] - list_x[j][k])**2
        if math.sqrt(sum_) ==(math.sqrt(sum_))//1:
            count += 1
print(count)

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

def check(x, y):
    s = 0
    for a, b in zip(x, y): s += (a - b) ** 2

    for i in range(0, s+1):
        if i * i == s: return 1
    return 0


ans = 0
for i in range(N):
    for j in range(i+1, N): ans += check(A[i], A[j])
print(ans)

Solution (Python):
import numpy as np
N,D = map(int, input().split())
X_matrix = [list(map(int, input().split())) for _ in range(N)]
count=0
for i in range(N):
  for k in range(i+1,N):
      if np.sqrt(sum((np.array(X_matrix[i])-np.array(X_matrix[k]))**2)).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)]

ans = 0

for i in range(N):
    for j in range(i):
        d = 0
        for k in range(D):
            d += (X[i][k]-X[j][k])**2
        dsqrt = d**0.5
        if dsqrt == dsqrt//1:
            ans += 1 
print(ans)

Solution (Python):
import math

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

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

print(ans)

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

def dist(r1, r2):
    ans = 0
    for i in range(len(r1)):
        ans += (r1[i] - r2[i])**2
    return ans**(1/2)

ans = 0
for i in range(n):
    for j in range(i):
        if dist(x[i], x[j])%1 == 0:
            ans += 1
        else:
            continue

print(ans)

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

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

for j in range(n):
    for k in range(n):
        a=0
        if j!=k:
            for l in range(d):
                a+=(x[j][l]-x[k][l])**2
            if sqrt(a).is_integer()==True:
                ans+=1
print(ans//2)

Solution (Python):
import itertools
import numpy as np

n, d = [int(_) for _ in input().split()]
a = np.array([[int(_) for _ in input().split()] for _ in range(n)])

L = list(itertools.combinations(a, 2))
cnt = 0
for u, v in L:
    dist = np.sqrt(sum((u-v)**2))
    if dist%1==0:
        cnt +=1
print(cnt)

Solution (Python):



import numpy as np
from itertools import combinations


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

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


def calc_distance(y,z):
    return np.sqrt(np.sum((y - z)**2))

res = 0

for y, z in combinations(X, r = 2):
    distance = calc_distance(y, z)
    if distance - int(distance) == 0:
        res += 1


print(res)

Solution (Python):
from itertools import combinations
sq = [i**2 for i in range(500)]
ans = 0
n,d = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
for (i,j) in combinations(a,2):
  dist2 = 0
  for x in range(d):
    dist2 += (i[x]-j[x])**2
  if dist2 in sq:
    ans += 1
print(ans)

Solution (Python):
import math


def n_sum(n):
    return n * (n - 1) // 2

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

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

if __name__ == '__main__':
    print(main())

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):
        norm = 0
        for k in range(d):
            diff = abs(x[i][k] - x[j][k])
            norm += diff * diff
    
        flag = False
        for k in range(norm+1):
            if k * k == norm:
                flag = True
        if flag:
            ans += 1

print(ans)

Solution (Python):
cnt = 0
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):
		num = 0
		for k in range(D):
			num += (x[i][k] - x[j][k])**2
		num = num**0.5
		if num.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)]

ans = 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
        t = t**(1/2)
        if t.is_integer():
            ans += 1
print(ans)

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

def ok(x,y):

    z = 0
    for i in range(d):
        z += (x[i]-y[i])**2
    if z**(0.5) == int(z**(0.5)):
        return True
    else:
        return False

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if ok(data[i],data[j]):
            ans += 1

print(ans)

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

print(count)

Solution (Python):
N, D = map(int, input().strip().split())
X = [[int(n) for n in input().strip().split()] for _ in range(N)]
c = 0
for i in range(N):
    for j in range(i+1, N):
        n = 0
        for k in range(D):
            x = abs(X[i][k] - X[j][k])
            n += x * x 
        b = False
        for k in range(n+1):
            if k * k == n:
                b = True
        if b:
            c += 1
print(c)

Solution (Python):
import math
nd = list(map(int,input().split()))
n = nd[0]
d = nd[1]
x_dic = {}
for i in range(n):
    temp = list(map(int,input().split()))
    x_dic[i] = temp

def calc(list_1, list_2, d):
    dist_sq = 0
    for i in range(d):
        dist_sq += (list_1[i]-list_2[i])*(list_1[i]-list_2[i])
    dist = math.sqrt(dist_sq)
    return dist

ans = 0
for i in range(n):
    for j in range(i+1,n):
        temp = calc(x_dic[i], x_dic[j], d)
        if temp == math.ceil(temp):
            ans += 1
print(ans)

Solution (Python):
import math
n, d = map(int, input().split())
x = list(input().split() for i in range(n))
x = [[int(i) for i in x[j]] for j in range(len(x))]
a = 0
for i in range(n-1):
    for j in range(i+1,n):
        di = 0
        for b in range(d):
            di += (x[i][b] - x[j][b]) ** 2
        di = math.sqrt(di)
        if di == int(di):
            a += 1
        else:
            pass
print(a)

Solution (Python):
import math
n, d = map(int, input().split())
def dist(x, y):
    ans = 0
    for i in range(d):
        ans += (x[i] - y[i]) ** 2
    if int(math.sqrt(ans)) * int(math.sqrt(ans)) == ans:
        return True
    else:
        return False
arr = []
for i in range(n):
    x = list(map(int, input().split()))
    arr.append(x)
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if i == j:
            continue
        if dist(arr[i], arr[j]):
            ans += 1
print(ans)

Solution (Python):
n, d = map(int, input().split())
p = []
for i in range(n):
  p.append(list(map(int, input().split())))
def distance(x, y):
  a = 0
  for i in range(d):
    a += (p[x][i]-p[y][i])**2
  return(a**0.5)

ans = 0
a = 0
while a < n:
  for i in range(a+1, n):
    if distance(a, i) % 1 ==0:
      ans += 1
  a += 1

print(ans)

Solution (Python):
n,*l, = [list(map(int,s.split()))for s in open(0)]
cnt = 0
for i in range(len(l)-1):
    for j in range(i+1,len(l)):
        dist = 0
        for d in range(n[1]):
            dist += (l[i][d] - l[j][d])**2
        if (dist**(0.5))%1 ==0:
            cnt += 1
print(cnt)

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

c = 0
for i in range(n):
    for j in range(i+1, n):
        s = 0
        for k in range(d):
            s += (X[i][k] - X[j][k])**2
        s = s**0.5

        if s.is_integer():
            c += 1
print(c)

Solution (Python):
import itertools
import math

def kyori(data1, data2):
    result = 0
    for i in range(len(data)):
        result += (data1[i]-data2[i])**2
    return math.sqrt(result)

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

comb = itertools.combinations(X, 2)
ans = 0
for c in comb:
   if kyori(c[0],c[1]).is_integer():
       ans += 1

print(ans)

Solution (Python):
import itertools


def distance(Y, Z):
    result = 0
    for y, z in zip(Y, Z):
        result += (int(y) - int(z)) ** 2
    result = result ** 0.5
    return result


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


ans = 0
for Y, Z in itertools.combinations(X, 2):
    if distance(Y, Z).is_integer():
        ans += 1

print(ans)