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=[list(map(int,input().split()))for _ in range(n)]
def a(a,b):
  aa=0
  for i in range(d):aa+=abs(a[i]-b[i])**2
  if math.sqrt(aa)%1==0:return 1
  return 0
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    ans+=a(x[i],x[j])
print(ans)

Solution (Python):
from math import sqrt
from itertools import combinations

def dist(X, Y):
    d = 0
    for x, y in zip(X, Y):
        d += pow(x-y, 2)
    d = sqrt(d)
    if d == int(d):
        return 1
    return 0

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

C = [i for i in range(N)]
ans = 0
for c in combinations(C, 2):
    ans += dist(Z[c[0]], Z[c[1]])

print(ans)

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

x = []

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

c = 0
for i in range(n):
	for j in range(i,n):
		tmp = 0.0
		for k in range(d):
			tmp += (x[i][k] - x[j][k])**2
		tmp = tmp**0.5
		if tmp != 0 and tmp.is_integer():
			c+=1
print(c)

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

    count = 0
    for i in range(N-1):
        for j in range(i+1, N):
            total = 0.0
            for x, y in zip(X[i], X[j]):
                total += abs(x - y) ** 2
            total = total ** 0.5
            if int(total) == total:
                count += 1

    print(count)

if __name__ == '__main__':
    main()

Solution (Python):
import math


def distance(A,B):
    tmp = 0
    for i in range(len(A)):
        tmp += (A[i] - B[i]) ** 2
    tmp = math.modf(tmp ** 0.5)
    if tmp[0] == 0.0:
        return True
    else:
        return False


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

Solution (Python):
import math

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

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


def dist(p1, p2, D):
    sum = 0
    for i in range(D):
        sum += (p1[i] - p2[i]) ** 2
    return math.sqrt(sum)


cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        d = dist(X[i], X[j], D)
        if d.is_integer():
            cnt += 1
print(cnt)

Solution (Python):
from math import sqrt

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

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        sq_d = 0
        for k in range(D):
            sq_d += (X[i][k] - X[j][k]) ** 2
        d = sqrt(sq_d)
        if d - int(d) == 0:
            ans += 1
print(ans)

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

r = 0
for i in range(N):
  for j in range(i+1, N):
    y, z= Xs[i], Xs[j]
    d2 = 0
    for k in range(D):
      d2 += (y[k]-z[k])*(y[k]-z[k])
    d = math.sqrt(d2)
    if d==int(d):
      r += 1
print(r)

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

Solution (Python):
def inpl():
    return list(map(int, input().split()))


def distance(X, Y):
    tmp = 0
    for i in range(len(X)):
        tmp += (X[i] - Y[i])**2
    return tmp**0.5


def isInteger(i):
    return i - int(i) == 0


