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())
l = [list(map(int,input().split()))for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        r = 0
        for k in range(d):
            r += (l[i][k]-l[j][k])**2
        r = r**0.5
        if r == int(r):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
count = 0
X = [list(map(int, input().split())) for i in range(n)]
for x in range(n - 1):
	for y in range(x + 1, n):
		d = sum([(a - b)**2 for a, b in zip(X[x], X[y])])**0.5
		if d == d // 1:
			count += 1
print(count)

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,d=n1()
X=n3(n)
ans=0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import  math


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


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

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

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

Submission status: Accepted

Solution code:
import math

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

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

ans = 0

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

Submission status: Accepted

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


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


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

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

    print(ans)


if __name__ == '__main__':
    main()

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

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

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

#dis= kyori(x[0],x[1])
#print(x)
#print(dis)

count=0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import itertools
import math

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


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
N,D = (int(x) for x in input().split())
X =[]
for i in range(N):
    xx = list(map(int, input().split()))
    X.append(xx)

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

Submission status: Accepted

Solution code:
# For taking integer inputs.
import math


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


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N, D = invr()
X = []

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import math

# スペース区切りの整数の入力
N, D = map(int, input().split())
# 文字列の入力
#s = input()
#開業されたN個要素を受け付ける
input_list = [list(map(float, input().split())) for i in range(N)]

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

count = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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


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


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

print(ans)

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)
Count = 0
for i in range(N-1):
  for j in range(i+1,N):
    k = 0
    for t in range(D):
      k += (X[i][t]-X[j][t])**2
    k = k**(1/2)
    if k == int(k):
      Count += 1
print(Count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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


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

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

        len = math.sqrt(len)

        # 整数の判定
        b = int(len)
        if len == b:
            ans += 1


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

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

print(cnt)

Submission status: Accepted

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

c = 0  #count_all

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

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

print(c)

Submission status: Accepted

Solution code:
import itertools

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


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


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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def abc133_b():
    N, D = map(int, input().split())
    X = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i):
            sq = 0
            for k in range(D):
                sq += (X[i][k] - X[j][k]) ** 2
            rt = math.floor(math.sqrt(sq) + 0.5)
            if rt * rt == sq: ans += 1
    print(ans)

abc133_b()

Submission status: Accepted

Solution code:
import sys,math
input = sys.stdin.readline

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

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

print(cnt)

Submission status: Accepted

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

for j in range (N-1):
  for k in range(j+1, N):
    t = 0
    for l in range(D):
      t += (X[j][l]-X[k][l])**2
      
    if t**(1/2)%1 ==0:
      cnt += 1
      
print(cnt)

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N, D = map(int, input().split())
    p = []
    for i in range(N):
        p.append(list(map(int, input().split())))
    for i in range(N):
        for j in range(i, N):
            temp = 0
            for k in range(D):
                temp += (p[i][k]-p[j][k])**2
            if temp != 0 and float.is_integer(temp**0.5):
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
def good_distance(n, d, xli):

    ans = 0

    for i in range(n):
        for q in range(i+1, n):
            count = 0
            for w in range(d):
                count += (xli[i][w]-xli[q][w])**2

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

    return ans

def main():
    n, d = map(int, input().split())
    xli = [list(map(int, input().split()))for i in range(n)]
    print(good_distance(n, d, xli))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N):
    for j in range(i+1, N):
        distance = 0
        for c1,c2 in zip(points[i], points[j]):
            distance += (c1 - c2)**2

        if (distance**0.5).is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
ans=0
pos=[]
for i in range(N): pos.append(list(map(int,input().split())))
for i in range(N):
    y=pos[i]
    for j in range(N):
        z=pos[j]
        if i==j: pass
        else:
            distance=0.0
            for k in range(D): distance+=(y[k]-z[k])**2
            if math.sqrt(distance).is_integer(): ans+=1
print(ans//2)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
a=[[0]*d for ii in range(n)]
for ii in range(n):
  a[ii][:]=map(int,input().split())
r=0
for ii in range(n):
  for jj in range(n):
    if ii!=jj:
      d2=0
      for kk in range(d):
        d2+=(a[ii][kk]-a[jj][kk])**2
      d2=d2**0.5
      #print(d2)
      if int(d2)==d2:
        r+=1
print(r//2)

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, D = il()
    X = [il() for _ in range(N)]

    ret = 0
    for x, y in itertools.combinations(X, 2):
        i = 0
        for t in zip(x, y):
            i += abs(t[0] - t[1]) ** 2
        if float.is_integer(math.sqrt(i)):
            ret += 1
    print(ret)


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)]
f=0
for i in range(n-1):
  for j in range(i+1,n):
    l=(sum((X[i][a]-X[j][a])**2 for a in range(d)))**(1/2)
    if int(l)==l:
        f+=1
