Problem:
 Score : 200 points    Problem Statement There are N points in a D -dimensional space.  The coordinates of the i -th point are (X_{i1}, X_{i2}, ..., X_{iD}) .  The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2} .  How many pairs (i, j)  (i < j) are there such that the distance between the i -th point and the j -th point is an integer?      Constraints  All values in input are integers.  2 \leq N \leq 10  1 \leq D \leq 10  -20 \leq X_{ij} \leq 20  No two given points have the same coordinates. That is, if i \neq j , there exists k such that X_{ik} \neq X_{jk} .         Input Input is given from Standard Input in the following format:  N  D  X_{11}  X_{12}  ...  X_{1D}  X_{21}  X_{22}  ...  X_{2D}  \vdots  X_{N1}  X_{N2}  ...  X_{ND}       Output Print the number of pairs (i, j)  (i < j) such that the distance between the i -th point and the j -th point is an integer.        Sample Input 1 3 2
1 2
5 5
-2 8      Sample Output 1 1  The number of pairs with an integer distance is one, as follows:   The distance between the first point and the second point is \sqrt{|1-5|^2 + |2-5|^2} = 5 , which is an integer.  The distance between the second point and the third point is \sqrt{|5-(-2)|^2 + |5-8|^2} = \sqrt{58} , which is not an integer.  The distance between the third point and the first point is \sqrt{|-2-1|^2+|8-2|^2} = 3\sqrt{5} , which is not an integer.        Sample Input 2 3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3      Sample Output 2 2       Sample Input 3 5 1
1
2
3
4
5      Sample Output 3 10

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

INF = float("inf")











N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
num = []
for i in range(N-1):
    for j in range(i+1,N):
        a = 0
        li1 = X[i]
        li2 = X[j]
        for k in range(D):
            a += (li1[k]-li2[k]) ** 2
        num.append(a)
count = 0
co = Counter(num)
ans = 0
for i in range(10000):
    ans += co[i*i]
print(ans)

Solution (Python):
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

def dist(list1,list2):
    d = 0
    for i in range(len(list1)):
        d += (list1[i]-list2[i])**2
    return math.sqrt(d)
n,d = I2()
x = []
for i in range(n):
    inp = Intl()
    x.append(inp)

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

Solution (Python):
import itertools
import math

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

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

p = [ i for i in range(N)]
road = itertools.combinations(p,2)



cnt =0

for i in road:
    
    temp = 0.0
    
    for d in range(D):
            temp += ((X[i[1]][d] -X[i[0]][d])**2)
    
    res = math.sqrt(temp)
            
    if res.is_integer():
        cnt+=1
            
print(cnt)

Solution (Python):
import math

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

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

Solution (Python):

import itertools
import math
n, d = map(int, input().split())
a = [[] for m in range(n)]
for i in range(n):
    a[i] = list(map(int, input().split()))
count = 0
for i in range(n):
    for j in range(i+1,n):
        value = 0
        for k in range(d):
            value += (a[i][k] - a[j][k]) ** 2
        check = value ** 0.5
        count += check.is_integer()
print(count)

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

ansk = 0
l = set([i**2 for i in range(300)])
for i in range(n):
	for j in range(i+1, n):
		ans = 0
		for k in range(d):
			ans += (x[i][k]-x[j][k])**2
		if ans in l:
			ansk += 1
print(ansk)

Solution (Python):
N, D = map(int, input().split())
points=[[]]*N
for i in range(N):
  points[i]=list(map(int, input().split()))
count=0
for i in range(N-1):
  for j in range(i+1,N,1):
    dist_sq=0
    for l in range(D):
      dist_sq+=(points[i][l]-points[j][l])**2
    dist=dist_sq**0.5
    if abs(dist-int(dist))<0.0001:
      count+=1
print(count)

Solution (Python):

import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement


from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter





j=0
k=0
n=3
r=1
a=[0]






"1行1つの整数を入力を取得し、整数と取得する"




"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''


'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        
        if n % k == 0:
            return False
            
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  

'''

def factorial(x, mod=10**9+7):
    
    
    
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''











'''
ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'
hexdigits = '0123456789abcdefABCDEF'
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv...\xaf\xb0...
lowercase = 'abcdefghijklmnopqrstuvwxyz'
octdigits = '01234567'
printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU...
punctuation = '!"
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
whitespace = '\t\n\x0b\x0c\r '
'''
'''
引数endに任意の文字列を指定すると、その文字列が改行の代わりに最後に挿入される。例えば連続するprint()の出力を改行なしで単純に連結したい場合は空文字列''を指定すればよい。

print('abc', end='---')
print('xyz')


print('abc', end='')
print('xyz')

