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
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

import numpy as np  

def main():
    N, D = i2nn()
    X = ii2nnn(N)
    n = 0
    for i in range(N):
        for j in range(i+1, N):
            a = np.array(X[i])
            b = np.array(X[j])
            c = a - b
            d = np.linalg.norm(c)
            if int(d) == float(d):
                n += 1
    print(n)

main()

Solution (Python):
import math

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

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

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

print(ans)

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

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

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

answer=0
for i in range(0,N-1):
  x1=xlist[i]
  for j in range(i+1,N):
    x2=xlist[j]
    
    dist2=0
    for d in range(D):
      dist2+=(x2[d]-x1[d])**2
      
    dist=math.sqrt(dist2)
    if int(dist) == dist:
      answer += 1
      
print(answer)

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

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

def try_square_root_naive(n):
  m = int(n ** .5)
  return m if abs(m * m - n) < 1e-6 else None

ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    temp = 0
    for k in range(d):
      temp += (x[i][k] - x[j][k]) ** 2
    if try_square_root_naive(temp) is not None:
      ans += 1

print(ans)

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIR(n): return [LI() for _ in range(n)]

n,d = LI()
x = LIR(n)
ans = 0
for i in range(1,n):
    for j in range(i):
        sum = 0
        for k in range(d):
            sum +=(x[i][k] - x[j][k])**2
        if sum**(1/2) % 1 == 0:
            ans += 1
print(ans)

Solution (Python):
from math import sqrt
N,D = map(int, input().split())
L = []
for i in range(N):
    L.append([int(i) for i in input().split()])
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        a = L[i]
        b = L[j]
        e = sqrt(sum([abs(c-d)**2 for c, d in zip(a, b)]))
        if e == int(e):
            ans += 1
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

import math

n, d = getList()

zahyo = [getList() for i in range(n)]

ans = 0

for i in range(n):
    for j in range(i+1, n):
        tmp = 0
        va = zahyo[i]
        vb = zahyo[j]
        for dim in range(d):
            tmp += (vb[dim] - va[dim]) ** 2

        base = int(math.sqrt(tmp))
        if base ** 2 == tmp:
            ans += 1
            

print(ans)

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

def dis(A, B):
    s = 0
    for a, b in zip(A, B):
        s += (b - a) ** 2
    return s ** 0.5

res = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dist = dis(P[i], P[j])
        if dist - int(dist) < 10 ** -8:
            res += 1
print(res)

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

ans = 0
for i in range(N):
    Xi = Xss[i]
    for j in range(i+1, N):
        Xj = Xss[j]
        dist = 0
        for k in range(D):
            dist += (Xi[k]-Xj[k])**2
        if dist**0.5 == int(dist**0.5):
            ans += 1

print(ans)

Solution (Python):
N, D = map(int, raw_input().split())
X = [map(int, raw_input().split()) for _ in range(N)]

ans = 0
for i in range(N):
  for j in range(i):
    t = sum((X[i][k]-X[j][k])**2 for k in range(D))
    if int(t**0.5+0.01)**2==t:
      ans += 1
print ans

Solution (Python):
n, d = map(int, input().split())
x_array = [[int(x) for x in input().split()] for y in range(n)]
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        if i == j:
            continue
        tmp_i = x_array[i]
        tmp_j = x_array[j]
        tmp = sum([abs(x-y)**2 for x, y in zip(tmp_i, tmp_j)])
        if tmp ** 0.5 %1 == 0:
            cnt += 1
print(cnt)

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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        
        sq = np.sqrt(sum((X[j]-X[i])**2))
        
        if sq == int(sq):
            ans += 1
print(ans)

Solution (Python):
def dist(X1, X2):
    return sum((x1 - x2)**2 for x1, x2 in zip(X1, X2))

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

sq = set(i**2 for i in range(10**5))

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

print(ans)

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):
from itertools import combinations

def sqdist(X, Y):
    temp = 0
    for x, y in zip(X, Y):
        temp += (x - y)**2
    return temp

N, D = map(int, input().split())
points = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for x, y in combinations(points, 2):
    d2 = sqdist(x, y)
    if d2 == int(d2**0.5)**2: ans += 1
print(ans)

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

def dist(a, b):
    return math.sqrt(sum([(a[i] - b[i])**2 for i in range(d)]))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        y = x[i]
        z = x[j]
        w = dist(y, z)
        
        if w == int(w):
            ans += 1


print(ans)

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

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

