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

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

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

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

print(ans)

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

Solution (Python):
def main():

    """ convenient functions
    
    
    
    
    
    """

    """convenient decorator
    
    
        
        
        
        
        
        
        
        
        
        
    """
    
    
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product 
    
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  
        b, e = 2, 0  
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict 
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
    from copy import deepcopy, copy 
    import operator
    from operator import itemgetter
    
    
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd 
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    
    
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) 
    def modinv(a, p = MOD):
        
        
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        
        
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    """ initialize variables and set inputs
    
        
        
    
        
        
        
        
        
    
        
        
        
        
    
        
        
    """

    
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    
    
    
    
    
    
    
    """

    if __name__ != '__main__':
        
        sys.stdin = open('sample.txt')

    
    
    N, D = R()
    X = [R() for _ in range(N)]
    ans = 0
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            else:
                tmp = 0
                for k in range(D):
                    tmp += (X[i][k] - X[j][k]) ** 2
                if sqrt(tmp) == floor(sqrt(tmp)):
                    ans += 1
    print(ans//2)
    
    
    

    """memo: how to use defaultdict of list
    
    Dic = defaultdict(list)
    
    Dic[x].append(y)
    
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, D = map(int, input().split())
    X = []
    for _ in range(N):
        A = tuple(map(int, input().split()))
        X.append(A)

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

            t = int(s**(0.5))
            if s == t**2:
                ans += 1

    return ans


if __name__ == '__main__':
    print(main())

Solution (Python):
import numpy as np

N,D  = list(map(lambda x: int(x),input().split()))
Xs=[]
for i in range(N):
    X = list(map(lambda x: int(x),input().split()))
    Xs.append(X)
count=0
for i in range(N):
    for j in range(i+1,N):
        s = np.sum((np.array(Xs[i])-np.array(Xs[j]))**2)**0.5
        
        if s==int(s):
            count += 1

print(count)

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(N):
        if i >= j:
            pass
        else:
            distance = 0
            for x in range(D):
                distance += (X[i][x] - X[j][x]) ** 2
            distance = distance ** 0.5
            if int(distance) == distance:
                ans += 1

print(ans)

Solution (Python):
import numpy as np
N,D = map(int,input().split(' '))
X = np.array([list(map(int,input().split(' '))) for i in [0]*N])

M = int(np.sqrt(20000))
squares = [i**2 for i in range(0,M)]
ans = 0
for i in range(N):
	for j in range(i+1,N):
		a = np.sum(np.square(X[i]-X[j]))
		if a in squares:
			ans += 1

print(ans)

Solution (Python):
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ret = 0
for i in range(n):
    for j in range(i + 1, n):
        distance = sum((x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) for k in range(d))
        sq = int(math.sqrt(distance))
        if distance == sq * sq:
            ret += 1
print(ret)

Solution (Python):
import itertools
n,d=map(int,input().split())
ans=0
def dist(A,B):
  ret=0
  for i in range(d):
    ret+=(A[i]-B[i])**2
  return int(ret**0.5)**2==ret
XX=[]
for i in range(n):
  X=[int(i) for i in input().split()]
  XX.append(X)

for c1,c2 in itertools.combinations(range(n),2):
  A,B=XX[c1],XX[c2]
  if dist(A,B):
    ans+=1
print(ans)

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

Solution (Python):
import math

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

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

def dist(x,y):
    d2 = 0
    for i in range(D):
        d2 += (x[i]-y[i])**2
    d = d2**0.5
    return d

for i in range(N):
    for j in range(i,N):
        if i==j:
            continue
        else:
            d = dist(listX[i],listX[j])
            if d == int(d):
                output += 1

print(output)

Solution (Python):
from math import sqrt

def distance(A, B):
    s = sum((a-b)**2 for a, b in zip(A, B))
    s = sqrt(s)
    return s

def solve(N, D, X):
    c = 0
    for i in range(N):
        for j in range(i+1, N):
            d = distance(X[i], X[j])
            if float(int(d)) == d:
                c+=1
    return c

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

    print(solve(N, D, X))

main()

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

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

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

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


def distance(A, B):
    d = 0
    for i in range(D):
        d += (A[i] - B[i])**2
    return math.sqrt(d)

ans = 0

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

print(ans)

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

Solution (Python):
n,d = map(int,input().split())
x = []
for _ in range(n):
  xi = list(map(int,input().split()))
  x.append(xi)
def dis(a,b,d):
  s = 0
  for i in range(d):
    s += (a[i] - b[i])**2
  return s
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    e = dis(x[i],x[j],d)
    ed = e**(1/2)
    if (ed - int(ed)) == 0:
      count += 1
print(count)

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

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

arr=[]
for i in range(N):
    for j in range(N):
        if i < j:
            dist_l=[]
            for d in range(D):
                dist_l.append((X[i][d]-X[j][d])**2)
            arr.append(sum(dist_l)**(1/2))

print(sum(list(map(lambda x: x%1==0,arr))))

Solution (Python):
from math import sqrt

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

