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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############
N,D = inputIL()
X  = inputILL(N)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    d = pow(sum((X[i][d]-X[j][d])**2 for d in range(D)),1/2)
    if d == int(d):
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from itertools import accumulate
import sys
sys.setrecursionlimit(10**6)

mo=10**9+7
#n=int(input()) 
n,d=map(int,input().split())
y=[]
for i in range(n):
    x=[int(i) for i in input().split()]
    y.append(x)
    
def dist(x,y):
    a=0
    rt=False
    for i in range(len(x)):
        a+=(x[i]-y[i])**2
    if a==int(a**0.5)**2:
        rt=True
    return rt
    #print(a,int(a**0.5)**2)
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=1 if dist(y[i],y[j]) else 0


print(ans)

Submission status: Accepted

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

ll = []
for i in range(N):
    l = [int(i) for i in input().rstrip().split()]
    ll.append(l)

num = 0
for i in range(N - 1):
    for j in range(i + 1, N):
#        print('i={}, j={}'.format(i, j))
        la = ll[i]
        lb = ll[j]
        x = 0
        for k in range(D):
            v = la[k] - lb[k]
            x = x + v ** 2

#        print(math.sqrt(x))
        if math.sqrt(x).is_integer():
            num = num + 1

print(num)

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

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N,D=pin()
    X=[lispin()for i in range(N)]
    cnt=0
    for i in range(N-1):
        for j in range(i+1,N):
            temp=0
            #print(i,j)
            for d in range(D):
                temp+=(X[i][d]-X[j][d])**2
            #print(temp)
            for k in range(100000):
                if k**2==temp:cnt+=1
                if k**2>temp:break
    print(cnt)
#%%submit!
resolve()

Submission status: Accepted

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

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

for i in range(N):
  for j in range(i+1,N):
    dist = 0
    for k in range(D):
      dist += pow(X[i][k]-X[j][k],2)
    dist = math.sqrt(dist)
    
    if dist.is_integer():
      cnt += 1
      
print(cnt)

Submission status: Accepted

Solution code:
from math import sqrt

n,d = map(int,input().split())
li  = [list(map(int,input().split())) for i in range(n)]
tmp = 0
ans = 0

for i in range(n):
  for j in range (i+1,n):
    for k in range(d):
      tmp += pow(abs(li[i][k]-li[j][k]),2)
    if sqrt(tmp)%1==0:
      ans += 1
    tmp =  0

print(ans)

Submission status: Accepted

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

import numpy as np
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:
# ABC133B

import numpy as np

n, d = map(int, input().split())
x = [0] * n
for i in range(n):
    x[i] = list(map(int, input().split()))
x = np.array(x)
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        d = np.sqrt(sum((x[i, :] - x[j, :]) ** 2))
        # print(i, j, "** d =", d)
        if d == int(d):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import numpy as np
import math

n, d = map(int, input().strip().split())
points = np.array([list(map(int, input().strip().split())) for _ in range(n)])


def is_square(num):
    root = int(math.sqrt(num))
    return root ** 2 == num

counts = 0
for i in range(n):
    for j in range(i + 1, n):
        pi = points[i]
        pj = points[j]
        d2 = np.sum((pi - pj) ** 2)
        if is_square(d2):
            counts += 1

print(counts)

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())
xs=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i,y in enumerate(xs):
    for z in xs[i+1:]:
        s=sum([(a-b)**2 for a,b in zip(y,z)])**(1/2)
        if s==s//1:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

l = [i for i in range(N)]
C = list(itertools.combinations(l, 2))

a = 0
ans = 0
for c in C:
    a = 0
    for i in range(D):
        a += (X[c[0]][i] - X[c[1]][i]) ** 2
    a **= 0.5
    if a % 1 == 0:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import functools