N, D = inpl()
X = [inpl() for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        if isInteger(distance(X[i], X[j])):
            ans += 1

print(ans)

Solution (Python):
def main():
    n, d = map(int, input().split())
    xs = [[int(a) for a in input().split()] for _ in range(n)]

    cnt = 0
    for i, x in enumerate(xs):
        for j, y in enumerate(xs):
            if i >= j:
                continue
            d = sum([(xi - yi)**2 for xi, yi in zip(x, y)])
            d2 = int(d ** 0.5) - 1
            if d2 ** 2 == d or (d2 + 1) ** 2 == d or (d2 + 2) ** 2 == d:
                cnt += 1
    print(cnt)


main()

Solution (Python):

import math

def dist(x, y):
    s = 0
    for _x, _y in zip(x, y):
        s += (_x - _y) ** 2
    return math.sqrt(s)


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

cnt = 0
for i in range(n):
    for j in range(i+1, n):
        d = dist(xs[i], xs[j])
        if d == int(d):
            cnt += 1

print(cnt)

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

xs = []
for _ in range(n):
    xs.append(list(map(int, input().split())))
ans = 0
for i in range(n):
    xi = xs[i]
    for j in range(i+1, n):
        xj = xs[j]
        dist = sum([(xid - xjd)**2 for (xid, xjd) in zip(xi, xj)]) ** 0.5
        if dist.is_integer():
            ans += 1
print(ans)

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

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

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

def dist(l,m):
    sum = 0
    for i in range(D):
        sum += (X[l][i] - X[m][i])**2
    return math.sqrt(sum)

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        
        d = dist(i,j)
        if d.is_integer():
            ans += 1

print(ans)

Solution (Python):
import numpy as np
import copy


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


def main():
    N, D = map(int, input().split())
    Xs = []
    for _ in range(N):
        X = list(map(int, input().split()))
        Xs.append(X)
    Xs = np.array(Xs, dtype=np.int)
    assert Xs.shape == (N, D)

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            d = dist2(Xs[i, :], Xs[j, :])
            if d == int(np.sqrt(d))**2:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

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

result = 0

for i in range(n):
    for j in range(i+1, n):
        sum = 0
        for k in range(d):
            sum += (points[i][k] - points[j][k]) ** 2
        dist = sum ** 0.5
        if dist.is_integer():
            result += 1
print(result)

Solution (Python):
import math

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

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

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        total = 0
        for d in range(D):
            total += pow(points[i][d] - points[j][d], 2)
        if math.sqrt(total).is_integer():
            count += 1

print(count)

Solution (Python):
def getlist():
	return list(map(int, input().split()))

N, D = getlist()

XL = []

for i in range(N):
	X = getlist()
	XL.append(X)

ans = 0
for i in range(N):
	for j in range(i + 1, N):
		c = 0
		for k in range(D):
			c += (XL[i][k] - XL[j][k]) ** 2
		for k in range(150):
			if k ** 2 == c:
				ans += 1
				break

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())))
count=0

y=np.array(x)

for i in range(n):
    for j in range(n):
        if i<j:
            s=sum((y[i]-y[j])**2)
            
            if np.round(np.sqrt(s))**2==s:
                
                count+=1
print(count)

Solution (Python):
N,D = map(int,input().split())
nums = []
for i in range(N):
    nums.append(list(map(int,input().split())))
count = 0
for j in range(len(nums)):
    for k in range(len(nums)):
        ans = 0
        if j==k:
            continue
        for (x,y) in zip(nums[j],nums[k]):
            ans+=abs(x-y)**2
        ans = ans**(1/2)
        if int(ans)==ans:
            count+=1
print(count//2)

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

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

Solution (Python):
import math
n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
ans = 0
for y in range(n):
    for z in range(y+1, n):
        temp = 0
        for i in range(d):
            temp += (x[y][i] - x[z][i])**2
        if float(math.sqrt(temp)).is_integer():
            ans += 1
print(ans)

Solution (Python):
N,D = [int(i) for i in input().split()]
X = []
for n in range(N):
    X.append([int(i) for i in input().split()])
import numpy as np
X = np.array(X)
cnt = 0
for n in range(N):
    for nn in range(n+1,N):
        tmp = np.linalg.norm(X[n] - X[nn])
        if tmp == int(tmp):
            cnt+=1
print(cnt)

Solution (Python):
import math

def solve():
  N, D = map(int, input().split())
  X = [[int(i) for i in input().split()]for i in range(N)]
  cnt = 0

  for i in range(N):
    xi = X[i]
    for j in range(i + 1, N):
      xj = X[j]
      dist = math.sqrt(sum([(xi[d] - xj[d]) ** 2 for d in range(D)]))
      if dist.is_integer(): cnt += 1

  return cnt

print(solve())

Solution (Python):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)

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 - 1):
	for j in range(i + 1, N):
		dist = 0
		for k in range(D):
			dist += (X[i][k] - X[j][k]) ** 2
			
		dist **= 0.5
		if dist - int(dist) == 0:
			count += 1

print(count)

Solution (Python):
import math

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