print(f)

Submission status: Accepted

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

Submission status: Accepted

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

f=0
for i in range(n-1):
  for j in range(i+1,n):
    l=0
    for a in range(d):
      l+=(X[i][a]-X[j][a])**2
    if int(l**(1/2))==l**(1/2):
        f+=1
print(f)

Submission status: Accepted

Solution code:
import math
n, d = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(n)]
count = 0
def dist(X0, X1):
    l = 0
    for x0, x1 in zip(X0, X1):
        l += (x0 - x1) ** 2
    return math.sqrt(l)
for i in range(n - 1):
    for j in range(i + 1, n):
        l = dist(X[i], X[j])
        if l.is_integer():
            count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range (N):
  l.append(list(map(int, input().split())))
    
for j in range (N-1):
  for k in range (j+1, N):
    t = 0
    for d in range (D):
      t += (l[j][d]-l[k][d])**2
      
    if t**(1/2)%1 ==0:
      cnt += 1
      
print(cnt)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
import copy

n,d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
l = list(range(0,n))
pair = list(itertools.combinations(l, 2))
count = 0
for i in range(len(pair)):
    distance = 0
    for j in range(d):
        distance += (x[pair[i][0]][j] - x[pair[i][1]][j])**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=[[] for _ in range(n)]

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

Submission status: Accepted

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

x=[[] for _ in range(n)]

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

Submission status: Accepted

Solution code:
import itertools
import numpy as np
n,d = map(int,input().split())
x = [np.array(input().split(), dtype=np.int64)for _ in range(n)]


ans = 0
for u,v in itertools.combinations(x,2):
    d = ((u-v) * (u-v)).sum()
    if int(d**0.5) == d ** 0.5:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,d = tuple(map(int,input().split()))

x = [np.array(tuple(map(int,input().split()))) for _ in [0]*n]

ans = 0
for i in range(n):
  for j in range(i+1,n):
    if np.linalg.norm(x[i]-x[j]).is_integer():
      ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
count=0
for i in range(n-1):
    for j in range(i+1,n):
        a=np.array(x[i])
        b=np.array(x[j])
        ab=sum(np.power((a-b),2))**0.5
        if ab%1==0:
            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
for i in range(n-1):
    for j in range(i+1, n):
        
        int_ = 0
        for k in range(d):
            int_ += (L[i][k]-L[j][k])**2
        if int(int_**0.5)==int_**0.5:
            ans += 1
print(ans)

Submission status: Accepted

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

len_x = 0
youso = 0
count = 0
for i in range(1, n[0]+1):
  for j in range(i+1, n[0]+1):
    youso = 0
    for k in range(0, n[1]):
      t = x[i-1][k]+(-1)*x[j-1][k]
      youso += t*t
    youso = math.sqrt(youso)
    if str(youso)[-1] == '0':
      count += 1
print(count)

Submission status: Accepted

Solution code:
from math import floor
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):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        if floor(dist**0.5)**2 == dist:
            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)]
cnt=0
for i in range(n-1):
  for j in range(i+1,n):
    sum=0
    for dd in range(d):
      sum+=(l[i][dd]-l[j][dd])**2
    if sum**0.5==int(sum**0.5):
      cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
import bisect

def solve(A):
    n = len(A)
    m = len(A[0])
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            val = 0
            for k in range(m):
                val += (A[i][k] - A[j][k]) ** 2
            dval = math.sqrt(val)
            if dval == math.floor(dval):
                ans += 1
    return ans

def main():
    n, m = map(int, input().split())
    A = []
    for i in range(n):
        A.append(list(map(int, input().split())))
    print(solve(A))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue May 12 14:10:07 2020

@author: shinba
"""
import itertools

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

X = []

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

ans = 0

for i in itertools.combinations(range(n), 2):
    dist = 0
    for j in range(d):
        dist += (X[i[0]][j]-X[i[1]][j])**2
    else:
        if dist**(0.5) == int(dist**(0.5)):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
def LI(): return list(map(int,input().split()))
N,D = LI()
X = [LI() for _ in range(N)]
_ans = 0
for i in range(N):
    for j in range(i+1,N):
        temp = 0
        for k in range(D):
            temp += (X[j][k]-X[i][k])**2
        if temp**0.5%1==0:
            _ans += 1
print(_ans)