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



Sample input:
3 2
1 2
5 5
-2 8


Sample output:
1

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
arr = []
ans = 0
for i in range(n):
  x = list(map(int, input().split()))
  arr.append(x)

p = []
for i in range(n):
  for j in range(n):
    if i < j:
      p.append([i, j])

for ij in p:
  y = arr[ij[0]]
  z = arr[ij[1]]
  d = 0
  for i, j in zip(y, z):
    d += (i - j) ** 2 
  d = math.sqrt(d)
  if d == int(d):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
a = [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):
        hoge = 0
        for k in range(d):
            hoge += (a[i][k] - a[j][k])**2
        if math.sqrt(hoge) == int(math.sqrt(hoge)):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
xd = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        t = 0
        for k in range(D):
            t += pow(xd[i][k]-xd[j][k], 2)
        t = math.sqrt(t)
        if t == float(int(t)):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    import math
    N, D = map(int, input().split())
    A = []
    count = 0
    for i in range(N):
        A.append(list(map(int, input().split())))
    for j in range(N):
        for g in range(N):
            ans = 0
            if j != g:
                for k in range(D):
                    ans += (A[j][k]-A[g][k])**2
                if math.sqrt(ans)%1== 0:
                    count += 1
    print(count//2)
resolve()

Submission status: Accepted

Solution code:
def resolve():
    import math
    N, D = map(int, input().split())
    A = []
    count = 0
    for _ in range(N):
        A.append(list(map(int, input().split())))
    for i in range(N):
        for j in range(i+1, N):
            if j != i:
                ans=0
                for g in range(D):
                    ans += (A[i][g]-A[j][g])**2
                if math.sqrt(ans)%1 == 0:
                    count += 1
    print(count)
resolve()

Submission status: Accepted

Solution code:
import itertools
import math

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

ll = [i for i in range(n)]
count = 0
for a1, a2 in itertools.combinations(ll, 2):
    # print(a1)
    # print(a2)
    
    sum_v = 0
    for i in range(d):
        sum_v += (l[a1][i] - l[a2][i]) ** 2
        
    dist = math.sqrt(sum_v)
    if dist == int(dist):
        # print(dist)
        count += 1
        
print(count)

Submission status: Accepted

Solution code:
import math
def inp():return map(int,input().split())
def linp():return list(map(int,input().split()))

n,d=inp()
distance=[]
coordinates=[]
for i in range(n):
    coordinates.append(linp())

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

Submission status: Accepted

Solution code:
n,d = map(int, raw_input().split(' '))
elems = [map(int,raw_input().split(' ')) for _ in range(n)]

def f(x):
	q = 1
	while(q * q <= x):
		if q **2 == x: return True
		q +=1
	return False
count = 0
for i in range(len(elems)):
	for j in range(i+1, len(elems)):
		if f(sum([(abs(a-b) ** 2) for a, b in zip(elems[i],elems[j])])):
			count +=1
print count

Submission status: Accepted

Solution code:
n,d=map(int, input().split())
xd = [list(map(int, input().split())) for _ in range(n)]
import math
ans = 0
for i in range(len(xd)):
    for j in range(len(xd)):
        d = 0
        if i == j:
            continue
        for k in range(len(xd[i])):
            d += abs(xd[i][k]-xd[j][k])**2
        if math.sqrt(d).is_integer():
            ans += 1
print(int(ans/2))

Submission status: Accepted

Solution code:
import math
import itertools


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

X = list()

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

ans_count = int()

if d > 1:
    for v in itertools.combinations(X, 2):
        dist = int()
        for num in range(d):
            dist += (v[0][num] - v[1][num])**2
        ans_dist = math.sqrt(dist)
        if ans_dist.is_integer():
            ans_count += 1
    print(ans_count)
    
else:
    for v in itertools.combinations(X, 2):
        dist = int()
        dist = (v[0][0]- v[1][0])**2
        ans_dist = math.sqrt(dist)
        if ans_dist.is_integer():
            ans_count += 1
    print(ans_count)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        t = 0
        for k in range(d):
            t += (abs(lis[i][k] - lis[j][k]))**2
            
        if (t**0.5).is_integer():
            cnt += 1
            
print(cnt)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
a=[]
for i in range(n):
    a.append([int(i) for i in input().split()])
ans=0

for i in range(n-1):
    for j in range(i+1,n):
        x=a[i]
        y=a[j]
        kyori=[(x[k]-y[k])**2 for k in range(d)]
        if sum(kyori)**(0.5)==int(sum(kyori)**(0.5)):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math
n, d  = map(int, input().split())
ll = []
count = 0
for i in range(n):
    ll.append(list(map(int, input().split())))
for i in range(n):
    for j in range(i+1,n):
        dd = 0
        for k in range(d):
            dd += (ll[i][k]-ll[j][k])**2
            s = math.sqrt(float(dd))
        if s == int(s):
            count+=1
print(count)

Submission status: Accepted

Solution code:
def main():
    N, D = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]    
    cnt = 0
    for i in range(len(A)-1):
        for j in range(i+1, len(A)):
            a1 = A[i]
            a2 = A[j]
            dist = 0
            for x, y in zip(a1, a2):
                dist += (x-y)**2
            dist_sqr = dist**0.5
            if dist_sqr == int(dist_sqr):
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    n, d = map(int, input().split())
    X=[]
    count = 0
    sum = 0
    for i in range(n):
        x = list(map(int, input().split()))
        X.append(x)
    for i in range(n-1):
        for v in range(i+1,n):
            for u in range(d):
                sum += (X[i][u] - X[v][u])**2
            len = math.sqrt(sum)
            sum = 0
            if len == int(len):
                count += 1
    print(count)


