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 sys

input = sys.stdin.readline

def main():
    ans = 0
    N, D = map(int, input().split())
    p = []
    for i in range(N):
        p.append(list(map(int, input().split())))
    for i in range(N):
        for j in range(i, N):
            temp = 0
            for k in range(D):
                temp += (p[i][k]-p[j][k])**2
            if temp != 0 and float.is_integer(temp**0.5):
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import math
def good_distance(n, d, xli):

    ans = 0

    for i in range(n):
        for q in range(i+1, n):
            count = 0
            for w in range(d):
                count += (xli[i][w]-xli[q][w])**2

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

    return ans

def main():
    n, d = map(int, input().split())
    xli = [list(map(int, input().split()))for i in range(n)]
    print(good_distance(n, d, xli))

if __name__ == '__main__':
    main()

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

for i in range(N):
    for j in range(i+1, N):
        distance = 0
        for c1,c2 in zip(points[i], points[j]):
            distance += (c1 - c2)**2

        if (distance**0.5).is_integer():
            ans += 1

print(ans)

Solution (Python):
import math
N,D=map(int,input().split())
ans=0
pos=[]
for i in range(N): pos.append(list(map(int,input().split())))
for i in range(N):
    y=pos[i]
    for j in range(N):
        z=pos[j]
        if i==j: pass
        else:
            distance=0.0
            for k in range(D): distance+=(y[k]-z[k])**2
            if math.sqrt(distance).is_integer(): ans+=1
print(ans//2)

Solution (Python):
n,d=map(int,input().split())
a=[[0]*d for ii in range(n)]
for ii in range(n):
  a[ii][:]=map(int,input().split())
r=0
for ii in range(n):
  for jj in range(n):
    if ii!=jj:
      d2=0
      for kk in range(d):
        d2+=(a[ii][kk]-a[jj][kk])**2
      d2=d2**0.5
      
      if int(d2)==d2:
        r+=1
print(r//2)

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    ret = 0
    for x, y in itertools.combinations(X, 2):
        i = 0
        for t in zip(x, y):
            i += abs(t[0] - t[1]) ** 2
        if float.is_integer(math.sqrt(i)):
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
n,d=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(n)]
f=0
for i in range(n-1):
  for j in range(i+1,n):
    l=(sum((X[i][a]-X[j][a])**2 for a in range(d)))**(1/2)
    if int(l)==l:
        f+=1
print(f)

Solution (Python):
n,d=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(n)]
f=0
for i in range(n-1):
  for j in range(i+1,n):
    l=0
    for a in range(d):
      l+=(X[i][a]-X[j][a])**2
    if int(l**(1/2))==l**(1/2):
        f+=1
print(f)

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

f=0
for i in range(n-1):
  for j in range(i+1,n):
    l=0
    for a in range(d):
      l+=(X[i][a]-X[j][a])**2
    if int(l**(1/2))==l**(1/2):
        f+=1
print(f)

Solution (Python):
import math
n, d = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(n)]
count = 0
def dist(X0, X1):
    l = 0
    for x0, x1 in zip(X0, X1):
        l += (x0 - x1) ** 2
    return math.sqrt(l)
for i in range(n - 1):
    for j in range(i + 1, n):
        l = dist(X[i], X[j])
        if l.is_integer():
            count += 1
print(count)

Solution (Python):
import math
n, d = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(n)]
count = 0
def dist(X0, X1):
    l = 0
    for x0, x1 in zip(X0, X1):
        l += (x0 - x1) ** 2
    return math.sqrt(l)
for i in range(n - 1):
    for j in range(i + 1, n):
        l = dist(X[i], X[j])
        if l.is_integer():
            count += 1
print(count)

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

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

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

Solution (Python):
import itertools
import math
import fractions
import functools
import copy

n,d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
l = list(range(0,n))
pair = list(itertools.combinations(l, 2))
count = 0
for i in range(len(pair)):
    distance = 0
    for j in range(d):
        distance += (x[pair[i][0]][j] - x[pair[i][1]][j])**2
    if (math.sqrt(distance)).is_integer():
        count += 1
