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(" "))
X=[input().split(" ") for _ in range(N)]

Ans_List=[]
for i in range(N):
    for j in range(i+1,N):
        Sum=0
        for k in range(D):
            Sum+=(int(X[i][k])-int(X[j][k]))**2
        Ans_List.append(math.sqrt(Sum))
        
count=0
for i in Ans_List:
    if int(i)==i:
        count+=1
        
print(count)

Solution (Python):
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]

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

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

ans = 0
for i in range(len(arr)-1):
  for j in range(i+1, len(arr)):
    dis = 0
    for k in range(d):
      dis += (arr[i][k] - arr[j][k])**2
    l = 0
    while l*l < dis:
      l+=1
      if l*l == dis:
        ans += 1

print(ans)

Solution (Python):
import math


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

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

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

print(ans)

Solution (Python):
N,D=map(int, input().split())
X=list(list(map(int, input().split())) for _ in range(N))
import itertools
import math
tmp=0
ans=0
for x1,x2 in list(itertools.combinations(X,2)):
    for d in range(D):
        tmp+=(x1[d]-x2[d])**2
    tmp=math.sqrt(tmp)
    tmp1=math.ceil(tmp)
    if tmp==tmp1:
        ans+=1
    tmp=0
print(ans)

Solution (Python):
N, D, *X = map(int, open(0).read().split())
*X, = zip(*[iter(X)]*D)

cnt = 0
for i, x in enumerate(X):
    for j in range(i+1, N):
        d = 0
        for y, z in zip(x, X[j]):
            d += (y-z)**2
        if (d**0.5).is_integer():
            cnt += 1

print(cnt)

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

        temp = int(dis ** 0.5)
        if temp ** 2 == dis:
            cnt += 1
print(cnt)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    import numpy as np
    n,d=map(int, input().split())
    l=[list(map(int,input().split())) for i in range(n)]
    cnt=0
    for j in range(n-1):
        for k in range(j+1,n):
            a=np.array(l[j])-np.array(l[k])
            if np.linalg.norm(a)%1==0:
                cnt+=1
    print(cnt)
resolve()

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

Solution (Python):
def main():
    n, d = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*n]

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


main()

Solution (Python):
def main():
    from math import sqrt
    import sys
    input = sys.stdin.buffer.readline
    N, D = (int(i) for i in input().split())
    Xs = [[int(i) for i in input().split()] for j in range(N)]

    def check(A, B):
        v = sum((a-b)**2 for a, b in zip(A, B))
        if sqrt(v).is_integer():
            return True
        else:
            return False

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if check(Xs[i], Xs[j]):
                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())))

cnt=0

i=0
while i<n-1:
    j=i+1
    while j<n:
        temp=0
        for k in range(d):
            temp+=(x[i][k]-x[j][k])**2
        if temp==int(temp**(1/2))*int(temp**(1/2)):
            cnt+=1
        
        j+=1
    i+=1    

print(cnt)

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):
        y = x[i]
        z = x[j]
        a = 0
        for k in range(d):
            a += (y[k] - z[k]) ** 2
        a = a ** 0.5
        if int(a) == a:
            ans += 1

print(ans)

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

ans = 0
for i, j in combinations(x, 2):
    tmp = 0
    for k, l in zip(i, j):
        tmp += (k-l)**2
    if round(tmp**0.5)**2==tmp:
        ans += 1
print(ans)

Solution (Python):
from math import sqrt

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

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

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if tmp == int(sqrt(tmp)) ** 2:
            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):
        pw = 0
        for k in range(d):
            pw += (x[i][k]-x[j][k])**2
        if pw**0.5%1==0: ans+=1
print(ans)

Solution (Python):
N,D = map(int,input().split())
X = [tuple(map(int,input().split())) for i in range(N)]
ans = 0
for i,x in enumerate(X[:-1]):
    for y in X[i+1:]:
        d = 0
        for a,b in zip(x,y):
            d += (a-b)**2
        if int(d**0.5) == d**0.5:
            ans += 1
print(ans)

Solution (Python):
import math
N,D = map(int,input().split())
k = []
ans_2 = 0
ans_1 = 0
now = 0
for i in range(N):
    k.append(list(map(int,input().split())))
for i in range(0,N):
    for j in range(i+1,N):
        for _ in range(D):
            now += (k[i][_]-k[j][_])**2
        ans_1 = math.sqrt(now)
        if ans_1%1 == 0:
            ans_2 += 1
        now = 0
        ans_1 = 0
print(ans_2)

