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().rstrip().split())
X = []
for i in range(N):
    X.append(list(map(int, input().rstrip().split())))
count=0
for i in range(N):
  for j in range(i+1,N):
    distance=0
    for k in range(D):
      distance += (X[i][k]-X[j][k])**2
    distance=math.sqrt(distance)
    if distance.is_integer():
      count += 1
print(count)

Submission status: Accepted

Solution code:
import math

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

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

for i in range(n):
    for j in range(i+1,n):
        dis = 0
        dis_sq = 0
        for k in range(len(points[i])):
            dis = dis+((points[i][k]-points[j][k])**2)
        dis_sq = int(math.sqrt(dis))
        if dis == dis_sq**2:
            ans = ans+1

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

print(count_int)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
N, D = [int(_) for _ in input().split()]
X = np.array([[int(_) for _ in input().split()] for _ in range(N)], dtype=int)
ans = 0
for i, j in itertools.combinations(range(N), 2):
    y = sum((X[i] - X[j])**2)
    if y == (int(y**0.5))**2:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
from itertools import combinations

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

X = []
for i in range (N):
    X.append([int(num) for num in input().split()])
    
combination = list(combinations(X, 2))

count = 0;
for combi in combination:
    row_combi = list(zip(*combi))
    
    num = 0
    for row in row_combi:
        num += abs(row[0] - row[1]) ** 2
        
    if (math.sqrt(num).is_integer()):
        count += 1
        
print(count)

Submission status: Accepted

Solution code:
import itertools
import math

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

results = 0
comb = itertools.combinations(range(1, N + 1), 2)
for a, b in comb:
    A = POINTS[a - 1]
    B = POINTS[b - 1]
    n = 0
    for d in range(D):
        n += math.fabs(B[d] - A[d])**2
    if math.sqrt(n).is_integer():
        results += 1

print(results)

Submission status: Accepted

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

ans=0
for i in range(n):
  for j in range(n):
    x=0
    for k in range(d):
      x+=(hoge[i][k]-hoge[j][k])**2
    if(x!=0 and x**0.5%1==0):
      ans+=1
      
print(ans//2)

Submission status: Accepted

Solution code:
import math
nd = input().split()
n = int(nd[0])
d = int(nd[1])

x = []
for i in range(n):
  x.append([])
  _x = input().split()
  for y in _x:
    x[i].append(int(y))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N,D=map(int,input().split())
X=[]
for _ 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):
        distance=0
        for k in range(D):
            l=(X[i][k]-X[j][k])**2
            distance+=l
        p=math.sqrt(distance)
        if math.ceil(p)==p:
            ans+=1
print(ans)

Submission status: Accepted

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

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

c=0
for i in range(N):
	for j in range(i+1, N):
		d2 = sum(map(lambda x: (X_lis[j][x] - X_lis[i][x])**2, range(D)))
		for k in range(int(math.sqrt(d2))+1):
			if k**2 == d2:
				c += 1
print(c)

Submission status: Accepted

Solution code:
import math

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

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

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

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

print(count)

Submission status: Accepted

Solution code:
import math
N, D = [int(x) for x in input().split()]
ar = [[int(x) for x in input().split()] for i in range(N)]
ans = 0
for i,x in enumerate(ar):
    for y in ar[i+1:]:
        d = 0
        for (a,b) in zip(x,y):
            d += (a-b)*(a-b)
        if (math.sqrt(d) == int(math.sqrt(d))):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
import numpy as np

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

ret = 0
for i in range(len(lst) - 1):
    for j in range(i + 1, len(lst)):
        n = sum(np.square(np.array(lst[i]) - np.array(lst[j])))
        if math.sqrt(n) == int(math.sqrt(n)):
            ret += 1

print(ret)

Submission status: Accepted

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0.0
        for d in range(D):
            dist+=(X_l[i][d]-X_l[j][d])**2
        dist = math.sqrt(dist)
        if dist.is_integer():
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math

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

n, d = list(map(int, input().split()))
x = []
memoize = []
count = 0

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

for i in range(n):
    for j in range(n):
        if i == j or ((i,j) in memoize) or ((j, i) in memoize):
            continue

        if float.is_integer(distance(x[i], x[j])):
            count += 1

count = count // 2
print(count)

Submission status: Accepted

Solution code:
import math

N,D = list(map(int, input().split()))
list_X = []
ans = 0

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

