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

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        for y,z in zip(X[i],X[j]):
            tmp += pow(y - z, 2)
        tmp = tmp ** 0.5
        if tmp.is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

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

x = [list(map(int, input().split())) for _ in range(N)]
#print(x_list)
cnt=0
for i in range(N):
    for j in range(i+1,N):
        tmp=0
        for k in range(D):
            tmp += pow((x[i][k]-x[j][k]),2)
        tmp = np.sqrt(tmp)
        if tmp.is_integer()==True:
            cnt+=1
print(cnt)

Submission status: Accepted

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

X=[]

for i in range(N):
    x=list(map(int,input().split()))
    X.append(x)
C=0
L=[]
for i in X:
    for j in X:
        if i==j:
            break
        else:
            S=0
            for k in range(D):
                S += (i[k]-j[k])**2
            l=S**(1/2)
            if l%1==0:
                C+=1
print(C)

Submission status: Accepted

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

def distance(lst1, lst2):
  dis = 0
  for i in range(len(lst1)):
    dis += (lst1[i] - lst2[i])**2
  dis = dis**(1/2)
  return dis

def comb(lst):
  res = 0
  for i in range(len(lst)-1):
    for j in range(i+1, len(lst)):
      if distance(lst[i], lst[j]).is_integer():
        res += 1
  return res

print(comb(List))

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math

def euclid_distance(x1,x2):
    dist = 0
    for i in range(len(x1)):
        dist += (x1[i] - x2[i])**2
    return dist

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

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    cnt = 0
    N,D = LI()
    X = []
    for i in range(N):
        X.append(LI())


    for i in range(N-1):
        for j in range(i+1,N):
            dist = euclid_distance(X[i],X[j])
            for num in range(150):
                if int(dist) == (num**2):
                    cnt += 1
                    continue
    print(cnt)
                
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

n, d = [int(i) for i in input().split()]
lst = []
ret = 0
for i in range(n):
	now = [int(j) for j in input().split()]
	for l in lst:
		sum = 0
		for j in range(d):
			sum += pow(l[j] - now[j], 2)
		if math.sqrt(sum) - int(math.sqrt(sum)) == 0.0:
			ret += 1
	lst.append(now)
print (ret)

Submission status: Accepted

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

Xs = []
for n in range(N):
    X = [int(s) for s in input().split(' ')]
    Xs.append(X)
j = 0
b = [i * i for i in range(1, int(math.sqrt(40 ** 2 * 10)) + 1)] # 40 ** 2 * 10 = 16000 < 130 * 130
count = 0
for Xi in Xs:
    j += 1
    for Xj in Xs[j:]:
        a = 0
        for d in range(D):
            a += (Xi[d] - Xj[d]) ** 2
        if a in b:
            count += 1

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import os, sys, re, math

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

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

print(result)

Submission status: Accepted

Solution code:
import math
n, d = list(map(int, input().split(' ')))
uuu = []
for i in range(n):
    uuu.append(list(map(int, input().split(' '))))
ans = 0
for i in range(n):
    for j in range(i+1, n):
        temp = 0.0
        for k in range(d):
            temp += (uuu[i][k] - uuu[j][k]) ** 2
        temp = temp ** 0.5
        ans += temp == math.ceil(temp)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split(" "))
City = []
count = 0

for _ in range(N):
    l = np.array([int(i) for i in input().split(" ")])
    City.append(l)

for i in range(N-1):
    for j in range(i+1,N):
        
        c = (((City[j]-City[i])**2).sum())**0.5
        if c.is_integer():
            count+=1
            
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

cnt = 0
for v in itertools.combinations(X, 2):
    y = 0
    for i in range(d):
        y += (v[0][i] - v[1][i]) ** 2
    if(y ** 0.5).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 _ in range(n)]
def a(a,b):
  aa=0
  for i in range(d):aa+=abs(a[i]-b[i])**2
  if math.sqrt(aa)%1==0:return 1
  return 0
ans=0
for i in range(n-1):
  for j in range(i+1,n):ans+=a(x[i],x[j])
