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 = []
while True:
  try:
    tmp = list(map(int,input().split()))
    x.append(tmp)
    
  except:
    break
    
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
    if int(math.sqrt(t))==math.sqrt(t):
      ans +=1
print(ans)

Solution (Python):
'''自分はこれをもう一回といた時にこのコードを見てあまり考えすぎずに
何をしているのがわかるのか教えて欲しいもしあまりにも考えてしまうなら
コメントを書いといてあげたほうがいいかもねこれからはなしでも何をしてどうやって解いているのか
関数とかを調べれば思い出せるならコメント書く時間は無駄かもね'''


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

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 round(math.sqrt(d)) ** 2 == d:
      ans += 1
print(ans)

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

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 round(math.sqrt(d)) ** 2 == d:
      ans += 1
print(ans)

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

Solution (Python):
import numpy as np

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

X = [[int(i) for i in 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 np.sqrt(tmp) % 1 == 0:
            ans += 1
            
print(ans)

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

Solution (Python):
import numpy as np
import math
n,d = map(int,input().split())
A =np.array([list(map(int,input().split())) for _ in range(n)])
ans =0
for i in range(n):
    for j in range(i+1,n):
        B = np.array(A[i] - A[j])
        if math.sqrt(sum(np.square(B))) == -1*(math.sqrt(sum(np.square(B))) //-1):
            ans += 1
print(ans)

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

import numpy as np    

ans = 0

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

Solution (Python):
import math
n,d=map(int,input().split())
cnt=0
dlist=[list(map(int,input().split())) for _ in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        ans=0
        for k in range(d):
            ans+=(dlist[i][k]-dlist[j][k])**2
        cnt+=math.floor(ans**0.5)==math.ceil(ans**0.5)

print(cnt)

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

temp_list = []
for _ in range(n):
    x_list = [int(x) for x in input().split()]
    temp_list.append(x_list)

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

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

for i in range(N):
    for j in range(i+1,N):
        temp=0
        for k in range(D):
            temp+=(X[i][k]-X[j][k])**2
        temp=(temp)**(1/2)
        if temp ==temp//1:
            count+=1

print(count)

Solution (Python):

from itertools import combinations

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

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

for a,b in combinations(X,2):
    if (sum((a[i]-b[i])**2 for i in range(d))) ** (1/2) % 1 == 0:
        count += 1
print(count)

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

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 round(math.sqrt(d)) ** 2 == d:
      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):
    for j in range(i+1, N):
        temp = 0
        for k in range(D):
            temp += (X[i][k] - X[j][k])**2
        temp = temp**(1/2)
        if temp == temp//1:
            ans+=1
print(ans)

Solution (Python):

n, d = map(int, input().split())
l = []
ans = []

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

for i in range(n-1):
  for j in range(i+1, n, 1):
    total = 0
    for k in range(d):
      total += abs(l[i][k] - l[j][k]) ** 2

    ans.append(total)

cnt = 0

for i in ans:
  for j in range(i+1):
    if j**2 == i:
      cnt += 1
      break

print(cnt)

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)

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])*(x[i][k]-x[j][k])

    dis=math.sqrt(dis)
    if dis==int(dis):
      cnt+=1

print(cnt)

Solution (Python):
n, d = map(int, input().split())
x = [[int(i) for i in input().split()] for _ in range(n)]
c = 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
        s = s ** 0.5
        if s == int(s):
            c += 1
print(c)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n,d = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(n)]
    res = 0
    def calc(a, b):
        total = 0
        for i in range(d):
            total += (a[i]-b[i])**2
        total = total ** 0.5
        return total.is_integer()

    for i in range(n-1):
        for j in range(i+1, n):
            if calc(x[i], x[j]):
                res += 1
    print(res)

if __name__ == '__main__':
    main()

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

ans = 0
sum = 0
for i in range(n):
    for j in range(1, n-i):
        for a, b in zip(x[i], x[i+j]):
            sum += (a-b)**2
        if math.sqrt(sum) == int(math.sqrt(sum)):
            ans += 1
        sum = 0
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):
    for j in range(i, n):
        leng = 0
        for k in range(d):
            leng += (x[i][k] - x[j][k]) ** 2
        for m in range(130):
            if leng == m ** 2:
                ans += 1
print(ans - n)

Solution (Python):

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

count = 0

for i in range(N):
    for j in range(i + 1, N):
        distance = (sum([(X[i][k] - X[j][k]) ** 2 for k in range(D)])) ** 0.5
        if distance ** 2 == (int(distance)) ** 2:
            count += 1

print(count)

Solution (Python):
import numpy as np


def main():
    N, D = map(int, input().split())
    p = [np.array(list(map(int, input().split()))) for _ in range(N)]
    ans = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            d = np.sqrt(np.sum(np.power(p[i] - p[j], 2)))
            if d % 1 == 0:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math
