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 numpy as np
N, M = list(map(int, input().split()))
X = [np.asarray(list(map(int, input().split()))) for i in range(N)]
count = 0
for i in range(N):
  for j in range(i+1, N):
    vec = X[i] - X[j]
    vec = np.dot(vec, vec.T)
    sq = int(np.sqrt(vec))
    if sq ** 2 == vec:
      count += 1
print(count)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D, X):
    p = set([i**2 for i in range(1, int(math.sqrt(16000)))])
    ans = 0
    for i, j in combinations(range(N), 2):
        d = 0
        for k in range(D):
            d += (X[i][k]-X[j][k])**2
        if d in p:
            ans += 1
    return ans


def main():
    N, D = read_int_n()
    X = [read_int_n() for _ in range(N)]
    print(slv(N, D, X))


if __name__ == '__main__':
    main()

Solution (Python):


from itertools import combinations
import math
import datetime
N, D = [int(x) for x in input().split()]
X = []
for _i in range(N):
    X.append([int(x) for x in input().split()])
ans = 0
for i in range(N):
    for j in range(i+1,N):
        dist2 = 0
        for x1, x2 in zip(X[i], X[j]):
            dist2 += (x1 - x2)**2
        if math.sqrt(dist2) == int(math.sqrt(dist2)):
            ans += 1
print(ans)

Solution (Python):
import math
n, d = [int(item) for item in input().split()]
x = []
for i in range(n):
    x.append([int(item) for item in input().split()])
ans = 0
for i in range(n):
    for j in range(i+1, n):
        val = 0
        for k in range(d):
            val += (x[i][k] - x[j][k]) ** 2.0 
        if math.sqrt(val).is_integer():
            ans += 1
print(ans)

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

import numpy as np
X = np.zeros((N, D))
for i in range(N):
    x = list(map(int, input().split()))
    X[i] = x

def isSq(n):
    a = np.sqrt(n)
    return n == int(a) * int(a)

p = 0
for i in range(N-1):
    for j in range(i+1, N):
        a = X[i] - X[j]
        s = a.dot(a)
        if isSq(s):
            p += 1

print(p)

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