count = 0

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

print(count)

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

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

Solution (Python):
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]





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


def dist(l1, l2):
    res = 0
    for i in range(1, D+1):
        tmp = (l1[i] - l2[i])
        res += tmp * tmp
    return res



ans = 0
for i in range(1, N+1):
    for j in range(i+1, N+1):
        tmp = dist(X[i], X[j])
        k = 0
        while k * k <= tmp:
            if k * k == tmp:
                ans += 1
            k += 1
print(ans)

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


def dist2(pos1, pos2):
    return sum([(p - q)**2 for p, q in zip(pos1, pos2)])


ans = 0
for i in range(N):
    for j in range(i + 1, N):
        dist = dist2(Positions[i], Positions[j])
        if int(dist**0.5)**2 == dist:
            ans += 1
print(ans)

Solution (Python):
from math import sqrt
n, d = map(int, input().split())
X = []
ans = 0
for _ in range(n):
    x = [int(i) for i in input().split()]
    X.append(x)

for i in range(n):
    for j in range(i+1,n):
        Y = X[i]
        Z = X[j]
        d = sqrt(sum([(y-z)**2 for y,z in zip(Y, Z)]))
        if divmod(d,1)[-1] == 0:
            ans += 1
            
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())))
    
ans = 0
for idx, point in enumerate(x):
    for idx2 in range(idx+1, len(x), 1):
    
        norm =  np.linalg.norm(np.asarray(point) - np.asarray(x[idx2]))
        if norm % 1 == 0:
            ans += 1
print(ans)

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