import itertools

n,d=map(int,input().split())
l=list()
for i in range(n):
    l.append(list(map(int,input().split())))
pp=0
for i,j in itertools.combinations(range(n),2):
    p=0
    for k in range(d):
        p += (l[i][k]-l[j][k])**2
    if math.sqrt(p)%1==0:
        pp+=1
print(pp)

Solution (Python):
import math

n,d = map(int,input().split())
x_inputs = [[int(j) for j in input().split()]for i in range(n)]

ans = 0
for i in range(n):
    for j in range(i+1,n):
        dist = math.sqrt(sum([(i-j)**2 for i,j in zip(x_inputs[i],x_inputs[j])]))
        
        if dist%1==0 and dist>0:
            ans+=1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N = int(input())
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""
import numpy as np


def distance(x, y, D):
    total = 0
    for d in range(D):
        total += np.abs(x[d] - y[d]) ** 2
    return np.sqrt(total)


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

ret = []
for i in range(N):
    for j in range(i+1, N):
        ret.append(distance(X[i], X[j], D))

counter = 0
for x in ret:
    if x - int(x) > 0:
        continue
    else:
        counter += 1


print(counter)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    n, a, b = LI()
    print(min(n * a, b))
    return


def B():
    n, d = LI()
    x = LIR(n)
    a = list(itertools.combinations(range(n), 2))
    ans = 0
    for a1,a2 in a:
        b = 0
        for bi in range(d):
            b += (x[a1][bi] - x[a2][bi])** 2
        if float.is_integer(math.sqrt(b)):
            ans += 1
    print(ans)
    return


def C():
    l, r = LI()
    ans = 2018
    if l // 2019 == r // 2019:
        for i in range(l, r + 1):
            for k in range(i+1, r + 1):
                ans = min(ans, (i * k) % 2019)
        print(ans)
    else:
        print(0)
    return


def D():
    n = II()
    a = LI()
    a = a + [a[0]]
    ans = [0] * n
    x = 0
    for i in range(1, n, 2):
        x = x + a[i + 1] - a[i]
    ans[1] = a[0] - x
    ans[0] = ans[1] + 2 * x
    for i in range(2, n):
        ans[i] = (a[i - 1] - ans[i - 1] // 2) * 2
    print(" ".join(map(str, ans)))

    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    B()

Solution (Python):

"""
Created on Sun Apr 19 20:44:36 2020

@author: Kanaru Sato
"""

import math

n,d = list(map(int, input().split()))
xs = []

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

count = 0

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

print(count)

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

for n in range(N):
    for k in range(n+1, N):
        tmp = 0
        for t in range(D):
            tmp += (X[n][t]- X[k][t])**2
        if int(math.sqrt(tmp)) == math.sqrt(tmp):
            count += 1
print(count)

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

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

def check(x,y):
    ss = sum([(x[i]-y[i])**2 for i in range(d)])
    i = 0
    while i*i<ss:
        i += 1
    return i*i==ss


res = 0
for i in range(n-1):
    for j in range(i+1,n):
        if check(xl[i],xl[j]):
            res += 1
print(res)

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

ans = 0

for a in range(N):
    for b in range(a):
        sq = 0
        for c in range(D):
            s = X[a][c] - X[b][c]
            sq += s*s
        for e in range(sq+1):
            if e*e == sq:
                ans += 1

print(ans)

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, D = MAP()
X = [LIST() for _ in range(N)]

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

	if sqrt(sum)%1 == 0:
		return 1
	else:
		return 0

cnt = 0
for i in range(N-1):
	for j in range(i+1, N):
		cnt += distance(X[i], X[j])

print(cnt)

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

for i in range(N-1):
    for j in range(i+1,N):
        tm = 0
        if i != j:
            for k in range(D):
                tm += (X[i][k] - X[j][k])**2

            if (tm**0.5).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)]
count=0

sum=0

for i in range(N):
  for j in range(1,N-i):
    for a,b in zip(X[i],X[i+j]):
      sum += (a-b)**2
    if sum**(0.5)==int(sum**(0.5)):
      count=count+1
    sum=0    

print(count)

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

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

sum=0

  

for i in range(N):
  for j in range(1,N-i):
    for k in range(D):
      
      sum=sum+(X[i][k]-X[i+j][k])**2
    
    if sum**(0.5)==int(sum**(0.5)):
      count=count+1
    sum=0    
    
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):
    for j in range(i + 1, n):
        add, dis = 0, 0
        for k in range(d):
            add += (x[i][k] - x[j][k]) ** 2
        dis = math.sqrt(add)
        if dis % 1 == 0:
            ans += 1

print(ans)