cnt = 0
for i in range(N):
    for j in range(N):
        if i == j:
            break
        tmp_sum = 0
        for d in range(D):
            tmp_sum += (X[i][d] - X[j][d]) ** 2
        if math.sqrt(tmp_sum).is_integer():
            cnt += 1

print(cnt)

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

sqs = [i ** 2 for i in range(100000)]

ans = 0
for i in range(n):
    for j in range(i+1,n):
        d1 = dots[i]
        d2 = dots[j]
        temp = 0
        for dd1,dd2 in zip(d1,d2):
            temp += (dd1 - dd2) ** 2
        if temp in sqs:
            ans += 1



print(ans)

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)

X = np.array(X)
count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        x1, x2 = X[i], X[j]
        dist = np.sqrt(((x1 - x2) ** 2).sum())
        if dist - int(dist) < 1e-10:
            count += 1
print(count)

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

def dist2(x, y):
    return sum((a-b)**2 for (a, b) in zip(x, y))

def judge(d):
    m = int(d ** 0.5)
    return m*m == d

cnt = 0
for p in combinations(X, 2):
    x, y = p
    cnt += 1 if judge(dist2(x, y)) else 0

print(cnt)

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

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

counter = 0
for i in range(N):
    for j in range(i+1, N):
        s = 0
        for d in range(D):
            s += (point[i][d] - point[j][d]) ** 2
        
        dist = int(math.sqrt(s))
        
        if dist ** 2 == s:
            counter += 1
print(counter)

Solution (Python):
import math
def prob_b():
    n, d = [int(a) for a in input().split()]
    spot_list = list()
    for i in range(n):
        spot_list.append([int(a) for a in input().split()])
    counter = 0
    for i in range(n-1):
        spot_1 = spot_list[i]
        for j in range(n-1-i):
            spot_2 = spot_list[i+1+j]
            dist_sq = sum([(a-b) ** 2 for a, b in zip(spot_1, spot_2)])
            dist = math.sqrt(dist_sq)
            if dist_sq == int(dist) ** 2:
                counter += 1
    print(str(counter))


prob_b()

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

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

res = set()
for i in range(1000):
    res.add(i ** 2)

ans = 0
for i in range(N):
    a = 0
    for j in range(i + 1, N):
        tmp = 0
        for k in range(D):
            y = items[i][k]
            x = items[j][k]
            tmp += abs(y-x) ** 2
        a = tmp
        if a in res:
            ans += 1
print(ans)

Solution (Python):




def isSquared(n):
    for i in range(128):
        if i ** 2 > n:
            return False
        elif i ** 2 == n:
            return True
    return False


def squaredDist(x, y):
    s = 0
    for i, j in zip(x, y):
        s += (i - j)**2
    return s


def solve():
    N, D = list(map(int, input().split()))
    points = [list(map(int, input().split())) for _ in range(N)]
    count = 0
    for i in range(N):
        for j in range(i + 1, N):
            if isSquared(squaredDist(points[i], points[j])):
                count += 1
    return count


def main():
    print(solve())


if __name__ == "__main__":
    main()

Solution (Python):
N, D = map(int, input().split())
list_x = [list(map(int, input().split()))]
count = 0
for i in range(1, N):
    list_x.append(list(map(int, input().split())))
    for j in range(i):
        sum_square = 0
        for k in range(D):
            sum_square += (list_x[i][k] - list_x[j][k]) ** 2
        sum = sum_square ** (1/2)
        if(sum == int(sum)):
            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):
    for j in range(i + 1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d]) ** 2
        if int(dist ** 0.5) ** 2 == dist:
            ans += 1

print(ans)

Solution (Python):


import sys
from math import sqrt

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,D=MAP()
X=[]
for i in range(N):
    X.append(LIST())

cnt=0
for i in range(N):
    for j in range(i+1, N):
        sm=0
        A=X[i]
        B=X[j]
        for k in range(D):
            sm+=(A[k]-B[k])**2
        ans=sqrt(sm)
        if ans>=0 and ans.is_integer():
            cnt+=1
print(cnt)

Solution (Python):
from itertools import combinations
import math

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

