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:
def distance(x1, x2):
    sum = 0
    for i in range(len(x1)):
        sum += (x1[i] - x2[i])**2
    return sum**(1/2)

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

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

Submission status: Accepted

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

X = []
for i in range(n):
  X.append(list(map(int, input().split())))
from itertools import combinations as cm
total = 0
for pair in cm(X, 2):
  dis2 = 0
  for i in range(d):
    dis2 += (pair[0][i] - pair[1][i])**2
  dis = dis2**0.5
  if int(dis) == dis:
    total += 1
print(total)

Submission status: Accepted

Solution code:
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(0,N-1):
    for j in range(i+1,N):
        dist=0
        for k in range(D):
            dist += (X[i][k]-X[j][k])**2
        if dist**0.5 % 1 ==0:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import numpy
N, D = map(int, input().split())
listx = []
count = 0
for i in range(N):
    x = list(map(int, input().split()))
    listx.append(x)

for j in range(0, N):
    for k in range(j+1,N):
        a = numpy.array(listx[j])
        b = numpy.array(listx[k])
        u = b - a
        c = float(numpy.linalg.norm(u))
        if c.is_integer() :
            count += 1
print(count)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x=[]
out=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):
        tol=0
        for k in range(d):
            tol+=(x[i][k]-x[j][k])**2
        if tol**(1/2)-int(tol**(1/2))==0:
            out+=1
print(out)

Submission status: Accepted

Solution code:
import numpy
N, D = map(int, input().split())
listX = []

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

cnt = 0
for i in range(N):
    for j in range(N):
        if i<j:
            u = numpy.array(listX[i]) - numpy.array(listX[j])
            distance = numpy.linalg.norm(u)
            if distance.is_integer():
                cnt += 1
                
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
n,d=map(int, input().split())
l=[np.array(list(map(int, input().split()))) for _ in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1,n):
        tmp=0
        for k in range(d):
            tmp+=(l[i][k]-l[j][k])**2
        if np.sqrt(tmp)%1==0.0: cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import numpy

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

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

count = 0
for i in range(0, N):
    for j in range(i+1, N):
        y = numpy.array(lstMain[i])
        z = numpy.array(lstMain[j])
        u = z - y
        distance = float(numpy.linalg.norm(u))
        if distance.is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
# 当初理解が及ばずできなかったが、後日リベンジできた！
# B問題とは思えない！

def dis(d, x, y): #d次元、2点間の距離の関数
    a = 0
    for i in range(d):
        a += (x[i] - y[i])**2
    return a**0.5
    
n, d = map(int,input().split())

l = [] # n個の座標を2次元リストで取得
for j in range(n):
    l.append(input().split())
 
c=[]
for j in l:
    b=[]
    for k in j:
        b.append(int(k))
    c.append(b)

z = []
for e in range(n):
    for f in range(e,n): #重複（逆の組み合わせ）無し
        g = dis(d, c[e], c[f]) #各座標間の距離を関数で取得
        if g == int(g) and g != 0: #距離が整数かつゼロでないか確認
            z.append(g) # 上の条件をpassした値をリスト'z'へappend
            
print(len(z))

Submission status: Accepted

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

cnt=0
for i in range(n-1):
 for j in range(i+1,n):
  l1=l[i]
  l2=l[j]
  sum=0
  for y,z in zip(l1,l2):
   sum+=(y-z)**2
  dist=sum**0.5
  if dist==int(dist):
   cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
def dis(d, x, y):
    a = 0
    for i in range(d):
        a += (x[i] - y[i])**2
    return a**0.5
    
n, d = map(int,input().split())
#print(n,d)

l = []
for j in range(n):
    l.append(input().split())

c=[]
for j in l:
    b=[]
    for k in j:
        b.append(int(k))
    c.append(b)
#print(c)

z = []
for e in range(n):
    for f in range(e,n):
        g = dis(d, c[e], c[f])
        if g == int(g) and g != 0:
            z.append(g)
print(len(z))

Submission status: Accepted

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

def f(y, z):
    return abs(y - z) ** 2
