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):


"""
Created on Sun Jul  7 20:52:12 2019

@author: YudNK
"""

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

def norm(i,j):
    norm2 = 0
    for k in range(D):
        norm2 += (i[k] - j[k])**2
    return norm2**0.5

count = 0
while len(point) > 1:
    for i in range(len(point) - 1):
        a = norm(point[-1],point[i])
        if a*10%10 == 0:
            count += 1
    point.pop(-1)
print(count)

Solution (Python):
import numpy as np
n, d = input().split()
N = int(n)
D = int(d)
x = []
for i in range(N):
    x.append([int(i) for i in input().split()])
x = np.array(x)
def calc_distance(l1, l2):
    return np.sqrt(np.sum((l1 - l2)** 2))
count = 0
for i in range(N):
    for j in range(i + 1, N):
        dd = calc_distance(x[i], x[j])
        
        if dd.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)]

ans = 0

def check(s):
    t = math.sqrt(s)
    u = int(t)
    if u * u == s:
        return 1
    else:
        return 0

for i in range(n):
    for j in range(n - i - 1):
        l = j + i + 1
        s = 0
        for k in range(d):
            s += (x[i][k] - x[l][k]) ** 2
        ans += check(s)

print(ans)

Solution (Python):
import numpy as np

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



count = 0
for i in range(N):
  for j in range(N-i-1):
    pool = data[i,:] - data[i+j+1,:]
    pool = np.sqrt(np.sum(np.power(pool, 2)))
    if pool.is_integer():
      count += 1
print(count)

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

def dist(a,b):
    return sum([(p-q)**2 for p,q in zip(a,b)])

def is_sqrt(p):
    if p == int(p**0.5)**2:
        return True
    else:
        return False

ans = 0

for i in range(n):
    for j in range(i,n):
        if i == j:
            pass
        else:
            
            if is_sqrt(dist(x[i],x[j])):
                ans += 1
print(ans)

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

for i in range(n):
    y = x[i]
    for z in x[i+1:]:
        dis = 0
        for j in range(d):
            dis += (y[j] - z[j])**2
        a = math.sqrt(dis)
        if int(a) == a:
            answer += 1
print(answer)

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

if __name__ == "__main__":
    solve()

Solution (Python):
def is_sqrt(m,n):
    return m**2 <= n < (m+1)**2

def isqrt(n):
    low = 0
    high = n
    m = (low + high)//2

    while not is_sqrt(m,n):
        if m**2 < n: 
            low = m+1
        else: 
            high = m - 1
        m = (low + high) // 2
    return m

def is_square(n):
    return n == (isqrt(n))**2

n,d = map(int,raw_input().split())
x = []
for a in range(n):
  x.append(map(int,raw_input().split()))
ans = 0
for a in range(n):
  for b in range(a+1,n):
    q = 0
    for c in range(d):
      q += (x[a][c] - x[b][c])**2
    if is_square(q) == True:ans += 1
print ans

Solution (Python):
n, d = map(int, input().split())
coodinates = [[int(x) for x in input().split()] for _ in range(n)]
result = 0
for left in range(n-1):
    for right in range(left+1,n):
        dist = 0
        for i in range(d):
            dist += (coodinates[left][i] - coodinates[right][i])**2
        dist = dist ** 0.5
        result += 1 if dist.is_integer() else 0
print(result)

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

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

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

Solution (Python):
from math import sqrt

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


def calc_distance(A, B):

    distance = 0
    for a, b in zip(A, B):
        distance += (a - b)**2
    
    return sqrt(distance)

ans = 0
for i in range(N):
    for j in range(N):
        if i == j: continue
        d = calc_distance(X[i], X[j])
        if d.is_integer(): ans += 1


print(int(ans/2))

Solution (Python):
import numpy

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

def cal_distance(point1, point2):
    return numpy.linalg.norm(numpy.array(point1) - numpy.array(point2))

if __name__ == "__main__":
    counter = 0
    for i in range(N):
        for j in range(i + 1, N):
            
            if cal_distance(points[i], points[j]).is_integer():
                counter += 1

    print(counter)

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

import numpy as np
X = np.array(X)

count = 0
for n in range(N-1):
    d = np.sqrt(np.sum((X[n] - X[n+1:])**2, axis=1))
    count += np.sum(d == np.round(d))

print(count)

Solution (Python):
import sys
import numpy as np