ans = 0
for n1 in range(N - 1):
    for n2 in range(n1 + 1, N):
        v1 = vectors[n1]
        v2 = vectors[n2]
        dist2 = 0
        for e1, e2 in zip(v1, v2):
            dist2 += (e1 - e2) ** 2
        tmp = int(round(math.sqrt(dist2)))
        if tmp * tmp == dist2:
            ans += 1
print(ans)

Solution (Python):



import sys
from math import sqrt

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return list(map(proc, rl().split()))
    else:
        return rl().split()

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

def issq(d):
    c = int(sqrt(d))
    return c * c == d or (c+1) * (c+1) == d

def main():
    N, D = srl(int)
    A = []
    for _ in range(N):
        A.append(srl(int))
    c = 0
    for i in range(N):
        for j in range(i+1, N):
            if issq(dist(A[i], A[j])):
                c += 1
    print(c)

if __name__ == '__main__':
    main()

Solution (Python):
R = lambda: map(int, raw_input().split())

n, d = R()
a = [R() for _ in xrange(n)]
ans = 0
for i in xrange(n):
    for j in xrange(i):
        dis = sum((a[i][k] - a[j][k]) ** 2 for k in xrange(d))
        ans += int(dis ** 0.5 + 0.1) ** 2 == dis


print ans

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


def len(i,j):
    foo = 0
    for n in range(D):
        foo += (X[i][n]-X[j][n])**2
    return foo
ans = 0
for i in range(N):
    for j in range(i+1,N):
        len2 = len(i,j)
        if int(len2**0.5)**2 == len2:
            ans += 1
print(ans)

Solution (Python):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7





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


ans = 0
for i, j in itertools.combinations(range(N), r=2):
    a = X[i]
    b = X[j]
    r = 0
    for aa, ba in zip(a, b):
        r += (aa - ba) ** 2
    ans += int(math.sqrt(r)) ** 2 == r
print(ans)

Solution (Python):
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):
    for j in range(n):
        if i>j:
            dis=0
            for h in range(d):
                dis+=(x[j][h]-x[i][h])**2
            if (dis**0.5).is_integer():
                ans+=1
print(ans)

Solution (Python):
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
import math
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]) * (X[i][k] - X[j][k])
        tmp = math.sqrt(tmp)
        if float.is_integer(tmp):
            ans += 1
            
print(ans)

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

ans = 0
for i,a in enumerate(X[:-1]):
    for b in X[i+1:]:
        d = 0
        for x,y in zip(a,b):
            d += (x-y)**2
        if d**0.5 - int(d**0.5) < 10e-10:
            ans += 1
print(ans)

Solution (Python):
N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
def dist(a,b):
    return (sum([(a[i]-b[i])**2 for i in range(D)]))**0.5
cnt=0
for i in range(N):
    for j in range(i+1,N):
        if dist(X[i],X[j])==int(dist(X[i],X[j])):
            cnt+=1
print(cnt)

Solution (Python):
N,D=list(map(int,input().strip().split(' ')))
points=[]
for _ in range(N):
    P=list(map(int,input().strip().split(' ')))
    points+=[P]

count=0
for i in range(len(points)):
    for j in range(i+1,len(points)):
        temp=sum([(points[i][k]-points[j][k])**2 for k in range(D)])
        root=int(temp**0.5)
        if (root-1)**2==temp or root**2==temp or (root+1)**2==temp:
            count+=1
print(count)

Solution (Python):
from functools import reduce
import math

MIN = -10 ** 9
MAX = 10 ** 9


def main():
    N, D = [int(a) for a in input().split()]
    X = [
        [int(a) for a in input().split()]
        for _ in range(N)
    ]

    c = 0

    for i in range(N):
        for j in range(i+1,N):
            t = 0
            for k in range(D):
                aaa = X[i][k] - X[j][k]
                t += aaa * aaa
            t = math.sqrt(t)
            if t - int(t) == 0:
                c += 1
    print(c)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
from operator import sub


def calc(a, b):
    r = sum(c ** 2 for c in map(sub, a, b)) ** (1 / 2)
    return r % 1 == 0


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

cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if calc(x[i], x[j]):
            cnt += 1
print(cnt)

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

count = 0
for i, xi in enumerate(X):
    for j, xj in enumerate(X):
        if i >= j:
            continue
        t = 0
        for k in range(D):
            t += (xi[k] - xj[k]) ** 2
        if int(t ** 0.5) ** 2 == t:
            count += 1

print(count)

Solution (Python):

import sys
import math


def judge_dist(X, Y):
    total = 0
    for x, y in zip(X, Y):
        total += (x - y) ** 2
    return int(math.sqrt(total)) ** 2 == total