ans = 0
B = tuple(itertools.combinations(A, 2))
for i in range(len(B)):
    accum = 0
    for j in range(D):
        accum += f(B[i][0][j], B[i][1][j])
    if (accum ** 0.5).is_integer():
        ans += 1
print(ans)

Submission status: Accepted

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

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


ans = 0
for i in range(n):
    for j in range(i+1, n):
        l = 0
        for k in range(d):
            l += (a[i][k] - a[j][k]) ** 2
        if (l ** .5).is_integer(): ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

def dist(x,y,d):
    sum=0
    for length in range(d):
       sum=sum+pow(x[length]-y[length],2)
    if not(int(np.sqrt(sum))==float(np.sqrt(sum))):
        return 0
    else:
        return 1

buf=0
count=0
N,D=map(int,input().split())
X=np.zeros((N,D))
for i in range(N):
    buf=input().split()
    for j in range(D):
        X[i][j]=buf[j]

#print(X)
for i in range(N-1):
    for j in range(N-i-1):
        count=count+dist(X[i],X[j+i+1],D)
print(count)

Submission status: Accepted

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

counter = 0
for i in range(N):
  for j in range(N-i-1):
    base = 0
    for k in range(D):
      base += (List[i][k]-List[i+j+1][k])**2
    if float.is_integer(base**0.5):
      counter += 1
  
print(counter)

Submission status: Accepted

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


def calc(a, b):
    return np.sqrt(sum((a - b)**2))


ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        k = calc(point[i], point[j])
        if k.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

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

def distance(x,y):
  total = 0
  for x_i,y_i in zip(x,y):
    total+=(x_i - y_i)**2    
  return math.sqrt(total)

X = []

N,D = LI()

for i in range(N):
  X.append(LI())
  
count = 0

for i in range(N):
  for j in range(i+1,N):
    d = distance(X[i],X[j])
    if float.is_integer(d):
      count+=1
print(count)

Submission status: Accepted

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

ans = 0
for i in range(n):
  for j in range(i):
    d2 = 0
    for k in range(d):
      d2 += (ll[i][k] - ll[j][k])**2
    d1 = d2 ** 0.5
    if d1 == round(d1):
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

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

cVec = list(itertools.combinations(vecList,2))
count = 0

for i in cVec:
  sqT = 0
  for j in range(d):
    sqT += (i[0][j]-i[1][j])**2
  sqT = math.sqrt(sqT)
  if sqT.is_integer():
    count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def dist(x,y,d):
    ret = 0.0
    for i in range(d):
        ret += pow(x[i] - y[i], 2)
    return pow(ret, 0.5)

def main():
    n, d = map(int, input().split())

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

    ans = 0

    for i in range(n):
        for j in range(i+1,n):
            distance = dist(num_list[i],num_list[j],d)
            if math.ceil(distance) == math.floor(distance):
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

N, D = map(int,input().split())
x = []
for _ in range(N):
    x.append(list(map(int,input().split())))
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        dist =0
        ist = [x[i][k] - x[j][k] for k in range(D)]
        for n in ist:
            dist += n ** 2
        if math.sqrt(dist) == int(math.sqrt(dist)):
            cnt +=1
print(cnt)

Submission status: Accepted

Solution code:
import math

def GoodDist():
    N, D = map(int, input().split())
    X = []
    for _ in range(N):
        X.append(list(map(int, input().split())))
    cnt = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            dist = 0
            lst = [X[i][k] - X[j][k] for k in range(D)]
            for n in lst:
                dist += n ** 2
            if math.sqrt(dist) == int(math.sqrt(dist)):
                cnt += 1
    print(cnt)

GoodDist()

Submission status: Accepted

Solution code:
import numpy as np
N,D=map(int,input().split())
X=[]
for i in range(N):
  X.append(list(map(int,input().split())))
cnt=0
for k in range(N-1):
  for j in range(k+1,N):
    sum=0
    ans=0
    for l in range(D):
      sum+=(X[k][l]-X[j][l])**2
    ans=np.sqrt(sum)
    if ans.is_integer():
      cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