str = [int(i) for i in input().split()]
n, d = str

s = [[int(j) for j in input().split()] for i in range(n)]
s = np.array(s)
count = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        tmp = np.sqrt(np.sum(np.power(s[i] - s[j], 2)))
        if tmp.is_integer() == True:
            count += 1
print(int(count/2))

Solution (Python):
import numpy as np
N,D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in range(N-1):
    x = np.array(X[i])
    for j in range(i+1,N):
        y = np.array(X[j])
        d = np.linalg.norm(x-y)
        if d - int(d) == 0:
            count += 1
print(count)

Solution (Python):
n, d = map(int, input().split())
p = []
count = 0

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

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

        pownum = total ** 0.5

        if pownum.is_integer():
            count += 1

print(count)

Solution (Python):
import math

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

cnt=0
for i in range(N-1):
    for j in range(N-i-1):
        j+=i+1
        s=0
        for d in range(D):
            s+=(X[i][d]-X[j][d])**2
        for l in range(160):
            if l**2==s:
                cnt+=1
                break
print(cnt)

Solution (Python):
import math

if __name__ == '__main__':
    n, d = map(int, input().split())
    l = []
    for i in range(0, n):
        l.append(list(map(int, input().split())))
    count = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            s = 0
            for k in range(0, d):
                s += math.pow(l[i][k] - l[j][k], 2)
            if math.sqrt(s).is_integer():
                count += 1
    print(count)

Solution (Python):
import math
a = list(map(int, input().split()))
x = [input().split() for i in range(a[0])]
ans =0
for i in range(a[0]-1):
    for k in range(i+1, a[0]):
        kyori=0
        for j in range(a[1]):
            kyori += (int(x[i][j])-int(x[k][j]))*(int(x[i][j])-int(x[k][j]))   
        if math.sqrt(kyori)==int(math.sqrt(kyori)):
            ans+=1
print(ans)

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

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

cnt = 0
import numpy
for i in range(1,n):
	for j in range(i):
		dis = numpy.linalg.norm(numpy.array(hoge[i]) - numpy.array(hoge[j]))
		if dis.is_integer():
			cnt += 1
print(cnt)

Solution (Python):
import math

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

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

ans = 0
mathTemp = 0

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

print(ans)

Solution (Python):


import math

def is_sqrt(n):
    s = int(math.sqrt(n))
    return s*s == n


def d2(d, pi, pj, xss):
    return sum([(xss[pi][i] - xss[pj][i])**2 for i in range(d)])


def solv(n, d, xss):
    count = 0
    for pi in range(n):
        for pj in range(pi):
            dd = d2(d, pi, pj, xss)
            if is_sqrt(dd):
                count += 1
    return count

if __name__ == '__main__':

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

    xss = []

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

    ans = solv(n, d, xss)
    print(ans)

Solution (Python):
import math

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

X = []

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

count = 0
for i in range(N):
  p1 = X[i]
  for j in range(i + 1, N):
    p2 = X[j]

    total = 0
    for k in range(D):
      total += abs(pow(p1[k] - p2[k], 2))

    total = math.sqrt(total)
    if total == int(total):
      count += 1

print(count)

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

Solution (Python):
import math

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

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

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

counter = 0
distance = 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 is_integer_num(distance):
            
            counter += 1

print(counter)

Solution (Python):


import numpy

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

count = 0
for i in range(N):
    for j in range(N):
        if i != j:
            a = numpy.array(X[i])
            b = numpy.array(X[j])
            u = b - a
            distance = numpy.linalg.norm(u)
            if distance == int(distance):
                count += 1

print(int(count/2))

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()])
c = 0
for i in range(n):
    for j in range(n):
        if i>=j :
            continue
        dis = 0.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.is_integer():
            c+=1
print(c)

Solution (Python):
import math

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

X = []
result = 0

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

for i in range(N):
	p1 = X.pop(0)
	for p2 in X:
		diff = 0
		for i in range(D):
			diff += (p1[i] - p2[i])**2
		res = math.sqrt(diff)
		if res.is_integer():
			result += 1

print(result)

Solution (Python):



import math

N, D = map(int, input().split())
x_arr = [list(map(int, input().split())) for i in range(N)]
num = 0
ctr = 0