Solution (Python):
icase=0
if icase==0:
    from itertools import permutations, combinations,combinations_with_replacement,product
    n,d=map(int,input().split())
    x=[]
    for i in range(n):
        xi=list(map(int,input().split()))
        x.append(xi)
    xc=list(combinations(x,2))
    icnt=0
    for xxc in xc:
        dist=0
        x1=xxc[0]
        x2=xxc[1]
        for i in range(d):
            dist=dist+(x1[i]-x2[i])**2
        dist=dist**0.5
        if int(dist)==dist:
            icnt+=1
    print(icnt)

Solution (Python):


N, D = map(int,input().split())
X = []
for i in range(N):
    X.append(list(map(int,input().split())))
cnt = 0
for i,p in enumerate(X):
    for j,q in enumerate(X):
        dist = 0
        if i!=j:
            for xi in range(D):
                dist += (p[xi]-q[xi])**2
            dist = dist**0.5
            if dist == int(dist):

                cnt+=1
print(cnt//2)

Solution (Python):
import numpy as np
n,d = map(int,input().split())
arr = np.zeros((n,d))
for i in range(n):
    arr[i,:] = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        l = np.sum((arr[i,:] - arr[j,:])**2)**0.5
        if l.is_integer():
            ans+=1
print(ans)

Solution (Python):
import math
n,d = map(int,input().split())
l = []
for i in range(n):
  r = list(map(int,input().split()))
  l.append(r)
f = []
for i in range(n-1):
  for j in range(i+1,n):
    e = []
    for k in range(d):
      e.append((l[i][k]-l[j][k])**2)
    f.append(sum(e))
count = 0
for i in f:
  if math.sqrt(i).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)]
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        dis_2 = 0
        for k in range(D):
            dis_2 += (X[i][k] - X[j][k])**2
        dis = math.sqrt(dis_2)
        if dis%1 == 0:
            cnt += 1
print(cnt)

Solution (Python):
import itertools
import math

N,D = map(int,input().split(' '))
Xn = [ list(map(int,input().split(' '))) for n in range(N)]
comb_list = list(itertools.combinations(Xn,2))
ans = 0
for comb in comb_list:
    sum_num = 0
    for i,v in enumerate(comb[0]):
        sum_num += (comb[0][i] - comb[1][i])**2
    distance = math.sqrt(sum_num)
    if distance.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):
    add,dis = 0,0
    for k in range(d): 
      add += (x[i][k] - x[j][k]) ** 2 
      dis = math.sqrt(add)
    if dis % 1 == 0:
      count += 1
print(count)

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):
        Y = X[i]
        Z = X[j]
        d2 = sum((y - z) ** 2 for y, z in zip(Y, Z))
        for k in range(1, d2 + 1):
            if k * k == d2:
                ans += 1
print(ans)

Solution (Python):
N,M = list(map(int,input().split()))
list_dis = []
import math
total = 0
for i in range(N):
    list_dis.append(list(map(int,input().split())))
for i in range(N-1):
    A = list_dis[i]
    for j in range(N-1-i):
        f_total = 0
        B = list_dis[N-j-1]
        for k in range(M):
            f_total += abs(A[k]-B[k]) ** 2
        f_total = math.sqrt(f_total)
        if f_total.is_integer() == True:
            total += 1
print(total)

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):
        Y = X[i]
        Z = X[j]
        d = sqrt(sum([(y - z) ** 2 for y, z in zip(Y, Z)]))
        if float(int(d)) == d:
            ans += 1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)


def calc_dist(x, y):
    dist = 0
    for xi, yi in zip(x, y):
        dist += (yi - xi) ** 2
    return dist ** (1/2)


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

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


if __name__ == '__main__':
    main()

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

import math

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


count=0
dammy2=[]
for i in range(N-1):
    for j in range(i+1,N):
        for k in range(D):
            dammy1 = (X[i][k] - X[j][k]) ** 2
            dammy2.append(dammy1)
        if is_integer_num(math.sqrt(sum(dammy2))) == True:
            count+=1
        
        dammy2 = []

print(count)

Solution (Python):
import math
def main():
    N, D = map(int, input().split())
    points = [[int(a) for a in input().split()] for i in range(N)]
    counts = 0
    for i in range(N-1):
        for j in range(i + 1, N):
            d = 0
            for k in range(D):
                d += (points[i][k] - points[j][k])**2
            d = math.sqrt(d)
            if d.is_integer() == True:
                counts += 1
    print(counts)
main()

Solution (Python):
import numpy as np
def main():
    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):
            dist = np.linalg.norm(np.array(x[i]) - np.array(x[j])).item()
            if dist.is_integer():
                cnt += 1
    print(cnt)
if __name__ == "__main__":
    main()

Solution (Python):
import math

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