# import itertools
# import bisect
# import heapq


# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )
# # from itertools import accumulate
# # from collections import deque

# from operator import mul
# from functools import reduce

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time


def main():
    n, d = map(int, input().strip().split())
    ll = [[] for i in range(n)]
    for i in range(n):
        ll[i] = list(map(int, input().strip().split()))
    cnt = 0
    for i in range(n):
        for j in range(i+1, n):
            dist = 0
            for k in range(0, d):
                dist += (ll[i][k] - ll[j][k])**2
            # eprint(dist**(1/2))
            dist_sqr = dist**(1/2)
            if dist_sqr.is_integer() is True:
                # eprint("dist**0.5 ", end=": ")
                # eprint(dist**0.5)
                cnt += 1
    print(cnt)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
n,d=map(int,input().split())
xlis=[list(map(int,input().split())) for i in range(n)]
def dis(x,y):
	dlis=[]
	for i in range(d):
		t=(xlis[x][i]-xlis[y][i])**2
		dlis.append(t)
	return (sum(dlis))**(1/2)
counter=0
for i in range(n):
	for j in range(n):
		if i<j and int(dis(i,j))==dis(i,j):
			counter+=1
print(counter)

Submission status: Accepted

Solution code:
import math
N , D = (map(int , input().split()))
x = []
ans = 0
for i in range(N):
    x.append(list((map(int , input().split()))))
for i in range(len(x)):
    for j in range(len(x)):
        ans_ = 0
        if i >= j:
            continue
        for k in range(D):
            ans_ += (x[i][k] - x[j][k])**2
        if math.sqrt(ans_).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    import numpy as np 
    N,D = map(int,input().split())
    X = []
    
    for i in range(N):
        X.append(list(map(int,input().split())))
    
    ans = 0

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


if __name__=="__main__":
    main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
from itertools import combinations

N, D = map(int, input().split())
X = []
for _ in range(N):
  x = [int(i) for i in input().split()]
  X.append(x)
  
count = 0
for i, j in combinations(X, 2):
  dist = sum([(i_ - j_)**2 for i_, j_ in zip(i, j)])**0.5
  if dist.is_integer():
    count += 1

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)]

dis = 0
count = 0
for i in range(n-1):
  for j in range(i+1, n):
    val = [x-y for (x, y) in zip(x[i], x[j])]
    dis = math.sqrt(sum(map(lambda x:x**2, val)))
    if dis%1==0:
      count += 1
      
print(count)

Submission status: Accepted

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

def nasu(x, y):
  t = 0
  for i in range(D):
    t += (X[x][i] - X[y][i]) ** 2
  t **= (1 / 2)
  if t == int(t):
    return 1
  else:
    return 0


ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    ans += nasu(i, j)

print(ans)

Submission status: Accepted

Solution code:
#python3
import numpy as np
n,d=map(int, input().split())
pos=[[int(i) for i in input().split()] for _ in range(n)]

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

  tmp=sum**(0.5) 
  if tmp==np.floor(tmp):
    return True
  else: False

cnt=0
for i in range(n):
  for j in range(i+1, n):
    if isInt(pos[i],pos[j]):
      cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
#python3
import numpy as np
n,d=map(int, input().split())
pos=[[int(i) for i in input().split()] for _ in range(n)]

def dist(a, b):
  sum=0;
  for i in range(d):
    sum+=(a[i]-b[i])**2
  return np.sqrt(sum) 

def isInt(d):
  if d-np.floor(d) == 0:
    return True
  else:
    return False

cnt=0
for i in range(n):
  for j in range(i+1, n):
    distance = dist(pos[i], pos[j])
    if isInt(distance):
      cnt+=1

print(cnt)

Submission status: Accepted

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

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

ans=0
for i in range(n):
  for j in range(i + 1, n):
    temp = 0
    for xi,xj in zip(pos[i], pos[j]):
      temp+=(xi-xj)**2
    if int(math.sqrt(temp)) ** 2 == temp:
      ans+=1
      
print(ans)

Submission status: Accepted