for a, b in combinations(X, 2):
    dist = 0.0
    for d in range(D):
        dist += abs(a[d] - b[d])**2
    if math.sqrt(dist).is_integer():
        ans += 1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, D = LI()
    X = []
    for _ in range(N):
        X.append(LI())

    counter = 0
    import itertools
    for i, j in itertools.combinations(range(N),2):
        summation = 0
        for dim in range(D):
            summation += (X[i][dim] - X[j][dim]) **2

        import math
        if math.sqrt(summation).is_integer():
            counter += 1


    print(counter)





main()

Solution (Python):
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
a=0
from math import sqrt
for i in range(N-1):
    for j in range(i+1,N):
        d=0
        for x in range(D):
            d+=(X[i][x]-X[j][x])*(X[i][x]-X[j][x])
        if sqrt(d)%1==0:
            a+=1
print(a)

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

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

        distance = sqrt(distance)
        if int(distance) - distance == 0:
                cnt += 1
print(cnt)

Solution (Python):
import math

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

res = 0
for i in range(a):
    for j in range(i,a):
        if i == j :continue

        s = 0
        
        for k,t in zip(x[i],x[j]):
            p = (k-t)**2
            s+=p
        
        res += (math.sqrt(s))==int(math.sqrt(s))
print(res)

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

Solution (Python):
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy





def d(yy,zz):
    ans = 0
    for i in range(len(yy)):
        ans += (yy[i]-zz[i])**2
    return sqrt(ans)

def main():
    N,D = map(int, input().split())
    xx = []
    for _ in range(N):
        xx.append(list(map(int,input().split())))
    
    c = 0
    for i in range(N):
        for j in range(i+1,N):
            if d(xx[i], xx[j]).is_integer():
                c += 1
    
    print(c)

if __name__ == '__main__':
    main()

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

def do(a,b):
    the=math.sqrt(sum([(a[i] - b[i])**2 for i in range(D)]))
    return the.is_integer()

r=0
for i in range(N):
    for j in range(i+1, N):
        if do(X[i], X[j]):
            r+=1
print(r)

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

num = 0
for i in range(n):
    for j in range(i+1, n):
        xi = x[i]
        xj = x[j]
        dist = 0
        for k in range(d):
            dist += (xi[k] - xj[k])**2
        if np.sqrt(dist).is_integer():
            num += 1

print(num)

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

Solution (Python):
def check(a):
    flag=False
    for i in range(1,100000):
        if a==i*i:
            flag=True
    return flag
    

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

ans=0
for i in range(n):
    for j in range(i+1,n):
        D=0
        for di in range(d):
            D+=(X[i][di]-X[j][di])**2
        if check(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, Xi in enumerate(X):
    for j, Xj in enumerate(X):
        if i == j:
            continue
        dist = 0
        for y, z in zip(Xi, Xj):
            dist += (y - z) ** 2
        dist **= .5
        if dist == int(dist):
            ans += 1
print(ans // 2)

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

Solution (Python):
import math


def calcDist(A, B):
    sqSum = 0
    for i in range(len(A)):
        sqSum += (A[i] - B[i]) ** 2
    return math.sqrt(sqSum)


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

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


count_int = 0
for i in range(N):
    for j in range(i + 1, N):
        if (calcDist(X[i], X[j]).is_integer()):
            count_int += 1

print(count_int)

Solution (Python):
def euclid(A, B):
    c2 = 0
    for a,b in zip(A,B):
        c2 += (a-b)**2
    return c2**0.5

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):
        c = euclid(X[i], X[j])
        if c.is_integer():
            cnt += 1
print(cnt)

Solution (Python):
import math


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


if __name__ == '__main__':
    solve()

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):
from math import sqrt

def judge(a,b):
    s = 0
    for i in range(len(a)):
        s+=(a[i]-b[i])**2
    q = sqrt(s)
    return q.is_integer()


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

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

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans += judge(x[i],x[j])
    