Solution (Python):
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
ans=0
for t in range(N-1):
    for s in range(t+1,N):
        count=0
        for x in range(D):
            count+=(X[t][x]-X[s][x])**2
        Z=count**(1/2)
        if Z.is_integer()==True:
            ans+=1
print(ans)

Solution (Python):
n,d = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(n)]
p = 0
if d != 10:
    for i in range(n):
        for j in range(10-d):
            ls[i].append(0)
for k in range(n):
    for l in range(n):
        if k < l:
            if ((ls[k][0]-ls[l][0])**2+(ls[k][1]-ls[l][1])**2+(ls[k][2]-ls[l][2])**2+(ls[k][3]-ls[l][3])**2+(ls[k][4]-ls[l][4])**2+(ls[k][5]-ls[l][5])**2+(ls[k][6]-ls[l][6])**2+(ls[k][7]-ls[l][7])**2+(ls[k][8]-ls[l][8])**2+(ls[k][9]-ls[l][9])**2)**(1/2) %1==0:
                p += 1
print(p)

Solution (Python):
import numpy as np
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, d = map(int, readline().split())
x = np.array(read().split(), np.int64).reshape(n, d)

z = []
ans = 0

for i in range(400):
    z.append(pow(i, 2))

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

        if t in z:
            ans += 1

print(ans)

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    import numpy as np
    n,d=map(int, input().split())
    l=[list(map(int,input().split())) for i in range(n)]
    cnt=0
    for j in range(n-1):
        for k in range(j+1,n):
            a=np.array(l[j])-np.array(l[k])
            if (np.linalg.norm(a))%1==0:
                cnt+=1
    print(cnt)
resolve()

Solution (Python):
n,d = map(int,input().split())
arr = [list(map(int,input().split())) for i in range(n)]
from math import sqrt
count = 0
from itertools import combinations
for kumi in combinations(range(n),2):
    inroot = 0
    for i in range(d):
        inroot += (arr[kumi[0]][i]-arr[kumi[1]][i])**2
    if sqrt(inroot)%1==0:
        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):
        tmp = 0
        for k in range(d):
            tmp += (x[i][k] - x[j][k]) ** 2
        tmp = math.sqrt(tmp)
        if tmp == int(tmp):
            cnt += 1
print(cnt)

Solution (Python):
import math

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

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

print(ans)

Solution (Python):
import itertools

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

cnt = 0
for c in list(itertools.combinations(range(n), 2)):
    total = 0
    for i in range(d):
        total += (abs(x[c[0]][i] - x[c[1]][i])) ** 2
    ans = total ** 0.5
    if ans == int(ans):
       cnt += 1
print(cnt)

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

for v in itertools.combinations(X, 2):
  s = 0
  for i in range(d):
    s += (v[0][i] - v[1][i]) ** 2
  if math.sqrt(s).is_integer():
    ans += 1

print(ans)

Solution (Python):
n,d = map(int, input().split())
arr = []
for i in range(n):
  arr.append(list(map(int, input().split())))
res = 0
for i in range(n-1):
  for j in range(i+1,n):
    dist = 0
    for k in range(d):
      dist += (arr[i][k] - arr[j][k])**2
    if dist == float(int(pow(dist,1/2))**2):
      res += 1
print(res)

Solution (Python):
import math

N, D = map(int, input().split())
Ps = []
count = 0

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

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

for i in range(N-1):
  for j in range(i+1, N):
    if math.sqrt(dis2(Ps[i], Ps[j])).is_integer():
      count += 1

print(count)

Solution (Python):
def dist(a, b):
    v = 0
    for d in range(D):
        v += (a[d]-b[d])**2
    v = v ** 0.5
    return v


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

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

print(ans)

Solution (Python):
import numpy as np
import sys
import math

n,d=map(int,input().split())
X=[]
for i in range(n):
    X.append(list(map(int,input().split())))
ans=0
X=np.array(X)
for i in range(n-1):
    for j in range(i+1,n):
        temp=0
        for k in range(d):
            temp+=(X[i][k]-X[j][k])**2
        if math.sqrt(temp)%1==0:
            ans+=1

print(ans)

Solution (Python):
n,d = map(int,input().split())
x = [0]*n
for i in range(n):
    x[i] = list(map(int,input().split()))
count = 0
for i in range(n):
    for j in range(n):
        dis2 = 0
        for k in range(d):
            dis2 += (x[i][k]-x[j][k])**2
        dis = float((dis2)**0.5)
        if dis.is_integer() == True:
            count += 1
print(int((count-n)/2))