source: print_basic.py
なお、デフォルトで改行されるのは引数endのデフォルト値が改行文字'\n'に設定されているから。
'''

def main():
    n=3
    steps=0
    state=0
    w=1
    j=0
    k=0
    ans=0
    
    
    
    n,d=map(int, input().split(" "))
    
    
    
    
    
    sum=0
    brray=[list(map(int, input().split(" ")))for i in range(n)]
    for i in range(n-1):
        for j in range(i+1,n):
            
            for k in range(d):
                sum=sum+(abs(brray[i][k]-brray[j][k]))**2
            if (np.sqrt(sum)).is_integer():
                ans=ans+1
            sum=0
    print(ans)
    


    
    
     

    l = ['aaa', 'bbb', 'ccc']
    x=l.index('aaa')
    
    
    
    

    
        
    
    

    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    
        
        
    
    
        
        
    


    
    



    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]
    

    ls = ["a", "b", "c", "d", "e"]


    
    

    
    

    
    
    
    
    
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

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):
    for j in range(i+1,n):
        value = 0
        for k in range(d):
            value += (x[i][k] - x[j][k]) ** 2
        check = value ** (1/2)
        dotti = check.is_integer()
        if dotti:
            count += 1
print(count)

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

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        SUM=0
        for k in range(D):
            SUM+=(S[i][k]-S[j][k])**2
        
        if math.sqrt(SUM)%1==0:
            ans+=1
print(ans)

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

Solution (Python):
N,D = map(int,input().split())
X = [list(map(int,input().split())) for i in range(0,N,1)]
count = 0
for i in range(0,N,1):
    for j in range(i+1,N,1):
        dist = 0
        for k in range(0,D,1):
            dist+=(X[i][k]-X[j][k])**2

        for k in range(0,dist+1,1):
            if k**2 == dist:
                count+=1
                break

print(count)

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

Solution (Python):
import math

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

cnt = 0
p_list = []

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

for i in range(N):
    for j in range(i+1, N):
        num = 0
        for k in range(D):
            num += (p_list[i][k] - p_list[j][k]) ** 2
        num = math.sqrt(num)
        if num.is_integer():
            cnt += 1

print(cnt)

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

def d(a, b):
    sum = 0
    for i in range(D):
        sum += (a[i]-b[i])**2

    return sum**0.5

cnt = 0

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

print(cnt)

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-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**(1/2)%1 == 0:
            count += 1

print(count)

Solution (Python):
sq_nums = {i * i for i in range(1, 151)}
N, D = map(int, input().split())
coords = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if sum((y - z) ** 2 for y, z in zip(coords[i], coords[j])) in sq_nums:
            ans += 1
print(ans)

Solution (Python):
import math
N, D = map(int, input().split(' '))
X = [[0 for _ in range(N + 10)] for _ in range(D + 10)]
res = 0
for i in range(N):
  X[i] = list(map(int, input().split(' ')))
for i in range(N - 1):
  for j in range(i + 1, N):
    dist = 0
    for k in range(D):
      dist += (X[i][k] - X[j][k])**2
    dist = math.sqrt(dist)
    if dist == int(dist):
      res += 1
print(res)

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

def main():
    n,d = map(int, input().split())
    list_num = []
    for i in range(n):
        list_x = list(map(int, input().split()))
        list_num.append(list_x)
    
    count = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                ans = 0
                result_num = 0
                for l in range(d):
                    result_num += pow(abs(list_num[i][l] - list_num[j][l]),2)
                ans = sqrt(result_num)
                
                if ans.is_integer():
                    count += 1
    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
n,d = map(int,input().split())
l = [list(map(int,input().split()))for _ 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):
n, d = map(int, input().split())
count = 0
X = [list(map(int, input().split())) for i in range(n)]
for x in range(n - 1):
	for y in range(x + 1, n):
		d = sum([(a - b)**2 for a, b in zip(X[x], X[y])])**0.5
		if d == d // 1:
			count += 1
print(count)

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)




import math



n,d=n1()
X=n3(n)
ans=0

for i in range(n):
    for j in range(i+1,n):
        line1,line2=X[i],X[j]
        c=0
        for x,y in zip(line1,line2):
            c+=(x-y)**2
        if (math.sqrt(c)).is_integer():
            ans+=1
print(ans)

Solution (Python):
from itertools import combinations
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for xi, xj in combinations(x, 2):
    d = sum((yi - zi) ** 2 for yi, zi in zip(xi, xj))
    l, r = 0, 1001001001
    while r - l > 1:
        c = (l + r) // 2
        if c ** 2 <= d:
            l = c
        else:
            r = c
    if l ** 2 == d:
        ans += 1
print(ans)

Solution (Python):
from itertools import combinations
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for v in combinations(range(N), 2):
  a = sum([(i - j) ** 2 for i, j in zip(X[v[0]], X[v[1]])])
  if math.ceil(a ** 0.5) == a ** 0.5:
    ans += 1
    
print(ans)

Solution (Python):
import  math


def length(l1, l2):
    total = 0
    for i in range(len(l1)):
        total += (l1[i] - l2[i]) ** 2
    return math.sqrt(total)


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

for i in range(N-1):
    for j in range(i+1, N):
        tmp = length(X[i], X[j])
        if tmp.is_integer():
            ans += 1
print(ans)

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

x = []
for i in range(n):
    x.append(list(map(int, input().split())))
    
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):
import math

N, D = map(int, input().split())
X = [None]*N

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

ans = 0

for i in range(N-1):
    for j in range(i+1, N):
        buf = 0
        for p in range(D):
            buf += (X[i][p]-X[j][p])*(X[i][p]-X[j][p])
        buf1 = math.sqrt(buf)
        if buf1 == int(buf1):
            ans += 1
print(ans)

Solution (Python):

import itertools
import math


def dist(xs, ys):
    ans = 0
    for x, y in zip(xs, ys):
        ans += (x - y) ** 2
    return math.sqrt(ans)


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

    ans = 0
    for i, j in itertools.combinations(range(N), 2):
        d = dist(Xs[i], Xs[j])
        if d == int(d):
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
from itertools import combinations
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
count=0
for y,z in combinations(X,2):
    count+=(sum(diff**2 for diff in np.array(y)-np.array(z))**.5).is_integer()
print(count)

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

x =[]

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

def kyori(x,y):
    kyo2=0
    for i in range(d):
        kyo2 += (x[i]-y[i])**2
    
    return math.sqrt(kyo2)





count=0

for i in range(n):
    for j in range(n):
        if i==j:
            pass
        else:
            dis = kyori(x[i], x[j])
            
            
            if dis.is_integer():
                count += 1
print(int(count/2))

Solution (Python):
from itertools import combinations
import numpy as np
n,d=map(int,input().split())
array=[]
x=[list(map(int,input().split())) for i in range(n)]
cnt=0
for y,z in combinations(x, 2):
  a=(sum(dif**2 for dif in np.array(y)-np.array(z))**0.5)
  if a.is_integer():
    cnt+=1
print(cnt)

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

x = [0]*n
c = 0
for i in range(n):
  x[i] = input().split()
  
for i in range(n-1):
  for j in range(i+1,n):
    dis = 0
    for k in range(0,d):
      dis = dis + (int(x[j][k])-int(x[i][k]))**2
    dis = math.sqrt(dis)
    
    dis = str(dis)
    if(dis[-1] == "0" and dis[-2] == "."):
      c = c + 1
print(c)

Solution (Python):
def dist(a, b):
	res = 0
	for i in range(D):
		res += (a[i] - b[i]) ** 2
	res = res ** 0.5
	return res


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

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

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

print(ans)

Solution (Python):

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
c = 0
for i in range(N):
    for j in range(N):
        if i != j:
            dis = sum([abs(a - b)** 2 for a, b in zip(X[i], X[j])])**0.5
            if dis.is_integer() == True:
                c += 1
print(c//2)

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

Solution (Python):


import itertools
import math

def dist(a,b):
    res=0
    for i in range(D):
        res+=(abs(a[i]-b[i]))**2
    res=res**0.5
    return res


N,D = map(int, input().split())
List = [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):
        if dist(List[i],List[j]).is_integer()==True:
            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)]
ans=0
for i in range(N-1):
  for j in range(i+1,N):
    key=0
    for x in range(D):
      key+=(X[i][x]-X[j][x])**2
    if math.sqrt(key)==int(math.sqrt(key)):
      ans+=1
print(ans)

Solution (Python):
import math

def calc(list,a,b):
    t = 0
    for k in range(len(list[a])):
        t += abs(list[a][k]-list[b][k])**2
    return math.sqrt(t)

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

for j in range(n-1,-1,-1):
    for i in range(j-1,-1,-1):
        if calc(x,i,j).is_integer():
            ans += 1

print(ans)

Solution (Python):
import math
n,d = map(int,input().split())
x = []
def dis(x1,x2):
    return (x1-x2)**2
for i in range(n):
    x_i = list(map(int,input().split()))
    x.append(x_i)
count = 0
for i in range(n):
    for j in range(i+1,n):
        sum = 0
        for k in range(d):
            sum += dis(x[i][k],x[j][k])
        if math.sqrt(sum).is_integer():
            count += 1
print(count)

Solution (Python):

import sys
input = sys.stdin.readline
N,D = (int(x) for x in input().split())
X =[]
for i in range(N):
    xx = list(map(int, input().split()))
    X.append(xx)


from itertools import combinations
import math
count =0
for i in combinations(range(N),2):
    dis_2jou =0
    for d in range(D):
       dis_2jou += (X[i[0]][d] -X[i[1]][d])**2 
    if  math.sqrt(dis_2jou).is_integer():
        count +=1
print(count)

Solution (Python):

import math


def inp():
    return(int(input()))



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



def instr():
    s = input()
    return(list(s[:len(s)]))



def invr():
    return(map(int, input().split()))


N, D = invr()
X = []

for i in range(N):
    X.append(inlist())
c = 0
for i in range(N):
    for j in range(i+1, N):
        dis = 0
        y = X[i]
        z = X[j]
        for d in range(D):
            dis += (y[d] - z[d])**2
        dis = math.sqrt(dis)
        if dis == math.floor(dis):
            c += 1
print(c)

Solution (Python):
N,D= map(int,input().split())
X =[]
for n in range(N):
    X.append([int(i) for i in input().split()])
cnt =0
from itertools import combinations
for i in list(combinations(X,2)):
    tmp=0
    for j in range(len(X[0])):
        tmp += ((i[0][j]-i[1][j])**2 )
    
    if int(tmp**0.5)==tmp**0.5:
        cnt+=1
print(cnt)

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

Solution (Python):


import math


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



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


ans = 0
for i, input in enumerate(input_list):
    j = i+1
    while j<len(input_list):
        sum = float(0)
        for k in range(D):
            sum = sum + (input_list[i][k] - input_list[j][k])**2
        
        if math.sqrt(sum).is_integer():
            ans = ans +1
        j=j+1

print(ans)

Solution (Python):
import math

n, d = map(int,input().split())
num = list(list(map(int, input().split())) for i in range(n))

count = 0

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

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

Solution (Python):
import math
def check(a, b):
  sum = 0
  a = [int(i) for i in a]
  b = [int(i) for i in b]
  for i in range(D):
    sum += (abs(a[i]-b[i]))**2
  if math.sqrt(sum).is_integer():
    return 1
  else:
    return 0
N, D = map(int, input().split())
X = [input().split() for _ in range(N)]
count = 0
for i in range(N):
  for j in range(i+1, N):
    count += check(X[i],X[j])
print(count)

Solution (Python):
import math

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


def calc_distance(x_list1, x_list2):
    return math.sqrt(sum([(x1 - x2)**2 for x1, x2 in zip(x_list1, x_list2)]))


ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        tmp = calc_distance(x_list[i], x_list[j])
        if tmp == int(tmp):
            ans += 1

print(ans)

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

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

Solution (Python):
import math

N, D = map(int, input().split())
xlist = []


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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        len = 0
        for k in range(D):
            len += pow(xlist[i][k]-xlist[j][k], 2)

        len = math.sqrt(len)

        
        b = int(len)
        if len == b:
            ans += 1


print(ans)

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

Solution (Python):
from itertools import combinations


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


cnt = 0
for i, j in combinations(X, 2):
    k = sum([abs(i[d] - j[d]) ** 2 for d in range(D)]) ** 0.5
    if k % 1 == 0:
        cnt += 1

print(cnt)

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

c = 0  

for j in range(n-1):
    for k in range(j+1,n):
        distance = 0
        for l in range(d):
            distance += (abs(a[j][l]-a[k][l]))**2
        distance = distance**0.5

        if distance.is_integer() == True:
            c += 1

print(c)

Solution (Python):
import itertools

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


def distancePoint(l1, l2):
    s = 0
    for j in range(d):
        s += (l1[j] - l2[j])**2
    return s**0.5


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

for k in itertools.combinations(x, 2):
    dist = distancePoint(k[0], k[1])
    if dist.is_integer():
        ans += 1

print(ans)

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

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

Solution (Python):
import math

def abc133_b():
    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):
            sq = 0
            for k in range(D):
                sq += (X[i][k] - X[j][k]) ** 2
            rt = math.floor(math.sqrt(sq) + 0.5)
            if rt * rt == sq: ans += 1
    print(ans)

abc133_b()

Solution (Python):
import sys,math
input = sys.stdin.readline

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(N):
    num = 0
    if i < j:
      for k in range(D):
        num += pow(abs(X[i][k] - X[j][k]) ,2)
      if math.floor(math.sqrt(num)) ** 2 == num:
        cnt += 1

print(cnt)

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

for j in range (N-1):
  for k in range(j+1, N):
    t = 0
    for l in range(D):
      t += (X[j][l]-X[k][l])**2
      
    if t**(1/2)%1 ==0:
      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(n):
    if i>j:
      goukei=0
      for k in range(d):
        goukei+=(x[i][k]-x[j][k])**2
      distance=goukei**0.5
      if distance.is_integer()==True:
        ans+=1
print(ans)