for i in range(N-1):
    for j in range(i+1,N):
        
        list_of_squares = [(list_X[i][k]-list_X[j][k])**2 for k in range(D)]
        sum_of_squares = sum(list_of_squares)
        distance = math.sqrt(sum_of_squares)

        if distance.is_integer() == True:
            ans+=1
        
print(ans)

Submission status: Accepted

Solution code:
import numpy

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

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

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        a = numpy.array(l[i])
        b = numpy.array(l[j])
        c = numpy.linalg.norm(b - a)
        if (c.is_integer()):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy

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

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

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        if i == j:
            continue
        a = numpy.array(l[i])
        b = numpy.array(l[j])
        c = numpy.linalg.norm(b - a)
        if (c.is_integer()):
            ans += 1

print(ans)

Submission status: Accepted

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

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

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

print(count)

Submission status: Accepted

Solution code:
import numpy as np
N,D= list(map(int, input().split()))
A = []
ans = 0

for i in range(N):
    x = np.array(list(map(int, input().split())))
    A.append(x)
    
for i in range(N):
    for j in range(i+1,N):
        dist = np.linalg.norm(A[i]-A[j])
        if dist == int(dist):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
#!/bin/env python3
def judge_dist(i,j,P,D):
    dist = 0
    for k in range(D):
        dist += (P[i][k] - P[j][k])**2
    square = dist**(1/2)
    if square - int(square) == 0:
        return 1
    else:
        return 0 

def main():
    n,D=map(int,input().split())
    P=[list(map(int,input().split())) for _ in range(n)]
    res = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                res += judge_dist(i,j,P,D)  
    print(res)

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(n):
        if i >= j:
            continue
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        for k in range (200):
            if dist == k**2:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math


def is_distance_integer(p1, p2):
    n = len(p1)

    total = 0
    for i in range(n):
        total += ((p1[i] - p2[i])**2)

    dist = int(math.sqrt(total))

    return (dist**2) == total


def count_pairs(points):
    cnt = 0
    n = len(points)

    for i in range(n):
        for j in range(i + 1, n):
            if is_distance_integer(points[i], points[j]):
                cnt += 1

    return cnt


def main():
    N, D = map(int, input().split())

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

    ans = count_pairs(points)

    print(ans)


main()

Submission status: Accepted

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

def calc(x1, x2):
    ans = 0
    for i in range(len(x1)):
        ans += (x1[i]-x2[i])**2
    return float(math.sqrt(ans))

def solve():
    N, D = list(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):
            ret = calc(X[i], X[j])
            if ret.is_integer():
                ans += 1

    print(ans)



if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

total = 0
for a in range(n-1):
    for b in range(a+1, n):
        dist2 = 0
        for dx in range(d):
            d2 = mat[a][dx]-mat[b][dx]
            dist2 += d2*d2
        dist = dist2**0.5
        # print(dist)
        if dist - int(dist) < 10**-6:
            total += 1
print(total)

Submission status: Accepted

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

sq_list = [ (n+1)**2 for n in range(400)]
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        sq_d = sum([ (X[i][k] - X[j][k])**2 for k in range(D)] )
        if sq_d in sq_list:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

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

points = []

cnt = 0

for _ in range(n):
  point = np.array(list(map(int, input().split())))
  for p in points:
    d = point - p
    if np.sqrt((d * d).sum()).is_integer():
      cnt += 1
  
  points.append(point)
  
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)]
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        res = 0
        a = np.array(x[i])
        b = np.array(x[j])
        dist = np.linalg.norm(b - a)
        if dist % 1 == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

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

output=0

for i in range(N):
    for j in range(N):
        if i>j:
            dist=0
            for y, z in zip(X[i],X[j]):
                dist=dist+(y-z)**2
            if int(dist**(1/2))==dist**(1/2):
                output=output+1
            else:
                output=output+0
        else: pass
print(output)

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()))
count=0

for i in range(0, N):
    for j in range(i+1,N):
        x = 0
        for a,b in zip(X[i],X[j]):
            x += (a-b)**2
        x = math.sqrt(x)
        if x.is_integer():
            count += 1

print(count)

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())))
X = np.array(X)

t=0
for i in range(N):
    for j in range(i+1,N):
        d = (X[i]-X[j])**2
        d = np.sum(d)
        if d**0.5==int(d**0.5):
            t += 1

print(t)

Submission status: Accepted