for i in range(N):
    for j in range(i + 1, N):
        for k in range(D):
            num += pow(x_arr[j][k] - x_arr[i][k],2)
        dist = math.sqrt(num)
        if dist.is_integer():
            ctr += 1
        num = 0
print(ctr)

Solution (Python):

import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, D: int, X: "List[List[int]]"):
    ret = 0
    for i in range(N):
        for j in range(N):
            if j <= i:
                continue

            acc = 0
            for y, z in zip(X[i], X[j]):
                acc += (y - z) ** 2

            tmp = int(sqrt(acc))
            ret += int((tmp * tmp) == acc)
    return ret


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    D = int(next(tokens))  
    X = [ [ int(next(tokens)) for _ in range(D) ] for _ in range(N) ]  
    result = solve(N, D, X)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
N, D = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(N)]
c = 0
for i in range(N):
  for j in range(i+1, N):
    S = 0
    for p in range(D):
      S  += (m[i][p]-m[j][p])**2

    if (S**0.5-int(S**0.5)) == 0:
      c += 1
print(c)

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

Solution (Python):


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

ok = 0
for i in range(0, n - 1):
    for j in range(i + 1, n):
        s = 0
        for k in range(d):
            s += (x[j][k] - x[i][k]) ** 2
        f = s ** (1/2)
        if f == int(f):
            ok += 1

print(ok)

Solution (Python):
import math

def dist(x1,x2):
    tmp = 0
    for i,j in zip(x1,x2):
        tmp += (i - j) * (i - j)
    return math.sqrt(tmp)

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

count = 0
for i in range(n):
    for j in range(i+1,n):
        tmp = dist(x[i],x[j])
        if abs(tmp - round(tmp)) < 0.0001:
            count += 1
print(count)

Solution (Python):

n1, n2 = [int(i) for i in input().split()]

na3 = [0] * n1
for i4 in range(n1):
    na3[i4] = [int(j) for j in input().split()]

r1 = 0
for i5 in range(n1):
    for j6 in range(n1):
        if i5 >=  j6:
            continue
        else:
            s7 = 0
            for i8 in range(n2):
                s7 += (na3[i5][i8] - na3[j6][i8]) **2
            if  (s7 ** 0.5) % 1 == 0:
                r1 += 1

print(r1)

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

sum=0;
for i in range(n):
    for j in range(i+1,n):
        iNP=np.array(x[i])
        jNP=np.array(x[j])
        dNP=iNP-jNP
        dNP=np.square(dNP)
        d=np.sqrt(np.sum(dNP))
        if(d%1.0==0):
            sum+=1
print(sum)

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

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

sum_a2=0
cnt=0
for i in range (n):
    for j in range (n):
        sum_a2=0
        if (i<j):
            for k in range(d):
                a=xl[i][k]-xl[j][k]
                a2=a*a
                sum_a2=sum_a2+a2
            ans=math.sqrt(sum_a2)
            
            if (ans.is_integer()):
                cnt=cnt+1
print(cnt)

Solution (Python):
N, D = map(int, input().split())
X = list()
for i 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) :
		s = 0
		for k in range(D) :
			s += (X[i][k] - X[j][k]) ** 2
		d = s ** (1/2)
		if(d == int(d)) :
			cnt += 1
		else :
			pass
	
print(cnt)

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

Solution (Python):
import math

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


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

count = 0
for i in range(N):
  for j in range(i+1, N):
    if is_int(X_list[i], X_list[j]):
      count += 1
print(count)

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

Solution (Python):
import math;

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def main():
    n,d = map(int,input().split())
    x = []
    for i in range(n):
        x.append([y for y in map(int,input().split())])
    ans = 0
    for i in range(n):
        for j in range(n):
            if i>=j:
                continue
            res = 0
            for k in range(d):
                res += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k])
            res = math.sqrt(res)
            res1 = int(res)
            if res1==res:
                ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()

Solution (Python):
import math

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

lin = []
lin.append(list(map(int, input().split())))

count = 0

apd = lin.append

for i in range(1, n):
    apd(list(map(int, input().split())))

    for j in range(0, i):
        tmp = sum([(lin[i][k] - lin[j][k]) * (lin[i][k] - lin[j][k])
                   for k in range(d)])
        
        if(math.sqrt(tmp) % 1 == 0):
            count += 1
print(count)