print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        sm = 0
        for p, q in zip(ll[i], ll[j]):
            sm += (p - q) ** 2
        if int(sm**.5)**2==sm:
            cnt += 1
print(cnt)

Submission status: Accepted

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

            d = sum([(xi-xj)**2 for xi,xj in zip(X[i],X[j])])**0.5
            if d.is_integer():
                ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
n,d=map(int,input().split())
D=[]
for i in range(n):
    List=list(map(int,input().split()))
    D.append(List)
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        cou=0
        for k in range(d):
            # print(i,j,k)
            cou+=(D[i][k]-D[j][k])**2
            
        if(np.sqrt(cou)%1.0==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 _ in range(n)]
def distance(a,b):
  s = 0
  for i in range(d):
    s += (a[i]-b[i])**2
  return math.sqrt(s)
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    if distance(x[i],x[j])//1 == distance(x[i],x[j]):
      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)]
Y = []
b = 0
for i in range(N):

    for k in range(N):

        a = 0
        if i < k:
            for j in range(D):
                a = a+(X[i][j]-X[k][j])**2

            Y.append(a)
for l in range(len(Y)):
    if math.sqrt(Y[l])-int(math.sqrt(Y[l])) == 0:
        b = b+1
print(b)

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

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
points = []
for _ in range(n):
  X = tuple(map(int,input().split()))
  points.append(X)
  
ans = 0

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

for i in range(n-1):
  for j in range(i+1,n):
    dis = distance(points[i],points[j])
    if dis == int(dis):
      ans += 1
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import itertools
a,b=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(a)]
cnt=0
sum_1=[]
for v in itertools.combinations(l,2):
    sum=0
    for i in range(b):
        sum+=(v[0][i]-v[1][i])**2
    if (sum**0.5).is_integer():
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math

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

x  = []
cnt = 0

def calc_dis(dis1, dis2):
    sum = 0
    for i in range(D):
        sum += (dis1[i] - dis2[i]) ** 2
    return math.sqrt(sum)


for i in range(N):
    row = input().split()
    for i in range(len(row)):
        row[i] = int(row[i])
    x.append(row)

for i in range(N):
    for j in range(i + 1, N):
        dis = calc_dis(x[i], x[j])
        if int(dis) == dis:
            cnt += 1


print(cnt)

Submission status: Accepted

Solution code:
import sys
import math

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

###solve
count = 0
for i in range(N):
  for j in range(i+1, N):
    sum = 0.0
    for (a, b) in zip(X[i], X[j]):
      sum += pow(abs(a-b),2)
    if math.sqrt(sum).is_integer() : count+=1
print(count)

Submission status: Accepted

Solution code:
from sys import stdin


def distance(y, z):
    distance2 = 0
    for i in range(len(y)):
        distance2 += (y[i] - z[i])**2
    return distance2**0.5


n, d = (int(x) for x in stdin.readline().rstrip().split())
points = [[int(x) for x in stdin.readline().rstrip().split()]
          for _ in range(n)]

count = 0
for i in range(n):
    for j in range(i+1, n):
        a = distance(points[i], points[j])
        if a == int(a):
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
xs = [list(map(int, input().split()))for _ in range(n)]
c = 0
check = []
for i in range(n):
  check.append(i)
  for j in range(n):
    if i == j or j in check:
      continue
    else:
      a = xs[i][:]
      b = xs[j][:]
      length = math.sqrt(sum([(n-m)**2 for n,m in zip(a,b)]))
      if length%1 == 0:
        c += 1
print(c)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X=[]
ans=0

def cheak_root(n):
    i=0
    while i<n:
        i+=1
        if i*i==n: return i
    return False

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

for i in range(N):
    for j in range(i+1,N):
        sums=0
        for d in range(D):
            diff=X[i][d]-X[j][d]
            sums+=diff*diff
        if cheak_root(sums):ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy

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

ans = 0
for i in range(n):
    for j in range(i):
        dist = numpy.linalg.norm(X[i]-X[j])
        if int(dist) ** 2 == dist ** 2:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def ret_distance(list1,list2,D):
    result = 0
    for i in range(D):
        result += (list1[i]-list2[i])**2
    return result**(1/2)