Solution (Python):
N,D = map(int,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(N):
    d = 0
    if i != j:
      for k in range(D):
        d += (X[i][k]-X[j][k])**2
      d = d ** (1/2)
      if int(d) == d:
        ans += 1
print(int(ans/2))

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


def is_valid(k):
    for i in range(200):
        m = i ** 2
        if k == m:
            return True
        elif k < m:
            return False
    
    return False


ans = 0
for i in range(n):
    for j in range(i + 1, n):
        s = 0
        for e in range(d):
            s += (xs[i][e] - xs[j][e]) ** 2
        if is_valid(s):
            ans += 1

print(ans)

Solution (Python):
import math
a,b = list(map(int, input().split()))

xs = []
for i in range(a):
    x = list(map(int, input().split()))
    xs.append(x)
ans = 0
for i in range(a):
    for j in range(a):
        if(i>=j):
            continue
        dist = 0
        for k in range(b):
            dist+= (xs[i][k]-xs[j][k])**2
        dist = math.sqrt(dist)
        if(dist%1==0):
            ans +=1
            
print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
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 [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 _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

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

result = 0
for i in range(N-1):
    for j in range(i + 1, N):
        tmp = 0
        for d in range(D):
            tmp += (X[i][d] - X[j][d])**2
        tmp = math.sqrt(tmp)
        if tmp % 1 == 0:
            result += 1
print(result)

Solution (Python):
from math import *

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        d2 = 0
        for k in range(D):
            d2 += (X[i][k] - X[j][k])**2
        if sqrt(d2)*10%10 == 0:
            ans += 1

print(ans)

Solution (Python):
n,d=map(int, input().split())
x=[list(map(int, input().split())) for i in range(n)]
count=0
for i in range(n):
    for j in range(n):
        if i== j or i>j:continue
        num=0    
        for k in range(d):
            num+=(x[i][k]-x[j][k])**2
        if abs(int(num**0.5)-num**0.5)<0.001:
            
            count+=1
print(count)

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

fin = sys.stdin.readline
N, D = [int(elem) for elem in fin().split()]
x_list = [[int(elem) for elem in fin().split()] for _ in range(N)]


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


count_all = 0
for each_combi in combinations(x_list, 2):
    if checkInteger(each_combi[0], each_combi[1]):
        count_all += 1

print(count_all)

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

x=[]

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

def K(a1,a2):
    return math.sqrt(sum(map(lambda x:pow(x[0]-x[1],2),zip(a1,a2))))

A=0

for i in range(N):
    for j in range(i+1,N):
        temp=K(x[i],x[j])
        if temp==math.floor(temp):
            A+=1

print(A)

Solution (Python):

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


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


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


def C():
    l, r = LI()
    if l // 2019 == r // 2019:
        print((l * (l + 1)) % 2019)
    else:
        print(0)
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    B()

Solution (Python):
import sys
from math import sqrt

input = sys.stdin.readline

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

count = 0
for i in range(N - 1):
    for j in range(i+1, N):
        p1 = points[i]
        p2 = points[j]
        dist = sqrt(sum((x - y) ** 2 for x, y in zip(p1, p2)))
        if int(dist) == dist:
            count += 1

print(count)

Solution (Python):
import math

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):
            sum = 0
            for k in range(d):
                sum += (x[i][k]-x[j][k])**2

            y = int(math.sqrt(sum))
            if y**2 == sum:
                count +=1

print(count)

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

def isint(a, b):
    s = 0
    for i in range(D):
        s += (X[a][i]-X[b][i])**2
    if int(s**0.5+0.5) ** 2 == s:
        return 1
    return 0

ans = 0
for a in range(N):
    for b in range(a+1, N):
        ans += isint(a, b)
print(ans)

Solution (Python):
import math

n, d = (int(_) for _ in input().split())

xlist=[]

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

kotae=0

for i in range(n):
    for j in range(n-i-1):
        a=i
        b=i+j+1
        kyori=0
        for k in range(d):
            kyori+=(xlist[a][k]-xlist[b][k])**2
        kyori2=math.sqrt(kyori)
        if kyori2==int(kyori2):
            kotae+=1

print(kotae)

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

count = 0
for i in range(n):
    for j in range(n):
        if i != j:
            d = np.linalg.norm(x[i] - x[j])
            if math.floor(d) == d:
                count += 1
print(count//2)

Solution (Python):
from math import sqrt
N,D = list(map(int, input().split()))
P = []
for i in range(N):
  P.append( list(map(int, input().split())) )
  
def dist(a,b):
  ret = 0
  for i in range(D):
    ret += (a[i] - b[i]) ** 2
  return ret

ans = 0
for i in range(N):
  for j in range(i+1,N):
    work = sqrt(dist(P[i], P[j]))
    if abs(int(work) - work) < 1e-11:
      ans += 1
      
print(ans)

Solution (Python):

import sys
import math

def distance(a, b):
    result = 0
    for i in range(len(a)):
        result += (a[i]-b[i])** 2
    return math.sqrt(result)
    

def solve(N: int, D: int, X: "List[List[int]]"):
    count = 0
    for i in range(N):
        for j in range(i+1, N):
            dist = distance(X[i], X[j])
            if dist % 1 == 0:
                count += 1
            else:
                pass
    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

def readInts():
  return [int(s) for s in input().split(" ")]

def isDistanceInt(X1, X2):
  d = 0
  for i in range(len(X1)):
    d += (X1[i] - X2[i]) ** 2

  dr = int(math.sqrt(d))
  return dr ** 2 == d

def main():
  N, D = readInts()
  Xs = [readInts() for _ in range(N)]
  ans = 0
  for i in range(N-1):
    for j in range(i+1, N):
      if isDistanceInt(Xs[i], Xs[j]):
        ans += 1
  print(ans)


if __name__ == "__main__":
  main()

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

from itertools import combinations

pairs = list(combinations(X, 2))

res = 0
for pair in pairs:
    d = 0
    for i in range(D):
        d += (pair[0][i] - pair[1][i])**2
    d = d**0.5
    if int(d) == d:
        res += 1

print(res)

Solution (Python):
import math

N, D = list(map(int, input().split()))
Xs = [[0 for _ in range(D)] for _ in range(N)]
for i in range(N):
    Xs[i] = list(map(int, input().split()))


def distisint(a, b):
    dsq = 0
    for i in range(D):
        dsq += (Xs[a][i] - Xs[b][i]) ** 2
    d = math.sqrt(dsq)
    return math.floor(d) ** 2 == dsq


c = 0
for i in range(0, N - 1):
    for j in range(i + 1, N):
        if distisint(i, j):
            c += 1
print(c)

Solution (Python):
import sys, math

def input(): return sys.stdin.readline()[:-1]
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 MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
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

def main():
    N, D = MAP()
    X = MATINT(N)
    count = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            sum = 0
            for d in range(D):
                sum += (X[i][d] - X[j][d])**2
            ans = math.sqrt(sum)
            if ans * 10 % 10 == 0:
                count += 1
    print(count)

if __name__ == '__main__':
    main()

Solution (Python):
import math
n, d = map(int, input().split())
dat_x = []
for i in range(n):
    l = map(int, input().split())
    l = list(l)
    dat_x .append((l))
res = 0
for i in range(n):
    for j in range(n):
        if i == j:
            break
        s = 0
        for k in range(d):
            s += (dat_x[i][k] - dat_x[j][k]) * (dat_x[i][k] - dat_x[j][k])
        
        t = math.sqrt(s)
        if t.is_integer():
            
            res += 1
print(res)

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

ans=0
import itertools
for i,j in itertools.combinations(range(n),2):
    res=0
    for k in range(d):
        res+=(x[i][k]-x[j][k])**2
    q=res**0.5
    if q==q*10//10:
        ans+=1
print(ans)

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

Solution (Python):
n,d=map(int,input().split())
x=[[int(a) for a in input().split()] for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        s = sum([(a-b)*(a-b) for a,b in zip(x[i],x[j])])
        t = int(s**.5)
        if s == t*t:
            ans +=1
print(ans)

Solution (Python):
import math
def cal_dis(a,b):
    out = 0
    for i in range(len(a)):
        out += (a[i]-b[i])**2
    return out


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

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        distanse = cal_dis(points[i],points[j])
        if math.sqrt(distanse)%1 ==0:
            cnt += 1

print(cnt)