main()

Submission status: Accepted

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

ans = 0

for i, x in enumerate(X):
    for y in X[i+1:]:
        d = 0
        for i in range(D):
            d += (x[i] - y[i]) ** 2
        
        j = 0
        while True:
            if j ** 2 == d:
                ans += 1
                break
            elif j ** 2 > d:
                break
            j += 1
print(ans)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x = []
nijou = set([i**2 for i in range(10000)])
for i in range(n):
	x.append([int(i) for i in input().split()])
ans = 0
for i in range(n-1):
	for j in range(i+1, n):
		if sum([(x[i][k] - x[j][k])**2 for k in range(d)]) in nijou:
			ans += 1
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    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):
            dd = sum([(x[i][k] - x[j][k]) ** 2 for k in range(d)])
            if dd == int(dd ** 0.5) ** 2:
                ans += 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

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

lis=[False for i in range(16001)]
i=0
while(i*i<16000):
  lis[i*i]=True
  i+=1
  
ans=0
for i in range(n):
  for j in range(i):
    dis=sum([(x[i][k]-x[j][k])*(x[i][k]-x[j][k]) for k in range(d)])
 #   print(dis)
    if lis[dis]:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
from itertools import combinations
n,d=map(int,input().split())
ct=0
list1=[[0 for i in range(d)]for j in range(n)]
list2=list(range(n))
pair=list(combinations(list2,2))
for i in range(n):
    list1[i]=list(map(int,input().split()))
for i in range(len(pair)):
    ans=0
    for j in range(d):
        ans+=(list1[pair[i][0]][j]-list1[pair[i][1]][j])**2
    if int(sqrt(ans))-sqrt(ans)==0:
        ct+=1
print(ct)

Submission status: Accepted

Solution code:
from itertools import combinations
import math
a,b=map(int,input().split())
li=[list(map(int,input().split())) for i in range(a) ]
ln=list(combinations(range(a),2))
ans=[]
l=0
for i in range(len(ln)):
    for j in range(b):
        l+=(li[ln[i][0]][j]-li[ln[i][1]][j])**2
    l3=math.sqrt(l)
    ans.append(l3)
    l=0