print(count)

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

x=[[] for _ in range(n)]

for j in range(n):
    x[j] = input().split()
cnt=0
for i in range(n):
    for k in range(i+1,n):
        wa=0
        for j in range(d):
            wa +=(int(x[k][j])-int(x[i][j]))**2
        a=math.sqrt(wa)
        if a.is_integer()==True:
            cnt+=1
print(cnt)

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

x=[[] for _ in range(n)]

for j in range(n):
    x[j] = input().split()
cnt=0
for i in range(n):
    for k in range(i+1,n):
        wa=0
        for j in range(d):
            wa +=(int(x[k][j])-int(x[i][j]))**2
        if math.sqrt(wa)%2==0 or math.sqrt(wa)%2==1:
            cnt+=1
print(cnt)

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


ans = 0
for u,v in itertools.combinations(x,2):
    d = ((u-v) * (u-v)).sum()
    if int(d**0.5) == d ** 0.5:
        ans += 1
print(ans)

Solution (Python):
import numpy as np
n,d = tuple(map(int,input().split()))

x = [np.array(tuple(map(int,input().split()))) for _ in [0]*n]

ans = 0
for i in range(n):
  for j in range(i+1,n):
    if np.linalg.norm(x[i]-x[j]).is_integer():
      ans+=1
print(ans)

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

Solution (Python):
import numpy as np
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
count=0
for i in range(n-1):
    for j in range(i+1,n):
        a=np.array(x[i])
        b=np.array(x[j])
        ab=sum(np.power((a-b),2))**0.5
        if ab%1==0:
            count+=1
print(count)

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

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

len_x = 0
youso = 0
count = 0
for i in range(1, n[0]+1):
  for j in range(i+1, n[0]+1):
    youso = 0
    for k in range(0, n[1]):
      t = x[i-1][k]+(-1)*x[j-1][k]
      youso += t*t
    youso = math.sqrt(youso)
    if str(youso)[-1] == '0':
      count += 1
print(count)

Solution (Python):
from math import floor
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):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        if floor(dist**0.5)**2 == dist:
            cnt += 1
print(cnt)

Solution (Python):
n,d=map(int,input().split())
l=[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):
    sum=0
    for dd in range(d):
      sum+=(l[i][dd]-l[j][dd])**2
    if sum**0.5==int(sum**0.5):
      cnt+=1
print(cnt)

Solution (Python):
import sys
import math
import bisect

def solve(A):
    n = len(A)
    m = len(A[0])
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            val = 0
            for k in range(m):
                val += (A[i][k] - A[j][k]) ** 2
            dval = math.sqrt(val)
            if dval == math.floor(dval):
                ans += 1
    return ans

def main():
    n, m = map(int, input().split())
    A = []
    for i in range(n):
        A.append(list(map(int, input().split())))
    print(solve(A))

if __name__ == "__main__":
    main()

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

Solution (Python):

"""
Created on Tue May 12 14:10:07 2020

@author: shinba
"""
import itertools

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

X = []

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

ans = 0

for i in itertools.combinations(range(n), 2):
    dist = 0
    for j in range(d):
        dist += (X[i[0]][j]-X[i[1]][j])**2
    else:
        if dist**(0.5) == int(dist**(0.5)):
            ans += 1

print(ans)

Solution (Python):
def LI(): return list(map(int,input().split()))
N,D = LI()
X = [LI() 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[j][k]-X[i][k])**2
        if temp**0.5%1==0:
            _ans += 1
print(_ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)




N,D = inputIL()
X  = inputILL(N)

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

Solution (Python):
from collections import deque
from itertools import accumulate
import sys
sys.setrecursionlimit(10**6)

mo=10**9+7

n,d=map(int,input().split())
y=[]
for i in range(n):
    x=[int(i) for i in input().split()]
    y.append(x)
    