print((ans-n)//2)

Solution (Python):

import sys


import numpy as np

import itertools

"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def main():
    def kyori(a, b):
        a = np.array(a)
        b = np.array(b)
        c = a-b
        c = c ** 2
        c = np.sum(c)
        return np.sqrt(c)

    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n, d = ip.IL()
    x = ip.SILS(n)
    memo = list(itertools.combinations(range(n), 2))
    
    ans = 0
    for y in memo:
        x1 = y[0]
        x2 = y[1]
        
        res = kyori(x[x1], x[x2])
        res2 = int(res)
        if res == res2:
            ans += 1
        
    print(ans)


main()

Solution (Python):
import math

def main():
  n, d = map(int, input().split())
  xlist = []
  for _ in range(n):
    xlist.append(list(map(int, input().split())))
  ans = 0
  for i in range(n):
    for j in range(n):
      if i == j:
        continue
      dist = 0
      for k in range(d):
        dd = xlist[i][k] - xlist[j][k]
        dist += dd*dd
      if int(math.sqrt(dist)) * int(math.sqrt(dist)) == dist:
        ans += 1
  print(ans // 2)


if __name__ == '__main__':
  main()

Solution (Python):
import sys
sys.setrecursionlimit(100000000)
input=lambda : sys.stdin.readline().rstrip()

def dist(a,b):
    ans=0
    for x,y in zip(a,b):
        ans+=(x-y)**2
    return ans**0.5

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(i+1,n):
        if abs(int(dist(x[i],x[j])+0.5)-dist(x[i],x[j]))<0.000000001:
            count+=1
print(count)

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

ans = 0
for i in range(1, n):
    for j in range(i):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        if abs(int(dist ** 0.5) ** 2 - dist) < 1e-6: 
            ans += 1
print(ans)

Solution (Python):
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def calc_distance(x, y, D):
    distance = 0
    for i in range(D):
        distance += (x[i] - y[i])**2
    distance = np.sqrt(distance)
    return distance

def main():
    N, D = map(int, input().split())
    X = []
    for _ in range(N):
        line = [int(i) for i in input().split()]
        X.append(line)
    
    num = 0
    for i in range(N):
        for j in range(i + 1, N):
            distance = calc_distance(X[i], X[j], D)
            if isinstance(distance, int) or distance.is_integer():
                num += 1
    print(num)




    



if __name__ == '__main__':
    main()

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

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

        if(dist.is_integer()):
            ans += 1
print(ans)

Solution (Python):
N,D = map( int, input().split())
X = [0 for i in range(10) for j in range(10)]
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):
    len = 0
    for a in range(D):
      len += (X[i][a] - X[j][a]) ** 2
    len = len ** 0.5
    if len == int(len):
      ans += 1
print(ans)

Solution (Python):




def main():
    N, D = map(int, input().split())
    X = [tuple(map(int, input().split())) for _ in range(N)]
    c = 0
    
    for i, x1 in enumerate(X):
        for x2 in X[i+1:]:
            d = sum((x1[j] - x2[j])**2 for j in range(D))
            if round(d**.5)**2 == d:
                c += 1

    print(c)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

N, D = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in range(N):
    for j in range(N):
        if j == i:
            continue
        dist = np.sqrt(sum([(points[i][d] - points[j][d]) ** 2 for d in range(D)]))
        if dist.is_integer():
            count += 1
print(count // 2)

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

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

import math

ans = 0
for i, x_i in enumerate(X):
    for j, x_j in enumerate(X[i+1:]):
        l = sum([ (a-b)**2 for a, b in zip(x_i, x_j)])
        ans += math.sqrt(l).is_integer()
        
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

n,d=intinput()
p=[]
for i in range(n):
    p.append(list(intinput()))
ans=0
for i in range(n):
    for j in range(i+1,n):
        tmp=0
        for k in range(d):
            tmp+=(p[i][k]-p[j][k])**2
        if int(tmp**0.5)**2==tmp:
            ans+=1
print(ans)

Solution (Python):
N,D=map(int,input().split())
L=[]
hei=[i**2 for i in range(200)]

for i in range(N):
  l=list(map(int,input().split()))
  L.append(l)
ans=0
for i in range(N):
  for j in range(i+1,N):
    if sum((L[i][k]-L[j][k])**2 for k in range(D)) in hei:
      ans+=1
print(ans)

Solution (Python):
import math
n, d = list(map(int, input().split(' ')))
tmp = []
for _ in range(n):
    res = list(map(int, input().split(' ')))
    tmp.append(res)
ans = 0
for i in range(n):
    for j in range(i+1, n):
        dis = 0
        for x, y in zip(tmp[i], tmp[j]):
            dis += pow((x-y), 2)

        root = int(math.sqrt(dis))
        if root * root == dis:
            ans += 1

print(ans)

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right





def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 






N, D = l_inpl()
X = []

for _ in range(N):
    Xi = l_inpl()
    X.append(Xi)

ans = 0
for yi, zi in combinations(list(range(N)), 2):
    tmp = 0
    for y, z in zip(X[yi], X[zi]):
        tmp += (abs(y - z)) ** 2
    
    if (tmp**(1/2)).is_integer():
        ans += 1

print(ans)

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

cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        dis = sqrt(float(sum([(X[i][c] - X[j][c])**2 for c in range(D)])))
        if float(int(dis)) == dis:
            cnt += 1

print(cnt)

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

Solution (Python):
import math

N, D = (map(int, input().split()))
X = []
output = 0

for i in range(N):
	X.append(list(map(int, input().split())))
	
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 math.sqrt(tmp) - int(math.sqrt(tmp)) == 0:
			output += 1
			
print(output)

Solution (Python):
N, D = map(int, input().split())
ans = 0
X = []
for i in range(N):
  x = [int(i) for i in input().split()]
  X.append(x)
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 ((tmp)**(1/2))%1 != 0:
      continue
    else:
      ans += 1
print(ans)

Solution (Python):
import sys, math

readline = sys.stdin.readline

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

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

count = 0
for i in range(0, N):
    for j in range(i + 1, N):
        l2 = sum([(x - y) ** 2 for x,y in zip(X[i], X[j])])
        l_floor = math.floor(l2 ** 0.5)
        if l2 == l_floor ** 2:
            count += 1

print(count)

Solution (Python):
import numpy as np
N, D = [int(n) for n in input().split()]
X = [[int(n) for n in input().split()] for _ in range(N)]
cnt = 0
for i in range(N-1):
    for j in range(i+1, N):
        d2 = 0
        for k in range(D):
            d2 += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k])
        d = np.sqrt(d2)
        if d == int(d):
            cnt += 1
print(cnt)

Solution (Python):
n,d = map(int,input().split())
x = [0 for _ in range(d)]*n
for i in range(n):
    x[i] = [int(_) for _ in input().split()]
res = 0
sq = [i*i for i in range(10000)] 
for i in range(n):
    for j in range(n):
        if i != j:
            if sum([(x[i][k]-x[j][k])**2 for k in range(d)]) in sq:
                res += 1