Solution (Python):
import math
def main():
    N, D = map(int, input().split())
    pt = []
    for _ in range(N):
        p = list(map(int, input().split()))
        pt.append(p)

    ans = 0
    for i in range(N):
        for j in range(i):
            l = 0
            for k in range(D):
                l += pow(pt[i][k]-pt[j][k], 2)
            l = math.sqrt(l)
            if l == int(l): ans += 1
    return ans

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

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


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

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

Solution (Python):

import sys
import itertools
import fractions
import copy
import bisect
import math
import numpy as np


from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter





N=3
M=3
i=0
j=0
k=0
sum=0
r=1
a=[0]*5
b=[]






"1行1つの整数を入力を取得し、整数と取得する"

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

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


for i in itertools.combinations(brray, 2):
    
    
    for j in range(D):
        sum=((abs(i[0][j]-i[1][j]))**2)+sum

    judge=np.sqrt(sum)
    
    
    
    
    if judge.is_integer():
        k=k+1
    sum=0
print(k)



"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

Solution (Python):
from math import sqrt

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 k in range(D):
            dist += (X[i][k] - X[j][k])**2
        
        if sqrt(dist) % 1 == 0:
            ans += 1
    
print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline
import math
def main():
    N, D = map(int, input().split())
    X = [list(map(int, input().split())) for i in range(N)]
    DIST, CNT = 0, 0
    for i in range(N-1):
        for j in range(i+1,N):
            for d in range(D):
                DIST += abs(X[i][d] - X[j][d])**2
            if math.sqrt(DIST).is_integer():
                CNT +=1
            DIST = 0
    print(CNT)
    

if __name__ == '__main__':
    main()

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

count=0
for j in range(0,n-1):
  for k in range(j+1,n):
    dist=0
    for l in range(0,d):
      dist+=(lis[j][l]-lis[k][l])**2
    if (dist**(1/2))%1==0:
      count+=1
print(count)

Solution (Python):


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

matrix = []
for _ in range(n):
    row = [int(i) for i in input().split()]
    matrix.append(row)

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        s = matrix[i]
        t = matrix[j]
        dist = 0
        for k in range(d):
            dist += (s[k] - t[k]) ** 2
        
        temp = 1
        while temp ** 2 <= dist:
            if temp ** 2 == dist:
                ans += 1
                break
            else:
                temp += 1
print(ans)

Solution (Python):


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

matrix = []
for _ in range(n):
    row = [int(i) for i in input().split()]
    matrix.append(row)

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        s = matrix[i]
        t = matrix[j]
        dist = 0
        for k in range(d):
            dist += (s[k] - t[k]) ** 2
        
        temp = 1
        while temp ** 2 <= dist:
            if temp ** 2 == dist:
                ans += 1
                break
            else:
                temp += 1
print(ans)

Solution (Python):

import numpy as np
n,d=map(int,input().split())
zahyo=[0]*n
count=0


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


for i in range(n):
    for j in range(i+1,n):
        dis=sum((arr[i]-arr[j])**2)
        if (dis**0.5).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)]

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

Solution (Python):
def dist(x, y):
    d = 0.0
    for i in range(len(x)):
        d += (x[i] - y[i]) ** 2
    return d ** 0.5

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

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        d = dist(x[i], x[j])
        if abs(d - int(d)) < 1e-6:
            ans += 1
print(ans)

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

Solution (Python):
N, D = map(int, input().split())
pts = [tuple(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 += (pts[i][k]-pts[j][k])**2
        if dist**0.5 == int(dist**0.5):
            ans += 1

print(ans)

Solution (Python):

import sys
N,D=map(int, sys.stdin.readline().split())
X=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]

L=[]  
for i in range(201):
    L.append(i**2)

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        t=0
        for x1,x2 in zip(X[i],X[j]):
            t+=(x1-x2)**2
        if t in L:
            ans+=1
print ans

Solution (Python):
N, D = map(int, input().split())
x =[]
cnt = 0


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

for j in range (N-1):
  for k in range (j+1, N):
    t = 0
    for d in range (D):
      t += (x[j][d]-x[k][d])**2
    if t **(1/2) %1 == 0:
      cnt += 1
        
        
print(cnt)

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

X = []
for n 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):
    sum = 0
    for d in range(D):
      sum += (X[i][d] - X[j][d]) ** 2
    if (sum ** (1/2)) % 1 == 0:
      cnt += 1
print(cnt)

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

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

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

Solution (Python):
n,d=map(int,input().split())
a=[list(map(int,input().split())) for j in range(n)]
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis+=(a[i][k]-a[j][k])**2
    dis=dis**(0.5)
    if dis==int(dis):
      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):
    d = 0
    for k in range(D):
      d += (X[i][k]-X[j][k])**2
    d = math.sqrt(d)
    if d.is_integer():
      ans += 1