Solution (Python):
from collections import defaultdict
from math import sqrt
def prime(n):
	d=defaultdict(int)
	while n%2==0:
		d[2]+=1
		n=n//2
	for i in range(3,int(sqrt(n))+1,2):
		while n%i==0:
			d[i]+=1
			n=n//i
	if n>2:
		d[n]+=1
	for p in d:
		if d[p]%2!=0:
			return False
	return True

n,d=map(int,input().split( ))
a=[]
for _ in range(n):
	l=list(map(int,input().split( )))
	a.append((l))
count=0
for i in range(n-1):
	for j in range(i+1,n):
		t1=a[i]
		t2=a[j]
		k=0
		check=0
		while k<d:
			diff=(t1[k]-t2[k])**2
			check+=diff
			k+=1
		if prime(check):
			count+=1
print(count)

Solution (Python):
import numpy as np

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

c = [1 if np.linalg.norm(x[i]-x[j]).is_integer() else 0 for i in range(1, len(x)) for j in range(i)]
print(sum(c))

Solution (Python):

N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))
    
ans = 0
for i in range(N):
    for k in range(i, N):
        if i == k:
            pass
        else:
            d_lst = []
            for s in range(D):
                d_lst.append((X[i][s] - X[k][s]) ** 2)
            b = sum(d_lst)
            a = int(sum(d_lst) ** 0.5)
            if abs(a * a - b) < 0.0000001:
                ans += 1

print(ans)

Solution (Python):
import numpy as np

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

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

def distance(p1, p2):
  squares = np.square(p1 - p2)
  return np.sqrt(squares.sum())

count = 0
for i in range(N):
  for j in range(i+1, N):
    dist = distance(points[i], points[j])
    count += dist.is_integer() * 1

print(count)

Solution (Python):
import math

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

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

count = 0
Dis = 0
Dis2 = 0
for i in range(N-1):
    for j in range(i+1,N):
        for d in range(D):
            Dis2+=(X[i][d]-X[j][d])**2
        Dis = math.sqrt(Dis2)
        if is_integer_num(Dis):
            count+=1
        Dis2 = 0
print(count)

Solution (Python):

"""
Created on Sun Jul  7 20:59:16 2019

@author: sp8783
"""
import math

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

ans = 0

for i in range(n):
    for j in range(i+1,n):
        if i != j:          
            tmp = 0
            for k in range(d):
                tmp = tmp + (lst[i][k] - lst[j][k])**2
            dis = math.sqrt(tmp)
            if dis == math.floor(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)]

co=0

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

print(co)

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

count=0
for i in range(N):
  for j in range(i+1,N):
    mass=0
    for z in range(D):
      mass += (int(lists[i][z])-int(lists[j][z]))**2
    if(math.sqrt(mass).is_integer()):
      count+=1
print(count)

Solution (Python):
import math
N,D = [int(x) for x in input().split()]
X = [list(map(int,input().split())) for i in range(N)]
count = 0
for j in range(N):
    for k in range(j+1,N):
        tmp = 0
        for l in range(D):
            tmp += pow(X[j][l] - X[k][l],2)
        if math.sqrt(tmp) % 1 == 0:
            count += 1
print(count)

Solution (Python):
import math

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

count = 0
for a in range(n):
    x1 = xs[a]
    for b in range(n):
        if a == b:
            continue
        x2 = xs[b]
        r = 0
        for ii in range(d):
            r += abs(x1[ii] - x2[ii])**2
        r = math.sqrt(r)
        if r.is_integer():
            count += 1
print(int(count / 2))

Solution (Python):
import math

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

x_li = []

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

    x_li.append(x)

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

        if math.sqrt(total) == int(math.sqrt(total)):
            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(N-1):
  X1 = X[i]
  for j in range(i+1,N):
    X2 = X[j]
    d2 = 0
    for k in range(D):
      d2 += (X1[k]-X2[k])**2
    if d2**0.5 == int(d2**0.5):
      count += 1
print(count)

Solution (Python):
n,d=map(int,input().split())
w=[]
for i in range(n):
    l=[int(i) for i in input().split()]
    w.append(l)
ans=chk=0
for i in range(n-1):
    for j in range(i+1,n):
        x=0
        for k in range(d):
            x+=(w[i][k]-w[j][k])**2
        ans+=[0,1][x==int(pow(x,0.5))**2]
print(ans)

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

Solution (Python):
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()))