Solution code:
from math import sqrt
n, d = map(int, input().split())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
sol = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        dist = 0
        for k in range(d):
            dist += pow(a[i][k] - a[j][k], 2)
        if sqrt(dist) == int(sqrt(dist)):
            sol += 1
print(sol)

Submission status: Accepted

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

def calc(a, b):
    s = 0
    for i in range(D):
        s += (a[i] - b[i]) ** 2
    s = math.sqrt(s)
    if s // 1 == s:
        return 1
    return 0

X = list(itertools.combinations(X,2))
for a, b in X:
    ret += calc(a, b)

print(ret)

Submission status: Accepted

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



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

  sqrtset = [i**2 for i in range(1000)]

  ans = 0
  for i in range(N):
    for j in range(i+1,N):
      sm = 0
      for d in range(D):
        sm += (Xn[i][d]-Xn[j][d])**2
      if sm in sqrtset:
        ans += 1

  print(ans)


if __name__ == "__main__":
  main()

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

for _ in range(N):
    point.append(tuple(map(int, input().split())))

ret = 0
for i in range(N):
    for j in range(i + 1, N):
        d = 0
        for a, b in zip(point[i], point[j]):
            d += (a - b) ** 2

        t = math.floor(math.sqrt(d))
        if t * t == d:
            ret += 1

print(ret)

Submission status: Accepted

Solution code:
n, d = list(map(int, input().split()))
p = []
ans = 0
for i in range(n):
  p.append(list(map(int, input().split())))
  for j in range(i):
    s = 0
    for k in range(d):
      s += (p[i][k] - p[j][k]) ** 2
    t = int(s ** 0.5 + 1e-7)
    if t * t == s:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
_,*x=open(0);print(sum(sum(eval(i+'-'+j)**2for i,j in zip(a.split(),b.split()))**.5%1==0for a in x for b in x)-len(x)>>1)

Submission status: Accepted

Solution code:
import math

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

while True:
    try:
        X.append(list(map(int, input().split(" "))))
    except:
        break

def calc_dist(Y,Z):
	ans = 0
	for y, z in zip(Y,Z):
		ans += (y-z)**2
	return math.sqrt(ans)

ans = 0
for i in range(N-1):
	for j in range(i+1, N):
		dist = calc_dist(X[i], X[j])
		if dist.is_integer():
			ans += 1

print(ans)

Submission status: Accepted

Solution code:
_,*x=open(0);print(sum(sum((int(i)-int(j))**2for i,j in zip(a.split(),b.split()))**.5%1==0for a in x for b in x)-len(x)>>1)

Submission status: Accepted

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

maplist = []
for i in range(N):
    maplist.append(list(map(int,input().split())))
count = 0
for i in range(N-1):

    for j in range(i+1,N):
        dis = 0
        for k in range(D):
            dis += (maplist[i][k] - maplist[j][k]) ** 2
        dis = dis ** 0.5
        if float(int(dis)) == dis:
            count += 1
print(count)

Submission status: Accepted

Solution code:
_,*x=[t.split()for t in open(0)];print(sum(sum((int(i)-int(j))**2for i,j in zip(a,b))**.5%1==0for a in x for b in x)-len(x)>>1)

Submission status: Accepted

Solution code:
n,*x=[list(map(int,t.split()))for t in open(0)];print(sum(sum((i-j)**2for i,j in zip(a,b))**.5%1==0for a in x for b in x)-n[0]>>1)

Submission status: Accepted

Solution code:
n,*x=[list(map(int,t.split()))for t in open(0)];print(sum((sum((i-j)**2for i,j in zip(a,b)))**.5%1==0for a in x for b in x)-n[0]>>1)

Submission status: Accepted

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

cnt = 0

for i in range(len(li) - 1):
  for j in range(i+1, len(li)):
    total = 0
    for k in range(d):
      total += (li[i][k] - li[j][k])**2
    
    f = (total**0.5)
    if f.is_integer():
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

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

sq = {i*i for i in range(1000)}

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


print(ans)

Submission status: Accepted