N, D = list(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
        L = [(X[i][d]-X[j][d])**2 for d in range(D)]
        distance = math.sqrt(functools.reduce(lambda x,y:x+y,L))
        if (distance % 1) == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

from itertools import combinations
from fractions import math

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

c = list(combinations(points,2))

cnt = 0

for combi in c:
    distance = 0

    for j in range(D):
        X=combi[0][0]
        Y=combi[1][0]
        distance += ( X[j] - Y[j])**2

    distance = math.sqrt(distance)

    if distance.is_integer():
        cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n, d = Is()
X = LIR(n)
ans = 0
for i, j in combinations(range(n), 2):
    tmp = 0
    for l in range(d):
        tmp += (X[i][l]-X[j][l])**2
    if sqrt(tmp) % int(sqrt(tmp)) == 0:
        ans += 1
print(ans)

Submission status: Accepted

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

x = []

ans = 0

for i in range(n):
    x.append(list(map(int,input().split())))
    
def dis(a,b):
    t = 0
    for i in range(len(a)):
        t += (a[i]-b[i])**2
        
    if int(t**0.5)==t**0.5:
        return 1
    else:
        return 0
        
for i in range(len(x)):
    for s in range(i+1,len(x)):
        ans += dis(x[i],x[s])
        
print(ans)

Submission status: Accepted

Solution code:
import itertools
cnt = 0
N, D= (int(x) for x in input().split())
X = [[] * D for i in range(N)]
def distance(A,B):
  s = 0
  for i in range(len(A)):
    s = s + (A[i] -B[i])**2
  return s**(1/2)
for i in range(N):
  X[i] = [int(x) for x in input().split()]
c = list(itertools.combinations(X, 2))
for i in c:
  if distance(i[0],i[1]).is_integer():
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations

N, D = map(int, input().split())
X = np.zeros([N, D], dtype=int)
ans = []

def judge_int(array):
    return np.sqrt((array**2).sum()).is_integer()

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

for i, j in list(combinations(range(0, N), 2)):
    ans.append(judge_int(X[i] - X[j]))

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools


def solve():
    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):
        save = 0
        for d in range(D):
            save += (X[i[0]][d]-X[i[1]][d])**2
        if (save**0.5) % 1 == 0:
            ans += 1
    print(ans)


solve()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        tmp = 0

        for k in range(d):
            tmp = tmp + (T[i][k] - T[j][k]) ** 2

        tmp = tmp ** 0.5

        if tmp == int(tmp):
            ans = ans + 1

print(ans)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
dli = [[] for _ in range(n)]
for i in range(n):
    x = list(map(int,input().split()))
    dli[i] = x
#dli[0][0] - dli[1][0] + dli[0][1] - dli[1][1]

#(abs(dli[i][d] - dli[i+1][d]))**2 + dli[i][d] -
#
# dli[0][0] - dli[1][0] + dli[0][1] - dli[1][1]
#dli[0][0] - dli[2][0]
#dli[0][0] - dli[3][0]
cnt = 0
for i in range(n):
    for j in range(i+1,n,1):
        res = 0
        for k in range(d):
            res += abs(dli[i][k] - dli[j][k])**2
        if math.sqrt(res).is_integer():
            cnt+=1

print(cnt)

Submission status: Accepted

Solution code:

sq = set()

i, ii= 0,0
while ii <= 160000:
    sq.add(ii)
    i+=1
    ii = i*i

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

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

def d2(x,y):
    ret = 0
    for i in range(len(x)):
        ret += (x[i]-y[i])**2
    return ret

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if d2(X[i],X[j]) in sq:
            ans += 1
    
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in range(N):
  for j in range(i + 1, N):
    L = []
    for k in range(D):
      L.append((X[i][k] - X[j][k]) ** 2)
    y = sum(L)
    for l in range(y + 1):
      if l ** 2 == y:
        #print(l)
        count += 1

print(count)

Submission status: Accepted

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

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

for i in range(N):
  for j in range(i+1, N):
    L = []
    for k in range(D):
      L.append((X[i][k] - X[j][k])**2)
    y = sum(L)
    z = math.sqrt(y)
    if z - int(z) == 0:
      count += 1
print(count)

Submission status: Accepted

Solution code:
def calc_dist(y, z):
  l = []
  for each_y, each_z in zip(y, z):
    l.append((each_y - each_z)**2)
  return sum(l) ** 0.5

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):
    tmp = calc_dist(points[i], points[j])
    if tmp == int(tmp):
      ans += 1
      
print(ans)

Submission status: Accepted

Solution code:
import math


def main():
    N, D = (int(x) for x in input().split())
    X = [[int(x) for x in input().split()] for i in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            if distance(X[i], X[j]).is_integer():
                ans += 1
    print(ans)


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
a=[]
x=[]
count=0
c=0
ans=0
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(d):
        x.append(a[j])
for i in range(1,n):
    for j in range(i+1,n+1):
        for k in range(d):
            y=x[(i-1)*d+k]
            z=x[(j-1)*d+k]
            c=y-z
            count+=c*c
        e=math.sqrt(count)
        if e%1==0:
            ans+=1
        count=0
print(ans)

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
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):
        total = 0
        for k in range(D):
            total += (X[i][k] - X[j][k])**2
        if int(total**.5)**2 == total:
            ans += 1

print(ans)

Submission status: Accepted

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