cnt = 0
for i in range(N-1):
	for j in range(i+1, N):
		l = 0
		for x in range(D):
			l += (X[i][x] - X[j][x])**2
		if math.sqrt(l)-math.floor(math.sqrt(l)) == 0:
			cnt += 1

print(cnt)

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

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

for n in range(N-1):
    for s in range(n+1, N):

        for d in range(D):
            tmp_d += (x[n][d] - x[s][d])**2

        if tmp_d**(1/2) == int(tmp_d**(1/2)):
            counter += 1
        
        tmp_d = 0

print(counter)

Solution (Python):
import numpy as np
import math
n,d=map(int,input().split())
count=0
x=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    for j in range(n):
        x[i]=np.array(x[i])
        x[j]=np.array(x[j])
        l=np.linalg.norm(x[j]-x[i])
        if l.is_integer()==True and i!=j and i<j:
            count+=1
print(count)

Solution (Python):
import math
n,d = map(int,input().split())
dimention = []
ret =0
for i in range(n):
    next = list(map(int,input().split()))
    dimention.append(next)
for i in range(n-1):
    for j in range(i+1,n):
        s = 0
        for k in range(d):
            v = dimention[i][k]-dimention[j][k]
            s+= v*v
        ans = math.sqrt(s)
        ans = int(ans)
        if ans*ans==s:
            ret+=1
print(ret)

Solution (Python):
import math
n,d=map(int,input().split())
x = []
num = 0
z = 1
for m in range(n):
  x += [list(map(int,input().split()))]

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

Solution (Python):
import numpy as np

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

count = 0
for i in range(N):
  for j in range(N):
    a = np.array(cor[i])
    b = np.array(cor[j])
    u = b-a
    leng = np.linalg.norm(u)
    
    if leng!=0:
      if leng.is_integer() == True:
      	count += 1
print(count//2)

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

X = []
ans = 0

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

for i in range(n):
    for j in range(i+1,n):
        d1 = 0
        for k in range(d):
            d1 += (abs(X[i][k] - X[j][k]))**2
        d2 = math.sqrt(d1)
        if d2%1 == 0:
            ans += 1

print(ans)

Solution (Python):



def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, D = read_h()
    X = read_v(N, m=D)

    import numpy as np

    cnt = 0
    for i in range(0, N - 1):
        for j in range(i + 1, N):
            dist = np.sqrt(np.sum(np.power(np.asarray(X[i]) - np.asarray(X[j]), 2)))
            if dist - np.floor(dist) == 0.0:
                cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

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

Solution (Python):
import numpy as np
import math

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

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


def calc_distance(y, z):
    
    return float(
        math.sqrt(
            sum([(np_nums[y][d] - np_nums[z][d]) ** 2 for d in range(D)])
        )
    )


ans = 0
for Y in range(N - 1):
    for Z in range(Y + 1, N):
        if calc_distance(Y, Z).is_integer():
            ans += 1

print(ans)

Solution (Python):
import itertools
import math
def distance(v1,v2):
    if(len(v1)!=len(v2)):
        return False
    distance = 0
    for i in range(len(v1)):
        distance+=(v2[i]-v1[i])**2
    return math.sqrt(distance)


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

comb_l = list(itertools.combinations([i for i in range(N)],2))
ans = 0
for comb in comb_l:
    if(distance(plots[comb[0]],plots[comb[1]]).is_integer()):
        ans+=1

print(ans)

Solution (Python):
import numpy as np

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

count = 0
for i in range(N):
  for j in range(N):
    a = np.array(cor[i])
    b = np.array(cor[j])
    u = b-a
    leng = np.linalg.norm(u)
    
    if leng!=0:
      if leng.is_integer() == True:
      	count += 1
print(count//2)

Solution (Python):
import itertools
from scipy.spatial import distance

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

xs = []

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

pairs = list(itertools.combinations(xs, 2))

print(sum([True if distance.euclidean(pair[0], pair[1]) % 1 == 0 else False for pair in pairs]))

Solution (Python):
import math

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

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


cnt = 0

for p_i in points:
    for p_j in points:
        
        
        if p_i == p_j:
            continue
        
        
        dist = 0
        for d_i in range(0, d):
            dist += (p_i[d_i] - p_j[d_i]) * (p_i[d_i] - p_j[d_i])
        dist = math.sqrt(dist)
        




        
        
        if dist == int(dist):
            cnt += 1
        
print(int(cnt /2))