def dist(x,y):
    a=0
    rt=False
    for i in range(len(x)):
        a+=(x[i]-y[i])**2
    if a==int(a**0.5)**2:
        rt=True
    return rt
    
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=1 if dist(y[i],y[j]) else 0


print(ans)

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

ll = []
for i in range(N):
    l = [int(i) for i in input().rstrip().split()]
    ll.append(l)

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

        la = ll[i]
        lb = ll[j]
        x = 0
        for k in range(D):
            v = la[k] - lb[k]
            x = x + v ** 2


        if math.sqrt(x).is_integer():
            num = num + 1

print(num)

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

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

from collections import Counter
def resolve():
    N,D=pin()
    X=[lispin()for i in range(N)]
    cnt=0
    for i in range(N-1):
        for j in range(i+1,N):
            temp=0
            
            for d in range(D):
                temp+=(X[i][d]-X[j][d])**2
            
            for k in range(100000):
                if k**2==temp:cnt+=1
                if k**2>temp:break
    print(cnt)

resolve()

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

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

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

Solution (Python):
from math import sqrt

n,d = map(int,input().split())
li  = [list(map(int,input().split())) for i in range(n)]
tmp = 0
ans = 0

for i in range(n):
  for j in range (i+1,n):
    for k in range(d):
      tmp += pow(abs(li[i][k]-li[j][k]),2)
    if sqrt(tmp)%1==0:
      ans += 1
    tmp =  0

print(ans)

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

import numpy as np
for i in range(n-1):
    for j in range(i+1,n):
        a = np.array(x[i])
        b = np.array(x[j])
        ab = sum(np.power((a-b),2))**0.5
        if ab%1 == 0:
            count += 1
print(count)

Solution (Python):


import numpy as np

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

Solution (Python):
import numpy as np
import math

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


def is_square(num):
    root = int(math.sqrt(num))
    return root ** 2 == num

counts = 0
for i in range(n):
    for j in range(i + 1, n):
        pi = points[i]
        pj = points[j]
        d2 = np.sum((pi - pj) ** 2)
        if is_square(d2):
            counts += 1

print(counts)

Solution (Python):
import numpy as np
n,d = tuple(map(int,input().split()))

x = [np.array(tuple(map(int,input().split()))) for _ in [0]*n]

ans = 0
for i in range(n):
  for j in range(i+1,n):
    if np.linalg.norm(x[i]-x[j]).is_integer():
      ans+=1
print(ans)

Solution (Python):
n,d=map(int,input().split())
xs=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i,y in enumerate(xs):
    for z in xs[i+1:]:
        s=sum([(a-b)**2 for a,b in zip(y,z)])**(1/2)
        if s==s//1:
            ans+=1
print(ans)

Solution (Python):
import itertools

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

l = [i for i in range(N)]
C = list(itertools.combinations(l, 2))

a = 0
ans = 0
for c in C:
    a = 0
    for i in range(D):
        a += (X[c[0]][i] - X[c[1]][i]) ** 2
    a **= 0.5
    if a % 1 == 0:
        ans += 1
print(ans)

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