print(ans)

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

Solution (Python):
import math
n,d = map(int,input().split())
a = [list(map(int,input().split())) for hoge in range(n)]
ans = -n
for b in a:
  for c in a:
    k = 0
    s = 0
    while k < d:
      s += (b[k]-c[k])**2
      k += 1
    poge = math.sqrt(s)
    if poge%1 == 0:
      ans += 1
print(ans//2)

Solution (Python):
import math

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

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

ans=0

for i in range (n-1):
    for j in range(i+1,n):
        sum=0.0

        
        for k in range(d):
            sum+=math.pow(a[i][k]-a[j][k],2)
        
        sum=math.sqrt(sum)

        
        if(sum==int(sum)):
            ans+=1

print(ans)

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 







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

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


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

    return math.sqrt(s)


count = 0
for i in range(len(L)):
    for j in range(i + 1, len(L)):
        fn = f(L[i], L[j])
        n = int(fn)
        if (n == fn):
            count += 1
        else:
            continue

print(count)

Solution (Python):
import numpy as np


n, d = map(int ,input().split())
x = []
sq = [i**2 for i in range(200)]
for i in range(n):
    x.append(list(map(int, input().split())))
x = np.array(x)
count = 0
for i in range(n):
    for j in range(i+1, n):
        if sum((x[i]-x[j])**2) in sq:
            count += 1
print(count)

Solution (Python):
import math
def main():
	n ,d = map(int,input().split())
	arr = [ ]
	for _ in range(n):
		arr.append(list(map(int,input().split())))
	ans = 0
	for i in range(n):
		for j in range(i+1,n):
			cnt  = 0	
			for k in range(d):
				cnt += (arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k])
			if math.sqrt(cnt)==int(math.sqrt(cnt)):
				ans+=1
	print(ans)
	return



main()

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

Solution (Python):
import math
n, d = map(int,input().split())
xs = []
for _ in range(n):
  x = list(map(int, input().split()))
  xs.append(x)
ans = 0
for i in range(n-1):
  xi = xs[i]
  for j in range(i+1, n):
    xj = xs[j]
    dist = 0
    for k in range(d):
      dist += (xi[k] - xj[k])**2
    dist = math.sqrt(dist)
    if dist - int(dist) == 0.0:
      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(i+1,n):
        distance = 0
        for k in range(d):
            distance += (x[i][k] - x[j][k])**2
        distance = distance**0.5
        if distance == int(distance):

            cnt += 1
print(cnt)

Solution (Python):


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

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)%1==0:
            ans += 1

print(ans)

Solution (Python):
import itertools
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
res = 0
for v in itertools.combinations(x, 2):
    dist = 0
    for i in range(d):
        dist += abs(v[0][i]-v[1][i])**2
    if math.sqrt(dist).is_integer():
        res += 1
print(res)

Solution (Python):
import itertools
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
res = 0
for v in itertools.combinations(x, 2):
    dist = 0
    for i in range(d):
        dist += abs(v[0][i]-v[1][i])**2
    if math.sqrt(dist).is_integer():
        res += 1
print(res)

Solution (Python):
N,D = map(int,input().split())
L = []
for i in range(N):
    X = list(map(int,input().split()))
    L.append(X)
import itertools
C = list(itertools.combinations(L,2))
ans = 0
for i in range(len(C)):
    s = 0
    for j in range(D):
        s += (C[i][0][j]-C[i][1][j])**2
    s = s**0.5
    if s == int(s):
        ans += 1
print(ans)

Solution (Python):
N,D=map(int,input().split())
ans=0
keep=[]
lis=[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449, 11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884, 15129, 15376, 15625, 15876, 16129]
for i in range(N):
  s=list(map(int,input().split()))
  keep.append(s)
for j in range(0,N):
  for k in range(j+1,N):
    num=0
    for l in range(D):
      num+=abs(keep[j][l]-keep[k][l])**2
    if num in lis:
      ans+=1
print(ans)

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

all_pattern = list(itertools.combinations(a,2))
ans = 0
for i in range((n*(n-1)) // 2):
    x1 = x[all_pattern[i][0]]
    x2 = x[all_pattern[i][1]]
    distance = 0
    for j in range(d):
        distance += ((x1[j] - x2[j]) ** 2)
    if math.sqrt(distance) == int(math.sqrt(distance)):
        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):
    sm = 0
    for k in range(d):
      sm += (x[i][k] - x[j][k])**2
    if sm == round(sm**0.5)**2:
      ans += 1
      
print(ans)