Solution code:
X_list =  [list(map(int, input().split())) for _ in range(list(map(int, input().split()))[0])]
print((sum([((sum([(x1 - x2) ** 2 for x1, x2 in zip(x_lis1, x_lis2)])) ** (0.5) % 1) == 0 for x_lis1 in X_list for x_lis2 in X_list]) - len(X_list)) // 2)

Submission status: Accepted

Solution code:
import sys
def d(v1,v2):
    r = 0
    for x,y in zip(v1,v2):
        r += (x-y)**2
    if r == int(r**0.5) * int(r**0.5):
        return True
    return False


N, D = map(int, input().split())
vs = []
for line in sys.stdin:
    vs.append(list(map(int, line.split())))

rr = 0
for i in range(N):
    for j in range(N-i-1):
        if d(vs[i], vs[i+j+1]):
            rr += 1
print(rr)

Submission status: Accepted

Solution code:
n, d = input().split(" ")
p = [[int(i) for i in input().split()] for i in range(int(n))]
counter = 0
for i in range(int(n)):
    for j in range(int(n)):
        if i > j or i == j:
            continue
        else:
            dist = 0
            for k in range(int(d)):
                dist += (p[i][k] - p[j][k]) ** 2
            if (dist ** (1 / 2)).is_integer():
                counter += 1
print(counter)

Submission status: Accepted

Solution code:
import sys
from math import sqrt

def dist(I, J, D):
    d = 0
    for k in range(D):
        d += pow(I[k] - J[k], 2)
    if int(sqrt(d)) ** 2 == d: return 1
    else: return 0

def solve():
    input = sys.stdin.readline
    N, D = map(int, input().split())
    X = [[int(i) for i in input().split()] for n in range(N)]
    count = 0
    for i in range(N-1):
        for j in range(i + 1, N):
            count += dist(X[i], X[j], D)
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import math

s = input().split(" ")
n = int(s[0])
d = int(s[1])
list = []
count = 0
for i in range(n):
  list.append([float(a) for a in input().split(" ")])
for i1 in range(n):
  for i2 in range(i1, n):
    if i1 != i2:
      dist = 0.0
      for j in range(d):
        dist += (list[i1][j] - list[i2][j]) * (list[i1][j] - list[i2][j])
      sqrt = math.sqrt(dist)
      if sqrt.is_integer():
        count += 1
print(count)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
li =[]
import math
def dist(a,b):
    li2 = []
    for k in range(D):
        li2.append((a[k]-b[k])**2)
    return math.sqrt(sum(li2))
for _ in range(N):
    X = list(map(int,input().split()))
    li.append(X)
cnt = 0
for i in range(N):
    for j in range(N):
        x = li[i]
        y = li[j]
        dis = dist(x,y)
        if dis == 0:
            pass
        else:
            if dis.is_integer():
                cnt +=1
print(int(cnt/2))

Submission status: Accepted

Solution code:
import math
firstvar = input()
n = int(firstvar.split(" ")[0])
d = int(firstvar.split(" ")[1])
current = 0;
points = []
while current < n:
    points.append(input().split(" "))
    current = current + 1
current = 0
answer = 0
done = []
while current < n:
    current2 = 0
    while current2 < n:
        if current2 != current and not [current, current2] in done:
            total = 0
            current3 = 0
            while current3 < d:
                total = total + pow(int(points[current][current3]) - int(points[current2][current3]), 2)
                current3 = current3 + 1
            total = math.sqrt(total)
            if total == int(total):
                answer += 1
            done.append([current2, current])
        current2 = current2 + 1
    current = current + 1
print(answer)

Submission status: Accepted

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

for i in range(N-1):
    for j in range(N-1-i):
        a = 0
        for k in range(D):
            a += (li[i][k]-li[j+i+1][k])**2
        a = a**.5
        if a%1 == 0:
            count += 1

print(count)

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())))
counter = 0
set256 = {i ** 2 % 256 for i in range(256)}
for i in range(N - 1):
    for j in range(N - i - 1):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[i + j + 1][k]) ** 2
        if {d % 256} & set256 != set():
            r = math.sqrt(d)
            if r == int(r):
                counter += 1
print(counter)

Submission status: Accepted

Solution code:
N, D = map(int,input().split())
dots = []
for i in range(N):
  dot = [int(v) for v in input().split()]
  dots.append(dot)

answer = 0
for i in range(N-1):
  for j in range(i+1,N):
    d1,d2 = (dots[i],dots[j])
    distance = (sum([(v1-v2)**2 for v1,v2 in zip(d1,d2)]))**0.5
    if distance.is_integer():
      answer += 1
print(answer)

Submission status: Accepted

Solution code:
args = input().split()
n = int(args[0])
d = int(args[1])
points = []
for i in range(n):
    points.append([int(p) for p in input().split()])