Solution (Python):
import math
import functools
N, D = list(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(N):
        if i >= j:
            continue
        L = [(X[i][d]-X[j][d])**2 for d in range(D)]
        distance = math.sqrt(functools.reduce(lambda x,y:x+y,L))
        if (distance % 1) == 0:
            ans += 1
print(ans)

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

from itertools import combinations
from fractions import math

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

c = list(combinations(points,2))

cnt = 0

for combi in c:
    distance = 0

    for j in range(D):
        X=combi[0][0]
        Y=combi[1][0]
        distance += ( X[j] - Y[j])**2

    distance = math.sqrt(distance)

    if distance.is_integer():
        cnt+=1

print(cnt)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce


import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n, d = Is()
X = LIR(n)
ans = 0
for i, j in combinations(range(n), 2):
    tmp = 0
    for l in range(d):
        tmp += (X[i][l]-X[j][l])**2
    if sqrt(tmp) % int(sqrt(tmp)) == 0:
        ans += 1
print(ans)

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

x = []

ans = 0

for i in range(n):
    x.append(list(map(int,input().split())))
    
def dis(a,b):
    t = 0
    for i in range(len(a)):
        t += (a[i]-b[i])**2
        
    if int(t**0.5)==t**0.5:
        return 1
    else:
        return 0
        
for i in range(len(x)):
    for s in range(i+1,len(x)):
        ans += dis(x[i],x[s])
        
print(ans)

Solution (Python):
import itertools
cnt = 0
N, D= (int(x) for x in input().split())
X = [[] * D for i in range(N)]
def distance(A,B):
  s = 0
  for i in range(len(A)):
    s = s + (A[i] -B[i])**2
  return s**(1/2)
for i in range(N):
  X[i] = [int(x) for x in input().split()]
c = list(itertools.combinations(X, 2))
for i in c:
  if distance(i[0],i[1]).is_integer():
    cnt += 1
print(cnt)

Solution (Python):
import numpy as np
from itertools import combinations

N, D = map(int, input().split())
X = np.zeros([N, D], dtype=int)
ans = []

def judge_int(array):
    return np.sqrt((array**2).sum()).is_integer()

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

for i, j in list(combinations(range(0, N), 2)):
    ans.append(judge_int(X[i] - X[j]))

print(sum(ans))

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

Solution (Python):
import itertools


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

    for i in itertools.combinations(range(N), 2):
        save = 0
        for d in range(D):
            save += (X[i[0]][d]-X[i[1]][d])**2
        if (save**0.5) % 1 == 0:
            ans += 1
    print(ans)


solve()

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

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

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        tmp = 0

        for k in range(d):
            tmp = tmp + (T[i][k] - T[j][k]) ** 2

        tmp = tmp ** 0.5

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

print(ans)

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







cnt = 0
for i in range(n):
    for j in range(i+1,n,1):
        res = 0
        for k in range(d):
            res += abs(dli[i][k] - dli[j][k])**2
        if math.sqrt(res).is_integer():
            cnt+=1

print(cnt)

Solution (Python):

sq = set()

i, ii= 0,0
while ii <= 160000:
    sq.add(ii)
    i+=1
    ii = i*i

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

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

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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if d2(X[i],X[j]) in sq:
            ans += 1
    
print(ans)

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

import math
count = 0
for a in range(N-1):
    for b in range(a+1, N):
        dist = 0
        for i, j in zip(X[a], X[b]):
            dist += (i - j) ** 2       
        if dist != 0 and math.sqrt(dist).is_integer() == True:
            count += 1
print(count)

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

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

for i in range(N):
  for j in range(i + 1, N):
    L = []
    for k in range(D):
      L.append((X[i][k] - X[j][k]) ** 2)
    y = sum(L)
    for l in range(y + 1):
      if l ** 2 == y:
        
        count += 1

print(count)

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

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

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

Solution (Python):
def calc_dist(y, z):
  l = []
  for each_y, each_z in zip(y, z):
    l.append((each_y - each_z)**2)
  return sum(l) ** 0.5

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

ans = 0
for i in range(n):
  for j in range(i+1, n):
    tmp = calc_dist(points[i], points[j])
    if tmp == int(tmp):
      ans += 1
      
print(ans)

Solution (Python):
import math


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


def distance(y, z):
    dis = 0
    for i in range(len(y)):
        dis += (y[i] - z[i]) ** 2
    return math.sqrt(dis)


if __name__ == "__main__":
    main()

Solution (Python):
import math
n,d=map(int,input().split())
a=[]
x=[]
count=0
c=0
ans=0
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(d):
        x.append(a[j])
for i in range(1,n):
    for j in range(i+1,n+1):
        for k in range(d):
            y=x[(i-1)*d+k]
            z=x[(j-1)*d+k]
            c=y-z
            count+=c*c
        e=math.sqrt(count)
        if e%1==0:
            ans+=1
        count=0
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline









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):
        total = 0
        for k in range(D):
            total += (X[i][k] - X[j][k])**2
        if int(total**.5)**2 == total:
            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 j in range(0,N):
  for i in range(j+1,N):
    sum_ = 0
    for d in range(D):
      sum_+=(X[i][d]-X[j][d])**2
    if (sum_**0.5)%1==0: count_+=1