Solution code:
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):
        dist = math.sqrt(sum([(x - y) ** 2 for x, y in zip(X[i], X[j])]))
        if dist.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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

        print(ans)


# Run main
if __name__ == '__main__':
    Solution().main()

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, D = map(int, readline().split())
X = [np.array(readline().split(), dtype=np.int64) for _ in range(N)]
ans = 0

for u, v in itertools.combinations(X, 2):
    d = ((u - v) * (u - v)).sum()
    dd = int(d ** .5)
    if d == dd * dd:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

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

x=[]

for i in range(n):
    x.append([int(x) for x in input().split()])
    
count=0
buf=0

for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            buf+=(x[i][k]-x[j][k])**2
        if math.sqrt(buf).is_integer() == True:
            count+=1
        buf=0
print(count)

Submission status: Accepted

Solution code:
import math
n,d = (int(i) for i in input().split())
x = []
ans = 0
for i in range(n):
  x.append([int(i) for i in input().split()])
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
    a = math.sqrt(s)
    if a.is_integer():
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
XList = [i for _ in range(N) for i in map(int, input().split())]
couInt = 0
for i in range(N):
  for j in range(N):
    if i >= j:
      continue
    else:
      dist = 0.0
      for k in range(D):
        dist += (XList[i*D+k]-XList[j*D+k])**2
      if dist**0.5%1==0:
        couInt += 1
print(couInt)

Submission status: Accepted

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

rs = 0
for i in range(n):
    for ii in range(i+1, n):
        dis = 0
        for j in range(d):
            dis += (X[i][j]-X[ii][j])**2
        if dis**0.5 %1 == 0:
            rs += 1

print(rs)

Submission status: Accepted

Solution code:
N,D = [int(i) for i in input().split()]
lagd = []
for i in range(N):
    lagd.append([int(i) for i in input().split()])
lngs = D - 1
def kyoricac(daone,datwo,d):
    keka = []
    n = 0
    wa = 0
    while n <= d:
        wa = (daone[n] - datwo[n])**2
        keka += [wa]
        n += 1
    wa = sum(keka)
    kaesi = float(wa ** (1/2))
    return kaesi
ans = 0
fst = 1
for i in range(N):
    for n in range(fst,N):
        flag = float(kyoricac(lagd[i],lagd[n],lngs))
        if flag.is_integer() == True:
            ans += 1
    fst += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

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

for i in range(N):
    x[i]=list(map(int,input().split()))
        
def calc_dd(a,b):
    dd=0
    for i in range(D):
        dd+=(x[a][i]-x[b][i])**2
    return dd

def judge(dd):
    rdd=int(math.sqrt(dd))
    if rdd*rdd==dd:
        return True
    return False

    
        
ans=0        
for c in itertools.combinations(range(N),2):
    if judge(calc_dd(c[0],c[1])):
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import itertools
import math
import numpy as np
N, D = list(map(int, input().split()))

X = []
for i in range(N):
  X.append(list(map(int,input().split())))
  
select = list(itertools.combinations(X,2))
ans = 0

#距離を求める。
for i ,j in select:
  i = np.array(i)
  j = np.array(j)
  u = i - j
  dist = np.linalg.norm(u)
  
#整数かどうかの判断  
  if dist.is_integer():
    ans += 1
  else:
    pass
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, D = map(int, input().split(" "))
    X = []
    result = 0
    for n in range(N):
        X.append(list(map(int, input().split(" "))))
    for i in range(N):
        for j in range(i + 1, N):
            dist = 0
            for d in range(D):
                dist += (X[i][d] - X[j][d]) ** 2
            if float.is_integer(dist ** 0.5):
                result += 1
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

result=[]
result_hikaku=[]
for j in range(n-1):
    for k in range(j+1,n):
        cnt=0
        for l in range(d):
            cnt +=(int(x[j][l])-int(x[k][l]))**2
        result.append((cnt)**(1/2))
        result_hikaku.append(round((cnt)**(1/2)))

count=0
for m in range(len(result)):
    if result[m]==result_hikaku[m]:
        count+=1
print(count)

Submission status: Accepted