N,D = map(int,input().split())
s = [list(map(int,input().split())) for i in range(N)]
count = 0

for n in range(N):
    I = n
    for i in range(N-I-1):
        if ret_distance(s[n],s[N-i-1],D).is_integer():
            count+=1

print(count)

Submission status: Accepted

Solution code:
import math
import itertools


def distance(start, end):
    return math.sqrt(sum((x - y) ** 2 for x, y in zip(start, end)))


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

ans = 0
for p, q in itertools.combinations(Xs, 2):
    d = distance(p, q)
    if math.floor(d) == math.ceil(d):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
import numpy as np

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

ans = 0
for x, y in combinations(X, 2):
    d = ((x - y) ** 2).sum() ** 0.5
    if d.is_integer():
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, D = list(map(int, input().split()))
X = []
for i in range(N):
  X.append(list(map(int, input().split())))
  
def dis(l, m):
  out = 0
  for i in range(len(l)):
    out += (l[i] - m[i])**2
  return out ** 0.5

count = 0


for x in range(N-1):
  for y in range(x+1,N):
    if dis(X[x], X[y]) == int(dis(X[x], X[y])):
      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)]

ans = 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 int(d) == d:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
ans=0
X=[list(map(int,input().split())) for _ in range(n)]
for i ,j  in enumerate(X):
  for k in X[i+1:] :
    res=0
    for l in range(d):
       res+=(j[l]-k[l])**2
    if res**0.5-int(res**0.5)<10e-10:
          ans+=1
print(ans)

Submission status: Accepted

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

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

count = 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 (s**(0.5)).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)]
count=0
for i in range(N):
    for j in range(N):
        atai=0
        for k in range(D):
            atai+=(X[i][k]-X[j][k])**2
        else:
            #print(math.sqrt(atai))
            if math.sqrt(atai)==math.ceil(math.sqrt(atai)):
               count+=1
print((count-N)//2)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
#x = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
import numpy as np
cnt = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        dis = 0
        for k in range(d):
            dis += (x[i][k] - x[j][k])**2
        if np.sqrt(dis).is_integer():
            cnt += 1
print(int(cnt/2))

Submission status: Accepted

Solution code:

N,D = map(int,input().split())
X = []
for i in range(N):
    Xi = list(map(int,input().split()))
    X.append(Xi)
ans = 0
def norm(Xi,Xj):
    return sum([(Xi[i]-Xj[i])**2 for i in range(len(Xi))])
for i in range(N):
    for j in range(i,N):
        if i==j:
            continue
        d = norm(X[i],X[j])
        if int(d**0.5)**2==d:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
X = [0]*N
for i in range(0, N):
    X[i] = list(map(int, input().split()))
s = 0
for i in range(0, N):
    for j in range(i, N):
        t = 0
        for k in range(0, D):
            t = t+(X[i][k]-X[j][k])**2
        for l in range(1, t+1):
            if l**2 == t:
                s = s+1
                break
print (s)

Submission status: Accepted

Solution code:
import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, d = list(map(int,ipti().split()))
    x = [0] * n

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

    ans = 0
    for i in range(n-1):
        for j in range(i+1, n):
            temp = 0
            for k in range(d):
                temp += (x[i][k] - x[j][k])**2
            for k in range(401):
                if temp == k**2:
                    ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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):
        wrk=0    
        for k in range(d):
            #print(i,j,k)
            wrk+=(x[i][k]-x[j][k])**2
        #print(wrk**0.5)
        if wrk**0.5%1==0:
            ans+=1
print(ans)

Submission status: Accepted

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