print(count_)

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

count_ = 0
for j in range(0,N):
  for i in range(0,N):
    sum_ = 0
    for d in range(D):
      sum_+=(X[i][d]-X[j][d])**2
    if (sum_**0.5)%1==0: count_+=1
print(int((count_-N)/2))

Solution (Python):
n,d = map(int,input().split())
x = [[0]]*n
for i in range(n):
  x[i] = list(map(int,input().split()))
pairs = 0
sqset = set()
for i in range(1,127):
  sqset.add(i**2)
for i in range(n-1):
  for j in range(1,n-i):
    dstsq = 0
    for k in range(d):
      dstsq += (x[i][k]-x[i+j][k])**2
    if dstsq in sqset:
      pairs += 1
print(pairs)

Solution (Python):


N, D = map(int, input().split())
X = [[int(x) for x in input().split()] for _ 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 += (abs(X[i][k] - X[j][k])) ** 2
        if (dist ** (1 / 2)).is_integer():
            cnt += 1

print(cnt)

Solution (Python):
n,d=map(int,input().split())
x=[]
for i in range(n):
    X=list(map(int,input().split()))
    x.append(X)
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        t=0
        for l in range(d):
            t+=(x[i][l]-x[j][l])**2
        if t==int(t**(1/2))**2:
            ans+=1
print(ans)

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

Z = []
for j in range(N):
  for i in range(j):
    Y = []
    for n in range(D):
      Y.append((X[i][n] - X[j][n])**2)
    Z.append(Y)

a = 0    
for l in range(N*(N-1)//2):    
  if (sum(Z[l]))**0.5 == int((sum(Z[l]))**0.5):
    a = a+1

print(a)

Solution (Python):
import sys, heapq, bisect, math, fractions
from collections import deque


def ok(i, j, D):
    d = 0
    for k in range(D):
        d += (X[i][k] - X[j][k]) ** 2
    
    dd = int(math.sqrt(d))
    if dd ** 2 == d:
        return True
    else:
        return False


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

res = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if ok(i, j, D):
            res += 1

print(res)

Solution (Python):
import numpy as np
import math
ans=0
d=0
n,D = [int(i) for i in input().split()]
graph=np.zeros(n*D).reshape((n,D))
for i in range(n):
    graph[i:i+1,:] = np.array([int(i) for i in input().split()])
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(D):
            d += abs(graph[i,k] - graph[j,k])**2
        if(math.sqrt(d).is_integer()):
            ans+=1
        d=0
print(ans)

Solution (Python):
import math

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

for i in range(N):
    for j in range(i+1, N):
        length = 0
        for x_i, x_j in zip(X[i], X[j]):
            length += (x_i-x_j)**2
        length = math.sqrt(length)
        if length == int(length):
            cnt += 1

print(cnt)

Solution (Python):
import itertools
import math

N, D = input().split()
cnt = 0
X = [list(map(int, input().split())) for _ in range(int(N))]
N = [i for i in range(0, int(N))]
N_list = list(itertools.combinations(N, 2))

for n in N_list:
    length = 0
    for x_1, x_2 in zip(X[n[0]], X[n[1]]):
        length += (x_1-x_2)**2
    length = math.sqrt(length)
    if length == int(length):
        cnt += 1
        
print(cnt)

Solution (Python):
import numpy as np
N, M = map(int, input().split())
X = np.array([list(map(int, input().split())) for i in range(N)])
cnt = 0
for i in range(N):
  for j in range(N):
    D = np.linalg.norm(X[i]-X[j], ord=2)
    if i < j and  D%1 == 0:
      cnt += 1
print(cnt)