count_ = 0
for j in range(0,N):
  for i in range(j+1,N):
    sum_ = 0
    for d in range(D):
      sum_+=(X[i][d]-X[j][d])**2
    if (sum_**0.5)%1==0: count_+=1
print(count_)

Submission status: Accepted

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

count_ = 0
for j in range(0,N):
  for i in range(0,N):
    sum_ = 0
    for d in range(D):
      sum_+=(X[i][d]-X[j][d])**2
    if (sum_**0.5)%1==0: count_+=1
print(int((count_-N)/2))

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
x = [[0]]*n
for i in range(n):
  x[i] = list(map(int,input().split()))
pairs = 0
sqset = set()
for i in range(1,127):
  sqset.add(i**2)
for i in range(n-1):
  for j in range(1,n-i):
    dstsq = 0
    for k in range(d):
      dstsq += (x[i][k]-x[i+j][k])**2
    if dstsq in sqset:
      pairs += 1
print(pairs)

Submission status: Accepted

Solution code:
# B - Good Distance

N, D = map(int, input().split())
X = [[int(x) for x in 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 += (abs(X[i][k] - X[j][k])) ** 2
        if (dist ** (1 / 2)).is_integer():
            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)
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        t=0
        for l in range(d):
            t+=(x[i][l]-x[j][l])**2
        if t==int(t**(1/2))**2:
            ans+=1
print(ans)

Submission status: Accepted

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

Z = []
for j in range(N):
  for i in range(j):
    Y = []
    for n in range(D):
      Y.append((X[i][n] - X[j][n])**2)
    Z.append(Y)

a = 0    
for l in range(N*(N-1)//2):    
  if (sum(Z[l]))**0.5 == int((sum(Z[l]))**0.5):
    a = a+1

print(a)

Submission status: Accepted

Solution code:
import sys, heapq, bisect, math, fractions
from collections import deque


def ok(i, j, D):
    d = 0
    for k in range(D):
        d += (X[i][k] - X[j][k]) ** 2
    
    dd = int(math.sqrt(d))
    if dd ** 2 == d:
        return True
    else:
        return False


N, D = map(int, input().split())
X = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(N)]

res = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if ok(i, j, D):
            res += 1

print(res)

Submission status: Accepted

Solution code:
import numpy as np
import math
ans=0
d=0
n,D = [int(i) for i in input().split()]
graph=np.zeros(n*D).reshape((n,D))
for i in range(n):
    graph[i:i+1,:] = np.array([int(i) for i in input().split()])
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(D):
            d += abs(graph[i,k] - graph[j,k])**2
        if(math.sqrt(d).is_integer()):
            ans+=1
        d=0
print(ans)

Submission status: Accepted

Solution code:
import math

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

for i in range(N):
    for j in range(i+1, N):
        length = 0
        for x_i, x_j in zip(X[i], X[j]):
            length += (x_i-x_j)**2
        length = math.sqrt(length)
        if length == int(length):
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import itertools
import math

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

for n in N_list:
    length = 0
    for x_1, x_2 in zip(X[n[0]], X[n[1]]):
        length += (x_1-x_2)**2
    length = math.sqrt(length)
    if length == int(length):
        cnt += 1
        
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
X = np.array([list(map(int, input().split())) for i in range(N)])
cnt = 0
for i in range(N):
  for j in range(N):
    D = np.linalg.norm(X[i]-X[j], ord=2)
    if i < j and  D%1 == 0:
      cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]

N, D = ri_()
X = [ri_() for _ in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        tmp = 0
        for d in range(D):
            tmp += (X[i][d] - X[j][d]) ** 2
        for k in range(1000):
            if k ** 2 == tmp:
                ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(len(arr)-1):
  for j in range(i+1, len(arr)):
    dis = 0
    for k in range(d):
      dis += (arr[i][k] - arr[j][k])**2
    l = 0
    while l*l < dis:
      l+=1
      if l*l == dis:
        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):
    X[i] = list(map(int, input().split()))

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

print(ans)

Submission status: Accepted

Solution code:
N,D=map(int, input().split())
X=list(list(map(int, input().split())) for _ in range(N))
import itertools
import math
tmp=0
ans=0
for x1,x2 in list(itertools.combinations(X,2)):
    for d in range(D):
        tmp+=(x1[d]-x2[d])**2
    tmp=math.sqrt(tmp)
    tmp1=math.ceil(tmp)
    if tmp==tmp1:
        ans+=1
    tmp=0
print(ans)

Submission status: Accepted

Solution code:
N, D, *X = map(int, open(0).read().split())
*X, = zip(*[iter(X)]*D)

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