for i in range(n):
    for j in range(n):
        num = 0
        if i >= j:
            continue
        yi = xid[i]
        zi = xid[j]
        for k in range(d):
            num += (yi[k]-zi[k])**2
        num = math.sqrt(num)
        if num.is_integer():
            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(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        dist = 0
        for s in range(d):
            dist += pow(abs(x[i][s] - x[j][s]), 2)
        dist = pow(dist, 1/2)
        if dist.is_integer():
            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(list(map(int, input().split())))

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

print(s)

Submission status: Accepted

Solution code:
from itertools import combinations
from math import sqrt, floor, ceil


def is_square_of_int(n):
    f = sqrt(n)
    return floor(f) ** 2 == n or ceil(f) ** 2 == n


def square_distance(p1, p2):
    return sum((x1 - x2) ** 2 for x1, x2 in zip(p1, p2))


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

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

answer = sum(
    1 for p1, p2 in combinations(X, 2) if is_square_of_int(square_distance(p1, p2))
)
print(answer)

Submission status: Accepted

Solution code:
from math import sqrt
def get_dis(list1, list2):
    temp = 0
    for i in range(len(list1)):
        temp += (list2[i]-list1[i])**2
    return sqrt(temp)
N, D = map(int, input().split())
X_list = []
for i in range(N):
    X = list(map(int, input().split()))
    X_list.append(X)
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        distance = get_dis(X_list[i], X_list[j])
        if distance.is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math


def dist(X1, X2):
    distSq = 0
    for x1, x2 in zip(X1, X2):
        d = x1 - x2
        distSq += d * d
    return math.sqrt(distSq)


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

    count = 0
    for i in range(N):
        X1 = pts[i]
        for j in range(i + 1, N):
            X2 = pts[j]
            d = dist(X1, X2)
            if d == int(d):
                count += 1
    print(count)


main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
X = [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):
    ds = 0
    for k in range(D):
      ds += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k])
    sqds = int(ds**0.5)
    if sqds * sqds == ds:
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
N, D = map(int, input().split())
ans = 0
X = []
for i in range(N):
    x = list(map(int, input().split()))
    X.append(x[:])
for i in range(N - 1):
    for j in range(i+1, N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if int(tmp ** 0.5) == tmp ** 0.5:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  n, d = map(int, input().strip().split())
  xs = numpy.array([[list(map(int, input().strip().split()))] for _ in range(n)])
  count = 0
  for i in range(n-1):
    for j in range(i+1, n):
      l2n = numpy.linalg.norm(xs[i] - xs[j])
      if l2n % int(l2n) == 0:
        count += 1
  print(count)

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
from math import sqrt

N, D = map(int,input().split())
X = [[0]*D for _ in range(N)]
for i in range(N):
  X[i] = list(map(int,input().split()))
    
cnt = 0
for i in range(N-1):
  for j in range(i+1,N):
    sum = 0
    for d in range(D):
      sum += pow((X[i][d] - X[j][d]), 2)
    sum = sqrt(sum)
    if sum.is_integer():
      cnt += 1
print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(n):
    for j in range(i+1, n):
        dd = 0
        for m in range(d):
            dd += (x[i][m] - x[j][m]) ** 2
        dd = dd**0.5
        if dd % 1 ==0:
            ans += 1

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(n):
    for j in range(i+1, n):
        dd = 0
        for m in range(d):
            dd += (x[i][m] - x[j][m]) ** 2
        dd = dd**0.5
        if dd.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
n, d = map(int, input().split())
if d > 1:
  XX = [list(map(int, input().split())) for _ in range(n)]
else:
  XX = [[int(input())] for _ in range(n)]

print(
  sum(
    sqrt(sum((XX[i][k] - XX[j][k]) ** 2 for k in range(d))).is_integer()
	for i in range(n)
	for j in range(i + 1, n)
  )
)

Submission status: Accepted

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

cnt=0
for i in range(N):
    for j in range(N):
        if i!=j:
            val=0
            for k in range(D):
                val+=(X[i][k]-X[j][k])**2
            if val**0.5==int(val**0.5):
                cnt+=1

print(cnt//2)

Submission status: Accepted

Solution code:
import math
def dis(a,b,D):
  t = 0
  for i in range(D):
    t += (a[i] -b[i])**2
  t = t**0.5
  return t
N,D = map(int,input().split())
X = []
C =[]
for i in range(N):
  X.append(list(map(int,input().split())))
for i in range(N-1):
  for j in range(i+1,N):
    C.append(dis(X[i],X[j],D))
ans = 0
for i in C:
  if math.floor(i) == math.ceil(i):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def is_square(n):
    for i in range(200):
        if i*i == n:
            return True
    return False
n,d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int,input().split())))