for i in range(0, N - 1):
    for j in range(i + 1, N):
        sss = 0
        for k in range(0, D):
            sss += (int_list[i][k] - int_list[j][k]) ** 2

        if math.sqrt(sss) % 1 == 0:
            count += 1

print(count)

Solution (Python):
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N, D = map(int, readline().split())
  X = [np.array(readline().split(), np.int64) for _ in range(N)]
  ans = 0
  for i in range(N-1):
    for j in range(i+1, N):
      d = (X[i]-X[j])**2
      dist = d.sum()
      r = int(dist**0.5)
      if r**2 == dist:
        ans += 1
      else:
        continue
  print(ans)
  
  
  
  
      
if __name__ == '__main__':
  main()

Solution (Python):
def IfSquare(n):
    i = 0
    while i*i < n:
        i += 1
    if i*i == n:
        return True
    else:
        return False

n,d = map(int,input().split(' '))
X = []
i = 0
while i < n:
    x = tuple(map(int,input().split(' ')))
    X.append(x)
    i += 1
count = 0
i = 0
while i < len(X):
    j = i+1
    while j < len(X):
        distance = 0
        p = 0
        while p < d:
            distance += (X[i][p] - X[j][p])*(X[i][p] - X[j][p])
            p += 1
        if IfSquare(distance):
            count += 1
        j += 1
    i += 1
print(count)

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

def distance(Y, Z, D):
    double_sum = 0
    for i in range(D):
        double_sum += (Y[i] - Z[i]) ** 2
    distance = math.sqrt(double_sum)
    return distance
    
    
count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dist = distance(X[i], X[j], D)
        if dist.is_integer():
            count += 1

print(count)

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

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

Solution (Python):
from math import sqrt
n,d = map(int,input().split())
points = []
for i in range(n):
    x = list(map(int,input().split()))
    points.append(x)
count = 0
for i in range(n):
    for j in range(i+1,n):
        total_distance_ij = 0
        for k in range(d):
            dis = (points[i][k] - points[j][k])**2
            total_distance_ij += dis
        squared = sqrt(total_distance_ij)
        if squared == int(squared):
            count += 1
print(count)

Solution (Python):

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

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

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

cnt = 0
for i in range(n):
    for j in range(i,n):
        if i != j and is_integer_num(dist(x[i],x[j])):
            cnt += 1
            
print(cnt)

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

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

Solution (Python):
import math
n, d = map(int,input().split())
all_li = [list(map(int,input().split())) for _ in range(n)]
count = 0
for i,li in enumerate(all_li):
    if i == len(all_li) - 1:
        break
    for l in all_li[i+1:]:
        all_sum = 0
        for a,b in zip(li,l):
            all_sum += (a-b)**2
        if math.sqrt(all_sum) == int(math.sqrt(all_sum)):
            count += 1
print(count)

Solution (Python):
N, M = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in [0]*N]

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())
point = [list(map(int,input().split())) for _ in range(n)]
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    dis = 0
    for k in range(0,d):
      dis += pow(point[i][k]-point[j][k],2)
    dis = dis**0.5
    if int(dis)==dis: count += 1
print(count)

Solution (Python):
import math

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

temp = []

for i in range(N):
    for j in range(i + 1, N):
        sum = 0
        for k in range(D):
            
            sum += abs(table[i][k] - table[j][k]) ** 2
        else:
            temp.append(sum)

ans = 0

for i in temp:
    if math.sqrt(i).is_integer():
        ans += 1

print(ans)

Solution (Python):
import itertools
import math
def myAnswer(N:int,D:int,X:list)->int:
   l = [i for i in range(N)]
   total = 0
   for i in itertools.combinations(l,2):
      distance = 0
      for n in range(D):
         distance += (X[i[0]][n] - X[i[1]][n])**2
      distance = distance**0.5
      if(distance == math.ceil(distance)):
         total += 1
   return total

   

def modelAnswer():
   tmp=1
def main():
   N,D = map(int,input().split())
   X = []
   for _ in range(N):
      X.append(list(map(int,input().split())))
   print(myAnswer(N,D,X[:]))

if __name__ == '__main__':
   main()

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

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

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

Solution (Python):
def read_ints():
  return [int(w) for w in input().split()]

N, D = read_ints()
X = [read_ints() for _ in range(N)]
perf_sq = set(x * x for x in range(1, 201))

ret = 0
for i in range(N):
  for j in range(i):
    dsq = sum((X[i][k] - X[j][k]) ** 2 for k in range(D))
    if dsq in perf_sq:
      ret += 1
print(ret)

Solution (Python):
import math
N,D = map(int,input().split())
X = [0]*N
total = 0
cnt = 0
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):
    for k in range(D):
      total += abs(X[j][k]-X[i][k])**2
    if math.sqrt(total)%1==0:
      cnt += 1
    total=0
print(cnt)

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

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