print(res//2)

Solution (Python):
from math import sqrt

N, D = list(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):
        diff = [(X[i][k] - X[j][k])**2 for k in range(D)]
        dist = sum(diff)**.5
        if dist == int(dist):
            num += 1

print(num)

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

ans = 0
l = [ i for i in range(N)]
import itertools
for a in itertools.combinations(l,2):
    dis = 0
    for k in range(D):
        dis += (X[a[0]][k] - X[a[1]][k])**2
    dis = dis**(1/2)
    if float.is_integer(dis):
        ans += 1
print(ans)

Solution (Python):
import math
N,D = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for _ in range(N)]
n = 0 
for i in range(N-1):
    for j in range(i+1, N):
        dis = math.sqrt(sum([(xi-xj)**2 for xi,xj in zip(X[i], X[j])]))
        if dis == math.floor(dis):
            n+=1
print(n)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

import math

N, D = mi()

X = [li() for _ in range(N)]

count = 0
for i in range(N):
  for j in range(N):
    if i == j:
      continue
    distance = math.sqrt(sum([(X[i][index] - X[j][index]) ** 2 for index in range(D)]))
    if int(distance) == distance:
      count += 1

print(count // 2)

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

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

count = 0

for i in range(n):
    for j in range(n):
        nijou_dist = 0
        for k in range(d):
            nijou_dist = nijou_dist + (zahyou[i][k] - zahyou[j][k]) ** 2
        if (nijou_dist ** (1 / 2)).is_integer():
            count = count + 1

print((count - n) // 2)

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

Solution (Python):
n,d=map(int,input().split())
l=[[] for i in range(n)]
for i in range(n):
    l[i]=list(map(int,input().split()))
ans=0
for i in range(n):
    for j in range(i+1,n):
        cnt=0
        for k in range(d):
            cnt+=(l[i][k]-l[j][k])**2
        
        for x in range(1000):
            if x**2==cnt:
                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):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += (x[i][k]-x[j][k]) ** 2
        dis = dis ** (1/2)
        if dis.is_integer():
            ans += 1
print(ans)

Solution (Python):
import math

def distance(D, X, Y):
    ans = 0.0
    for i in range(D):
        ans += (X[i]-Y[i])*(X[i]-Y[i])
    return math.sqrt(ans)

def isInteger(n):
    return (n // 1) == n

N, D = map(int,input().split())
X = []
cnt = 0
for i in range(N):
    X.append(list(map(int,input().split())))
for i in range(N):
    for j in range(i+1, N):
        temp = distance(D, X[i], X[j])
        if isInteger(temp):
            cnt += 1
print(str(cnt))

Solution (Python):
import math

def checkDisInt(y, z):
    disSum = 0
    for i in range(D):
        disSum += (y[i] - z[i])**2
    if int(math.sqrt(disSum))**2 == disSum:
        return True
    return False

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

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

print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op



inf = float('inf')
input = stdin.readline


def bisearch(f, n):
    l = 0
    r = n
    fl = f(l)
    fr = f(r)
    while l <= r:
        m = (l + r) // 2
        fm = f(m)
        
        if fm == n:
            return m
        elif fm > n:
            r = m - 1
            fr = f(r)
        else:
            l = m + 1
            fl = f(l)


def try_square_root(n2):
    return bisearch(lambda n:n*n, n2)


def main():
    n, d = get_li()
    points = []
    for _ in range(n):
        points.append(get_li())
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            sq_distance = 0
            for k in range(d):
                sq_distance += (points[i][k] - points[j][k]) ** 2
            if try_square_root(sq_distance):
                ans += 1
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()

Solution (Python):
N,D = map(int,input().split())
X = []
for i in range(N):
  X.append(list(map(int,input().split())))
  
ans = 0
for i in range(N - 1):
  for j in range(i + 1,N):
    a = 0
    for k in range(D):
      a += (X[i][k] - X[j][k]) ** 2
    if int(a ** 0.5) == a ** 0.5:
      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):
    for j in range(i + 1, N):
        t = 0
        for y, z in zip(X[i], X[j]):
            t += abs(y - z) ** 2
        t = t ** 0.5
        if t % 1 == 0:
            ans += 1
print(ans)

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

def dist(i,j,x, d):
    distance = 0
    for k in range(d):
        distance += (x[i][k] - x[j][k])**2
    distance = math.sqrt(distance)
    return distance
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            distance = dist(i,j,x, d)
            if distance.is_integer() == True:
                count += 1
print(count//2)

Solution (Python):
import math
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):
    d2 = sum([(a-b)**2 for a, b in zip(X[i],X[j])])
    if float(int(math.sqrt(d2))) == math.sqrt(d2):
      ans += 1
print(ans)

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

res = 0

for i in range(len(xs)):
    for j in range(i):
        d = (sum((xs[i][k] - xs[j][k])**2 for k in range(D)))**0.5
        if d.is_integer(): res+=1

print(res)

Solution (Python):
import math
d, n = map(int, input().split())
listT = []
index=0
while index < d:
    listX = list(map(int, input().split()))
    listT.append(listX)
    index+=1

index2=0
count=0
while index2 < len(listT):
    index3=index2+1
    while index3 < len(listT):
        sumA=0
        index4=0
        while index4 < len(listT[index2]):
            sumA+=(listT[index2][index4]-listT[index3][index4])**2
            index4+=1
        if math.sqrt(sumA).is_integer():
            count+=1
        index3+=1
    index2+=1
print(count)

Solution (Python):
n, d = [ int(v) for v in input().split() ]
point_list = [  [ int(v) for v in input().split() ] for i in range(n) ]
square_list = [ i**2 for i in range(10**4+1) ]
ans = 0

for i in range(n):
    for j in range(i+1,n):
        d2 = 0
        for k in range(d):
            d2 += (point_list[i][k] - point_list[j][k])**2
        if d2 in square_list:
            ans += 1
print(ans)

Solution (Python):
import math

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

x_list = []
c = 0
for i in range(N):
    x_list.append(list(map(int, input().split())))
    if i != 0:
        for j in range(i):
            S = 0
            for k in range(D):
                s = (x_list[j][k]-x_list[i][k])**2
                S += s
            a = math.sqrt(S)
            if float.is_integer(a) == True:
                c += 1

print(c)

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

Xs = []

targets = []
count = 0
for i in range(0, 3000):
    targets.append(i**2)

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

for i in range(0,N):
    for h in range(i,N):
        if i == h:
            continue

        dist = 0
        for index in range(len(Xs[0])):
            dist += (Xs[i][index] - Xs[h][index])**2

        if dist in targets:
            count += 1


print(count)

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

Solution (Python):
import math

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

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        dis = 0
        for x1, x2 in zip(X[i], X[j]):
            dis += (x1 - x2)**2
        if math.sqrt(dis) == int(math.sqrt(dis)):
            ans += 1

print(ans)

Solution (Python):
import math
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(i+1, N):
        s = 0
        for k in range(D):
            s += (x[i][k] - x[j][k]) ** 2

        if math.sqrt(s) == int(math.sqrt(s)):
            ans += 1
print(ans)

Solution (Python):
import numpy as np


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

answer = 0
for i in range(N):
  for j in range(i+1, N):
    distance = np.linalg.norm(points[i]-points[j])
    if distance == int(distance):
      answer += 1

print(answer)

Solution (Python):
import math
N, D = [int(x) for x in input().split(' ')]

X = []
for n in range(N):
 X.append([int(x) for x in input().split(' ')])

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

print(count)

Solution (Python):
import sys

fin = sys.stdin.readline

n, d = map(int, fin().split())
x = [tuple(map(int, fin().split())) for i in range(n)]

count = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        d = (sum([(y - z) ** 2 for y, z in zip(x[i], x[j])]) ** 0.5)

        if abs(d - round(d)) < 1e-9:
            count += 1

print(count)

Solution (Python):

from itertools import combinations
from math import sqrt

def solve():
    N, D = map(int, input().split())
    X = [list(map(int, input().split())) for _ in range(N)]
    res = 0
    for x,y in combinations(X,r=2):
        z = sum(map(pow, map(int.__sub__,x,y), [2]*D))
        r = sqrt(z)
        if round(r)**2 == z:
            res += 1
    return str(res)

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

Solution (Python):
import math

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

X = []

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

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

ans = 0

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

print(ans)

Solution (Python):
import numpy as np

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

ans = 0
for j in range(1,N):
  for i in range(j):
    tmp = (P[i] - P[j])
    tmp2 = np.sqrt(np.dot(tmp,tmp))
    
    if (tmp2.is_integer()):
      ans += 1
print(ans)

Solution (Python):

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

dat = []

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

def isSquare(x):
    for i in range(x+1):
        if i**2 == x:
            return True
    return False
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        s = 0
        for k in range(d):
            s+= (dat[i][k]-dat[j][k])**2
        if isSquare(s):
            cnt+=1
print(cnt)

Solution (Python):
import math
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):
        a = 0
        for k in range(d):
            a += (x[i][k] - x[j][k])**2
        if int(int(math.sqrt(a))**2) == a:
            count += 1

print(count)

Solution (Python):
import numpy as np

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

X = [[] for _ in range(N)]

for i in range(N):
    X[i] = list(map(int,input().split()))
    
def dist(x,y):
    temp = 0
    for i in range(D):
        temp += (x[i]-y[i])**2
    
    return np.sqrt(temp)

ans = 0    

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