x = np.array(x)

count = 0
for i in range(n):
    for j in range(i+1,n):
        l = x[i] - x[j]
        l = np.square(l)
        l = np.sum(l)
        flag = is_square(l)
        if(flag) :
            count +=1

print(count)

Submission status: Accepted

Solution code:
import math
import itertools

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

listArray = list(itertools.combinations(X, 2))

for X in listArray:
    sumX = 0
    for x in range(D):
        subX = X[0][x] - X[1][x]
        sumX += subX**2
     
    if math.sqrt(sumX).is_integer():
        count += 1
    
print(count)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
X = []

def dis(a, b):
  t = 0
  for i in range(d):
    t += (a[i] - b[i])**2
  t = t**(0.5)
  return t
C = []
for i in range(n):
  X.append(list(map(int, input().split())))
for i in range(n-1):
  for j in range(i+1, n):
    C.append(dis(X[i], X[j]))
ans = 0
for i in C:
  if int(i) == math.ceil(i):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
n,d = map(int,input().split())
xlst = [list(map(int,input().split())) for _ in range(n)]
xxlst = list(itertools.combinations(xlst,2))
lst = [0]*len(xxlst)
index_num = 0
for i in xxlst:
    for j in range(d):
        lst[index_num] += (i[0][j] - i[1][j])**2
    index_num += 1
lst2 = list(map(math.sqrt,lst))
cnt = 0
for i in lst2:
    if i.is_integer():
        cnt += 1
print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(n):
    for j in range(i+1, n):
        dd = 0
        for m in range(d):
            dd += (x[i][m] - x[j][m]) ** 2
        dd = dd**0.5
        if dd.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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): #iは1個目の点
    for j in range(i + 1, n): #jは２つ目の点
        tmp = 0
        for k in range(d): #dは次元
            tmp += pow(x[i][k] - x[j][k], 2)
        #print(tmp)
        if pow(tmp, 0.5) % 1 == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
data=[]
for i in range(n):
    x=list(map(int,input().split()))
    data.append(x)
ans=0
for i in range(n-1):
    x_i=data[i]
    for j in range(i+1,n):
        x_j=data[j]
        dd=0
        for k in range(d):
            dd+=(x_i[k]-x_j[k])**2
        if (dd**0.5).is_integer()==True:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
xy = list(list(map(int, input().split())) for _ in range(N))
a = []
b = []
ans = 0
cnt = 0
for i, v in enumerate(xy, start=1):
    j = i
    while j < len(xy):
        a = v
        b = xy[j]
        for m in range(len(a)):
            ans += (b[m] - a[m]) ** 2

        ans = ans ** 0.5
        if ans.is_integer():
            cnt += 1
        ans = 0
        j += 1
print(cnt)

Submission status: Accepted

Solution code:
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)]
print(sum((sum(diff**2 for diff in np.array(y)-np.array(z))**.5).is_integer() for y,z in combinations(X,2)))

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):
    for j in range(i+1,N):
        count+=(sum((y-z)**2 for y,z in zip(X[i],X[j]))**.5).is_integer()
print(count)

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):
    for j in range(i+1,N):
        distance=0
        for d in range(D):distance+=pow(abs(X[i][d]-X[j][d]),2)
        if distance==int(distance**.5)**2:count+=1
print(count)

Submission status: Accepted

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

count = 0
for i in range(N-1):
  for j in range(i+1,N):
    dist = 0
    for m in range(D):
      dist += (x[i][m] - x[j][m]) **2
    if (dist ** 0.5) % 1 == 0: #squr dが整数値か判定
      count += 1
print(count)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
X = []
for i in range(n):
    x = list(map(int, input().split()))
    X.append(x)
c, ans = 0, 0
for i in range(0, 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 (c ** (1 / 2)) % 1 == 0:
            ans += 1
print(ans)