def solve(N: int, D: int, X: "List[List[int]]"):
    count = 0
    for i in range(1, N):
        for j in range(i):
            if judge_dist(X[i], X[j]):
                count += 1
    print(count)
    return



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) ]  
    solve(N, D, X)

if __name__ == '__main__':
    main()

Solution (Python):
import math
import itertools

N,D = (int(x) for x in input().split())

X_arr = []
for _ in range(N):
    X_arr.append([int(x) for x in input().split()])

ans = 0
for Y,Z in itertools.combinations(X_arr, 2):
    r2 = sum([(y-z)**2 for y,z in zip(Y,Z)])
    if round(math.sqrt(r2))**2 == r2:
        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):
    for j in range(i+1,N):
        r=0
        for k in range(D):
            r+=(l[i][k]-l[j][k])**2
        r=r**0.5
        if r==int(r):
            ans+=1
print(ans)

Solution (Python):
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
x,y = ips()
a = []
for i in range(x):
    a.append(iprow())
ans=0
for i in range(x):
    p = a[i]
    for k in range(i+1,x):
        q = a[k]
        s = 0
        for l in range(y):
            s+=pow(p[l]-q[l],2)
        if math.sqrt(s) == int(math.sqrt(s)):
            ans+=1
print(ans)

Solution (Python):
from math import sqrt


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


def main():
    n, d = map(int, raw_input().split())
    xx = []
    for _ in xrange(n):
        xx.append(map(int, raw_input().split()))
    count = 0
    for i in xrange(n - 1):
        for j in xrange(i + 1, n):
            d = dist2(xx[i], xx[j])
            if d == int(sqrt(d)) ** 2:
                count += 1
    print count


if __name__ == '__main__':
    main()

Solution (Python):
N,D = [int(x) for x in input().split()]
dots = [[int(x) for x in input().split()]for _ in range(N)]
cnt = 0
for ind,x in enumerate(dots):
    for i in range(ind+1,N):
        ans = 0
        for j in range(D):
            ans+=(x[j]-dots[i][j])**2
        ans **= 0.5
        if(int(ans)==ans):
            cnt+=1
print(cnt)

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

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

Solution (Python):
import sys

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

import math

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dist2 = sum([(Xi - Xj) ** 2 for Xi, Xj in zip(X[i], X[j])])
        dist = int(math.sqrt(dist2))
        if dist ** 2 == dist2:
            ans += 1

print(ans)

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

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

print(ans)

Solution (Python):











import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,D = MI()
    X = LLIN(N)
    ans = 0

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

    for i in range(N):
        for j in range(i+1,N):
            if i == j:
                continue
            dist =  distanse(X[i], X[j])
            if dist == int(dist):
                ans+=1
    print(ans)
if __name__ == '__main__':
    main()

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

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

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

cnt = 0
for p,q in combinations(points, 2):
    d = np.linalg.norm(p-q)
    if float(d) == int(d):
        cnt += 1

print(cnt)

Solution (Python):
from math import sqrt

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

ans = 0

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

Solution (Python):
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): 
	return list(map(int,input().split()))
def m(): 
	return map(int,input().split())
def onem(): 
	return int(input())
def s(x): 
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): 
	return " ".join(map(str,x))
def max2(x): 
	return max(map(max,x))

n,d = m()

a =[]
for i in range(n):
	a.append(l())
co = 0
su = 0
for i in range(n-1):
	for j in range(i+1,n):
		su = 0
		for k in range(d):
			su += (a[i][k] - a[j][k])**2
		if math.sqrt(su) == int(math.sqrt(su)):
			co += 1
print(co)

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

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

counter = 0
for i in range(n):
    y = x[i]
    for j in range(n):
        z = x[j]
        if j != i:
            dist = np.sqrt(np.sum((y - z) ** 2))
            if dist == int(dist):
                counter += 1

print(int(counter / 2))

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

Solution (Python):

import sys
from operator import itemgetter

from fractions import gcd

from math import ceil, floor, sqrt

from copy import deepcopy

from itertools import accumulate






from collections import Counter
import math
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(x): print("debug: ", x, file=sys.stderr)








def solve(N: int, D: int, X: "List[List[int]]"):
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            tmp = sum([(X[i][t] - X[j][t]) ** 2 for t in range(D)])
            for _i in range(int(sqrt(tmp)) - 2, int(sqrt(tmp)) + 2):
                if _i * _i == tmp:
                    ans += 1
                    break
    print(ans)


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