def isSquare(n):
    if n == 1:
        return True
    for i in range(2, n + 1):
        tmp = 0
        while n % i == 0:
            n = n // i
            tmp += 1
        if tmp % 2 != 0:
            return False
        if n == 1:
            return True

cnt = 0
for i in range(n):
    left = points[i]
    for j in range(i + 1, n):
        right = points[j]
        tmp = []
        for p in range(d):
            tmp.append(left[p] - right[p])
        dis = 0
        for k in tmp:
            dis += k ** 2
        if isSquare(dis):
            cnt += 1
        
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

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

counter = 0

for i in range(n):
    for j in range(i+1, n):
        ans = np.sqrt(np.sum((s[i] - s[j]) ** 2))
        if ans == int(ans):
            counter += 1

print(counter)

Submission status: Accepted

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

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

count = 0
for i in range(N):
	for j in range(i + 1, N):
		il, jl = X[i], X[j]
		distance = 0
		for d in range(D):
			distance += (il[d] - jl[d])** 2
		distance **= 0.5
		#print(distance, int(distance))
		if distance == int(distance):
			count += 1
print(count)

Submission status: Accepted

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

from itertools import combinations
import math

IA = lambda: [int(x) for x in input().split()]
IM = lambda N: [IA() for _ in range(N)]

N, D = IA()
X = IM(N)

ans = 0
for x, y in combinations(X, 2):
    t = sum((u - v)**2 for u,v in zip(x, y))
    ans += math.sqrt(t).is_integer()
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

from itertools import combinations
import math

IA = lambda: [int(x) for x in input().split()]
IM = lambda N: [IA() for _ in range(N)]

N, D = IA()
X = IM(N)

ans = 0
for x, y in combinations(X, 2):
    t = sum((u - v)**2 for u,v in zip(x, y))
    ans += int(math.sqrt(t))**2 == t
print(ans)

Submission status: Accepted

Solution code:
# -*- encoding : UTF-8 -*-
n, d = list(map(int, input().split()))

def distance(j_list, i_list):
 n = len(j_list)
# print([i_list, j_list])
 dist2 = 0
 
 for k in range(n):
   dist2 = dist2 + (j_list[k] - i_list[k])**2
   
 dist = dist2 ** 0.5
 return dist

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

count = 0

for i in range(n-1) :
  for j in range(i+1,n):
   dist = distance(nd_list[j], nd_list[i])
   dist_int = int(dist)
   if (dist - dist_int) == 0 :
     count = count + 1

print(count)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import math
N, D = map(int, input().split())
s = []
for i in range(N):
    s += [list(map(int, input().split()))]
count = 0
for i in range(N):
    for j in range(i + 1, N):
        x = 0.0
        for a in range(D):
            x += abs((s[i][a]- s[j][a])**2)
        b = math.sqrt(x)
        if (b.is_integer()):
            count+=1
print(count)

Submission status: Accepted

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

import math
def distance(vector1,vector2):
    sum = 0
    for i in range(D):
        sum += (float(vector1[i])-float(vector2[i]))**2
    return math.sqrt(sum)

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

print(ans)

Submission status: Accepted

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

cnt=0
for i in range(n-1):
    for j in range(i,n):
        if i==j:
            pass

        else:
            ans=0

            for y,z in zip(x[i],x[j]):
                ans+=(y-z)**2
            if pow(ans,1/2) == ans//pow(ans,1/2):
                cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
import itertools
import numpy

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

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

# print(grid)
cnt = 0
grid2 = list(itertools.combinations(grid, 2))
for i in grid2:
    x = numpy.array(i[0])
    y = numpy.array(i[1])
  #  print(x, y)
    dis = numpy.linalg.norm(y - x)
    # print(dis)
    if (dis.is_integer()):
        # print(dis)
        cnt += 1

  # print("-------------")
print(cnt)
# distance = [math.sqrt(() ^ 2+() ^ 2) for i in rang(N)]
# for i in range(N):

Submission status: Accepted

Solution code:
import math

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

count = 0

for i in range(n):
    for j in range(i+1,n,1):
        distance = 0
        total = 0
        for k in range(m):
            total += (table[i][k] - table[j][k]) ** 2
        distance = math.sqrt(total)
        if distance.is_integer() == True:
            count += 1

print(count)

Submission status: Accepted

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        distance = (sum([(a-b)**2 for a, b in zip(zahyo[i], zahyo[j])]))**(1/2)
        if distance == int(distance):
            ans += 1
print(ans)