Solution code:
import sys
import math
import numpy as np
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, d = na()
x = [[] for _ in range(n)]
for i in range(n):
    x[i] = na()
x = np.array(x)
c = 0
for i in range(n):
    for j in range(i+1, n):
        s = (np.sum((x[i] - x[j])**2))**0.5
        if s.is_integer():
            c += 1
print(c)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
X = [[int(x) for x in input().split()] for i in range(N)]
count = 0
for i in range(N):
    for j in range(i+1, N):
        sum = 0
        for d in range(D):
            sum += pow(X[i][d]-X[j][d], 2)
        if math.sqrt(sum)%1==0:
            count += 1
print(count)

Submission status: Accepted

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

import itertools
import math

count = 0
for u, v in itertools.combinations(X, 2):
  d = 0
  for i in range(D):
    d += abs(u[i] - v[i]) ** 2
  dd = round(math.sqrt(d))
  if d == dd ** 2:
    count += 1

print(count)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
l=[i**2 for i in range(130)]
set_l=set(l)
cnt=0
X=[list(map(int,input().split())) for i in range(n)]
from itertools import combinations
comb=list(combinations(range(0,n),2))
for pair in comb:
    v=0
    for j in range(d):
        v+=(X[pair[0]][j] - X[pair[1]][j])**2
    if v in set_l:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
points = [[int(i) for i in input().split()] for _ in range(N)]


def calc_distance(p_a, p_b):
    i = 0
    for a, b in zip(p_a, p_b):
        i += (a - b) ** 2
    return math.sqrt(i)


ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if calc_distance(points[i], points[j]).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
l = []
for i in range(n):
  l.append(list(map(int,input().split())))
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    ans = 0
    for k in range(d):
      ans += (int(l[i][k])-int(l[j][k]))**2

    if float.is_integer(math.sqrt(ans)) == True:
      count += 1
print(count)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
l = []
for i in range(n):
  l_ = list(input().split())
  l.append(l_)
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    ans = 0
    for k in range(d):
      ans += (int(l[i][k])-int(l[j][k]))**2
      
    if ans**0.5 % 1 == 0:
      count += 1
print(count)

Submission status: Accepted

Solution code:
N, D = map(int,input().split())
dots = []
for i in range(N):
    dots.append(list(map(int,input().split())))
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        tmp = 0
        for k in range(D):
            tmp+=(dots[i][k]-dots[j][k])**2
        if (tmp**0.5).is_integer():
            cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
import math
n,d = map(int ,input().split())
l=[list(map(int ,input().split())) for x in range(n)]
ans=0
cnt=0
k=0
for i in range(n-1):
    
    for k in range(n-i-1):
        ans=0
        for j in range(d):
            ans+=abs((l[i][j])-(l[i+1+k][j]))**2
        if float.is_integer(math.sqrt(ans))==True:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math
N, D = list(map(int, input().split()))
X = [None] * N
pair = 0

def count(l,r):
    s = 0
    for i in range(D):
        s += abs(l[i]-r[i])**2
    return math.sqrt(s)


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):
        #print(count(X[i], X[j]))
        if count(X[i], X[j]).is_integer():
            pair += 1

print(pair)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[]
count=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):
    sum_=0
    for k in range(D):
      sum_+=(X[i][k]-X[j][k])**2
    ans=sum_**(1/2)
    if ans.is_integer():
      count+=1
print(count)

Submission status: Accepted

Solution code:
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-1):
    for j in range(i+1, n):
        distance = 0
        for k in range(d):
            distance += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(distance).is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

ans=0
s=0
for i in range(N):
  for j in range(i+1,N):
    s=0
    for d in range(D):
      s+=(l[i][d]-l[j][d])**2
    if s**(1/2)%1==0:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
list_x = [[int(i) for i in input().split()] for _ in range(n)]
count = 0
for i in range(n):
    for j in range(i+1,n):
        sum_ = 0
        for k in range(d):
            sum_ += (list_x[i][k] - list_x[j][k])**2
        if math.sqrt(sum_) ==(math.sqrt(sum_))//1:
            count += 1
print(count)