print(cnt)

Submission status: Accepted

Solution code:
n, d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
cnt = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        dis = 0
        for k in range(d):
            dis += (x[i][k] - x[j][k]) ** 2
            #print(x[i][k], x[j][k])

        temp = int(dis ** 0.5)
        if temp ** 2 == dis:
            cnt += 1
print(cnt)

Submission status: Accepted

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

def resolve():
    import numpy as np
    n,d=map(int, input().split())
    l=[list(map(int,input().split())) for i in range(n)]
    cnt=0
    for j in range(n-1):
        for k in range(j+1,n):
            a=np.array(l[j])-np.array(l[k])
            if np.linalg.norm(a)%1==0:
                cnt+=1
    print(cnt)
resolve()

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
S=[]
C=0
for i in range(N):
	S.append(list(map(int,input().split())))
for i in range(0,N-1):
	for j in range(i+1,N):
		tmp=0
		for k in range(D):
			tmp+=(S[i][k]-S[j][k])**2
		tmp=math.sqrt(tmp)
		if tmp==int(tmp):
			C+=1
print(C)

Submission status: Accepted

Solution code:
def main():
    n, d = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*n]

    cnt = 0
    for i in range(n):
        for j in range(i+1, n):
            ans = 0
            for k in range(d):
                ans += ((ab[i][k]-ab[j][k])**2)
            if int(ans**0.5)**2 == ans:
                cnt += 1
    print(cnt)


main()

Submission status: Accepted

Solution code:
def main():
    from math import sqrt
    import sys
    input = sys.stdin.buffer.readline
    N, D = (int(i) for i in input().split())
    Xs = [[int(i) for i in input().split()] for j in range(N)]

    def check(A, B):
        v = sum((a-b)**2 for a, b in zip(A, B))
        if sqrt(v).is_integer():
            return True
        else:
            return False

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if check(Xs[i], Xs[j]):
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

cnt=0

i=0
while i<n-1:
    j=i+1
    while j<n:
        temp=0
        for k in range(d):
            temp+=(x[i][k]-x[j][k])**2
        if temp==int(temp**(1/2))*int(temp**(1/2)):
            cnt+=1
        
        j+=1
    i+=1    

print(cnt)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

ans = 0
for i, j in combinations(x, 2):
    tmp = 0
    for k, l in zip(i, j):
        tmp += (k-l)**2
    if round(tmp**0.5)**2==tmp:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt

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

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

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

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X = [tuple(map(int,input().split())) for i in range(N)]
ans = 0
for i,x in enumerate(X[:-1]):
    for y in X[i+1:]:
        d = 0
        for a,b in zip(x,y):
            d += (a-b)**2
        if int(d**0.5) == d**0.5:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
k = []
ans_2 = 0
ans_1 = 0
now = 0
for i in range(N):
    k.append(list(map(int,input().split())))
for i in range(0,N):
    for j in range(i+1,N):
        for _ in range(D):
            now += (k[i][_]-k[j][_])**2
        ans_1 = math.sqrt(now)
        if ans_1%1 == 0:
            ans_2 += 1
        now = 0
        ans_1 = 0
print(ans_2)

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 t in range(N-1):
    for s in range(t+1,N):
        count=0
        for x in range(D):
            count+=(X[t][x]-X[s][x])**2
        Z=count**(1/2)
        if Z.is_integer()==True:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(n)]
p = 0
if d != 10:
    for i in range(n):
        for j in range(10-d):
            ls[i].append(0)
for k in range(n):
    for l in range(n):
        if k < l:
            if ((ls[k][0]-ls[l][0])**2+(ls[k][1]-ls[l][1])**2+(ls[k][2]-ls[l][2])**2+(ls[k][3]-ls[l][3])**2+(ls[k][4]-ls[l][4])**2+(ls[k][5]-ls[l][5])**2+(ls[k][6]-ls[l][6])**2+(ls[k][7]-ls[l][7])**2+(ls[k][8]-ls[l][8])**2+(ls[k][9]-ls[l][9])**2)**(1/2) %1==0:
                p += 1
print(p)

Submission status: Accepted

Solution code:
import numpy as np
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, d = map(int, readline().split())
x = np.array(read().split(), np.int64).reshape(n, d)

z = []
ans = 0

for i in range(400):
    z.append(pow(i, 2))

for i in range(n-1):
    for j in range(i+1, n):
        t = 0
        for k in range(d):
            t += pow(x[j][k] - x[i][k], 2)

        if t in z:
            ans += 1

print(ans)