def main():
    tokens = iterate_tokens()
    N = int(next(tokens))  
    D = int(next(tokens))  
    X = [[int(next(tokens)) for _ in range(D)]
         for _ in range(N)]  
    solve(N, D, X)


if __name__ == '__main__':
    main()

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

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

    pairs = 0

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

            if int(dist**0.5) == dist**0.5:
                pairs += 1

    print(pairs)


main()

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

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

ANS=0
import math

for i in range(N-1):
    for j in range(i+1,N):
        DIS=math.sqrt(sum([(X[i][k]-X[j][k])**2 for k in range(D)]))

        if DIS==int(DIS):
            ANS+=1

print(ANS)

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

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        pi, pj = P[i], P[j]
        tmp = 0
        for d in range(D):
            tmp += (pi[d] - pj[d]) ** 2
        if (tmp ** 0.5).is_integer():
            ans += 1

print(ans)

Solution (Python):
def solve(N, D, Xs):
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 0
            for d in range(D):
                k += pow(Xs[i][d] - Xs[j][d], 2)
            d = pow(k, 0.5)
            if d == int(d):
                ans += 1
    return ans

if __name__ == "__main__":
    N, D = tuple(map(int, input().split(" ")))
    Xs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, D, Xs))

Solution (Python):

import sys
import math
INF = float("inf")

tol = 1e-6


def solve(N: int, D: int, X: "List[List[int]]"):

    counter = 0
    for i in range(N):
        for j in range(i+1, N):
            dist = 0
            for a, b in zip(X[i], X[j]):
                dist += (a-b)**2
            dist = math.sqrt(dist)
            if abs(dist - round(dist)) < tol:
                counter += 1
    print(counter)

    return


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)]  
    solve(N, D, X)


if __name__ == '__main__':
    main()

Solution (Python):
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
ans = 0
def k(a,b):
    dist = 0
    for i in range(d):
        dist +=(a[i]-b[i])**2
    dist = dist**(1/2)
    while dist > 0:
        dist -= 1
        if dist == 0:
            return True
    return False
for i in range(n):
    for j in range(i+1,n):
        if k(x[i],x[j]):
            ans += 1

print(ans)

Solution (Python):
from math import sqrt
N,D = map(int,input().split())
X = [list(map(int,input().split())) for i in range(N)]
ans = 0
for a in range(1,N):
    for b in range(a):
        jijou = sum([(y-z)**2 for y,z in zip(X[a],X[b])])
        if int(sqrt(jijou))**2 == jijou:
            ans+=1
print(ans)

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

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

Solution (Python):


from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, D = map(int, raw_input().split())
X = []
for i in range(N):
    p = map(int, raw_input().split())
    X += [p]

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        S = sum((X[i][k] - X[j][k]) * (X[i][k] - X[j][k]) for k in range(D))
        for q in range(1000):
            if q * q >= S:
                ans += (q * q == S)
                break
print ans

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, D = nl()

points = []
for i in range(N):
    Xs = nl()
    points.append(Xs)

import math
count  = 0
for i in range(N-1):
    for j in range(i+1, N):
        t = 0
        for k in range(D):
            diff = points[i][k] - points[j][k]
            t += diff * diff
        st = int(math.sqrt(t))
        if st * st == t:
            count +=1

print(count)

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

num = 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 int(tmp ** 0.5) ** 2 == tmp:
            num += 1

print(num)

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


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


def B():
    n,d = LI()
    x = LIR(n)
    f = defaultdict(lambda : 0)
    for i in range(1000000):
        f[i*i] = 1
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            s = 0
            for k in range(d):
                s += (x[i][k]-x[j][k])**2
            if f[s]:
                ans += 1
    print(ans)
    return


def C():
    n = I()

    return


def D():
    n = I()

    return


def E():
    n = I()

    return


def F():
    n = I()

    return



if __name__ == "__main__":
    B()

Solution (Python):


import sys

class BGoodDistance:
    def dist(self, u, v):
        return (sum((u[i] - v[i]) ** 2 for i in range(len(u)))) ** .5
    def solve(self):
        n, d = [int(_) for _ in input().split()]
        p = []
        for _ in range(n):
            p.append([int(_) for _ in input().split()])
        
        ans = 0
        for i in range(n):
            for j in range(i + 1, n):
                d = self.dist(p[i], p[j])
                if abs(d - int(d)) < 1e-9:
                    ans += 1
        
        print(ans)

solver = BGoodDistance()
input = sys.stdin.readline

solver.solve()