print(ans)

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

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        sum = 0
        for a,b in zip(li[i],li[j]):
            sum += (a-b)**2
        sum = math.sqrt(sum)
        if sum.is_integer():
            cnt += 1
print(cnt)

Solution (Python):
import math

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

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

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


ans = 0
for i in range(n):
  for j in range(n-i-1):
    a = i
    b = i+j+1
    t = 0
    for k in range(d):
      t += math.pow(abs(x[a][k] - x[b][k]),2)

    t = math.sqrt(t)
    if(is_integer_num(t)):
      ans += 1

print(ans)

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

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

for i in range(n-1):
    for j in range(i+1,n):
        t = 0
        for x in range(d):
            t += (X[i][x]-X[j][x])**2
        t **= 0.5
        if is_integer_num(t):
            ans += 1
print(ans)

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


cnt = 0
for i in range(n):
    for j in range(i+1,n):
        dist = 0
        for k in range(d):
            dist += (l[i][k] - l[j][k])**2
        sqrt = int(dist**.5)
        if sqrt**2 == dist:
            cnt += 1
print(cnt)

Solution (Python):

"""
AtCoder A
"""

import sys, math, random
import numpy as np







 
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N, D = list(map(int,input().split()))
    X=[]
    for i in range(N):
        X.append(LI())
    out=0
    for i in range(N-1):
        for j in range(N-1-i):
            tmp=0
            for d in range(D):
                tmp+=(X[i][d]-X[N-1-j][d])**2
            tmp=math.sqrt(tmp)
            if tmp%1==0:
                out+=1
    print(out)
    
    
if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A

if __name__ == '__main__':
    N, D = InputToInt()

    X = np.empty((N, D))
    for i in range(N):
        X[i, :] = InputToInt()

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

    print(count)

Solution (Python):



def solve():
    n, d = map(int, input().split())
    xl = [[int(i) for i in input().split()] for _ in range(n)]
    ans = 0
    valid = set([i ** 2 for i in range(1, 200)])
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            s = 0
            for k in range(d):
                s += (xl[i][k] - xl[j][k]) ** 2
            if s in valid:
                ans += 1
    print(ans // 2)

if __name__=="__main__":
    solve()

Solution (Python):


import math

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

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

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 = math.sqrt(temp)    
        if temp == int(temp):
            count += 1
            
print(count)

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

for i in range(n):
	X = list(map(int,input().split()))
	x[i] = X
	
c = 0
for i in range(n):
	for j in range(i+1,n):
		if(i == j):continue
		
		dist = 0.0
		for k in range(d):
			dist += (x[i][k] - x[j][k]) ** 2.0
		dist = np.sqrt(dist)
		if(dist % 1.0 < 0.001):c+=1
print(c)

Solution (Python):
import numpy as np

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

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

Solution (Python):
import itertools
import math

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

ans = 0
for i in itertools.permutations(range(n), 2):
    if i[0] < i[1]:
        x1 = X[i[0]]
        x2 = X[i[1]]
        check = 0
        for j in range(d):
            check += abs(x2[j] - x1[j]) ** 2
        if math.sqrt(check).is_integer():
            ans += 1
print(ans)

Solution (Python):

import math

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

count = 0
for i in range(0, N):
    for j in range(i + 1, N):
        p1 = points[i]
        p2 = points[j]
        distance = 0
        for k in range(D):
            distance += math.pow(p1[k] - p2[k], 2)
        distance = math.sqrt(distance)
        if distance == int(distance):
            count += 1

print(count)

Solution (Python):
import sys
import math

n, d = [ int(x) for x in sys.stdin.readline().split() ]
r = []
for _ in range(n): r.append( [ int(x) for x in sys.stdin.readline().split() ] )

count = 0
for i in range(n):
    ri = r[i]
    for j in range(i+1,n):
        rj = r[j]
        
        d2 = 0
        for k in range(d):
            d2+= (ri[k]-rj[k])**2
        
        sq = math.sqrt(d2)
        if abs(int(sq)-sq)<1.e-10: count+=1

print( count )