answe=0
for i in ans:
    if i.is_integer():
       answe+=1 
print(answe)

Submission status: Accepted

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

count = 0
for i in range(N):
    for j in range(i + 1, N):
        distance = sum([(y - z) ** 2 for y, z in zip(point[i], point[j])]) ** .5
        # print(f"i:{i} j:{j} distance:{distance}", file=sys.stderr)
        if abs(distance - int(distance)) < 0.0001:
            count += 1
print(count)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
#X = [input().split() for i in range(N)]
#a = [list(map(int,input().split(" "))) for i in range(N)]
X = [list(map(int,input().split(" "))) for i in range(N)]
import math


def diff(lis1,lis2):
	l = 0
	#lis3 = [0]*len(lis1)
	for i in range(len(lis1)):
		l += abs(lis1[i] - lis2[i])**2
	return math.sqrt(l)


cnt = 0
for i in range(N):
	for j in range(i+1,N):
		if diff(X[i],X[j]).is_integer():
			cnt += 1
		#print("diff(X[i],X[j]),cnt",diff(X[i],X[j]),cnt)

print(cnt)

Submission status: Accepted

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

import itertools,math
a = [i for i in range(n)]
e = itertools.combinations(a,2)

ans = 0
for i in e:
  c = 0
  for j in range(d):
    c += (x[i[0]][j] - x[i[1]][j]) ** 2
  if math.sqrt(c).is_integer():
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
N, D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
a = 0
for i in range(1,N):
    for j in X[i:]:
        W = 0
        for d in range(D):
            W +=(X[i-1][d]-j[d])**2
        if W**(1/2)== int(W**(1/2)):
            a +=1

print(a)

Submission status: Accepted

Solution code:
import math

LI = lambda : list(map(int, input().split()))
N, D = LI()
X = [LI() for _ in range(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

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

Submission status: Accepted

Solution code:
import math
X= []

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

f = 0
leng = 0

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

Submission status: Accepted

Solution code:
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")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
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)

Submission status: Accepted

Solution code:
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)
#print(x)
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
x = [[] for _ in range(n)]
for i in range(n):
	x[i] = list(map(int,input().split()))
#8000
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    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を複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
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)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
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()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



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

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
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
'''



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
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):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたら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)  # [1, 0, 3]

'''

def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    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.
    '''


########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

'''
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')
# abc---xyz

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

def main():
    n=3
    steps=0
    state=0
    w=1
    j=0
    k=0
    ans=0
    #lenを変数に置くと事故るから注意
    #n=int(input())
    #a,b=input().split(" ")#a,bがともに文字列のとき
    n,d=map(int, input().split(" "))
    #mapでとってもstrで変換すればappend可能
    #s=input()
    #a=[i for i in s]#int(i)にすれば数字も行ける
    #nl=list(map(int, input().split(" ")))#数字の時
    #print(a)
    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):
            #print(i,j)
            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)
    #print(brray)


    #for i in range(1,n+1,2):#これで1個飛ばしループになる
    # pass
     #print(i)

    l = ['aaa', 'bbb', 'ccc']
    x=l.index('aaa')#ある要素のインデックス番号を取得
    #s = ''.join(l)
    #s = " ".join(map(str,a))#スペースを空ける時はこう
    #print(s)
    # aaabbbccc

    #if state in known_states and not flag: # state => 2 steps => 5
        #こうやってある要素がリストの中にあるか探すのか
    #print(f'steps: {steps}, state: {state}')
    #こう書いてあるとデバックしやすい

    #dp= [[0]*3 for i in range(5)]#列　行
    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    #brray=[list(map(int, input().split(" ")))for i in range(N)
    #print(brray)



    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]#内包表記に慣れろ
    #print(pin_l)

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


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
S = [list(map(int, input().split())) for _ in range(N)]
#print(S)
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
        #print(SUM)
        if math.sqrt(SUM)%1==0:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()